
    *`iT	                         U d Z ddlZddlmZ ej                            d          dk    rddlmZ ndZee	d	<    G d
 d          Z
dS )zAThis module provides classes to handle C++ objects from nanobind.    N)AnyXGRAMMAR_BUILD_DOCS1   )xgrammar_bindingszdummy namespace_corec                   V    e Zd ZdZed	d            Zd Zed             Zde	de
fdZdS )
	XGRObjecta  The base class for all objects in XGrammar. This class provides methods to handle the
    C++ handle from nanobind.

    In subclasses, the handle should be initialized via the the _create_from_handle, or via
    the _init_handle method called within the __init__ method, and should not be modified
    afterwards. Subclasses should use the _handle property to access the handle. When comparing
    two objects, the equality is checked by comparing the C++ handles.

    For performance considerations, objects in XGrammar should be lightweight and only maintain
    a handle to the C++ objects. Heavy operations should be performed on the C++ side.
    returnc                 >    |                      |           }||_        |S )a  Construct an object of the class from a C++ handle.

        Parameters
        ----------
        cls
            The class of the object.

        handle
            The C++ handle.

        Returns
        -------
        obj : XGRObject
            An object of type cls.
        )__new___XGRObject__handle)clshandleobjs      a/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/xgrammar/base.py_create_from_handlezXGRObject._create_from_handle   s!    " kk#
    c                     || _         dS )zInitialize an object with a handle. This method should be called in the __init__
        method of the subclasses of XGRObject to initialize the C++ handle.

        Parameters
        ----------
        handle
            The C++ handle.
        Nr   )selfr   s     r   _init_handlezXGRObject._init_handle.   s     r   c                     | j         S )zvGet the C++ handle of the object.

        Returns
        -------
        handle
            The C++ handle.
        r   )r   s    r   _handlezXGRObject._handle9   s     }r   otherc                 Z    t          |t                    st          S | j        |j        k    S )a%  Compare two XGrammar objects by comparing their C++ handles.

        Parameters
        ----------
        other : object
            The other object to compare with.

        Returns
        -------
        equal : bool
            Whether the two objects have the same C++ handle.
        )
isinstancer
   NotImplementedr   )r   r   s     r   __eq__zXGRObject.__eq__D   s+     %++ 	"!!|u},,r   N)r   r
   )__name__
__module____qualname____doc__classmethodr   r   propertyr   objectboolr    r   r   r
   r
      s        
 
    [(	 	 	   X-F -t - - - - - -r   r
   )r#   ostypingr   environget r   r   __annotations__r
   r(   r   r   <module>r/      s    G G G 				      :>>'((C//,,,,,,,"E3"""G- G- G- G- G- G- G- G- G- G-r   