o
    )iT	                     @   sV   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 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                   @   sD   e Zd ZdZedddZdd Zedd Zd	e	de
fd
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                 C   s   |  | }||_|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obj r   J/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/xgrammar/base.py_create_from_handle   s   
zXGRObject._create_from_handlec                 C   s
   || _ 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   r   r   r   _init_handle.   s   
	zXGRObject._init_handlec                 C   s   | j S )zvGet the C++ handle of the object.

        Returns
        -------
        handle
            The C++ handle.
        r   )r   r   r   r   _handle9   s   	zXGRObject._handleotherc                 C   s   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   r   r   r   __eq__D   s   
zXGRObject.__eq__N)r	   r   )__name__
__module____qualname____doc__classmethodr   r   propertyr   objectboolr   r   r   r   r   r      s    

r   )r   ostypingr   environget r   r   __annotations__r   r   r   r   r   <module>   s    