
    _e1                     >    d Z ddlZddlZddlmZmZ  G d de      Zy)z.Base class for GLU callback-caching structures    N)longinteger_typesc                   J    e Zd ZdZd Z ee      ZdZdZdZ	d Z
d Zd Zd Zy)	GLUStructa.  Mix-in class for GLU Structures that want to retain references to callbacks
    
    Also provides original-object-return for the "datapointer" style paremters
    
    Each sub-class must override:
        CALLBACK_TYPES -- maps a "which" constant to a function type 
        CALLBACK_FUNCTION_REGISTRARS -- maps a "which" constant to the 
            registration function for functions of that type
        WRAPPER_METHODS -- maps a "which" consant to a method of the structure 
            that produces a callable around the function which takes care of 
            input/output arguments, data conversions, error handling and the 
            like.
    Creates a dictionary member dataPointers if original-object-return is used
    Creates a dictionary member callbacks if callback registration is used
    c                 ,    t        j                  |       S )z4Gets as a ctypes pointer to the underlying structure)ctypespointer)selfs    6/usr/lib/python3/dist-packages/OpenGL/GLU/glustruct.py
getAsParamzGLUStruct.getAsParam   s    ~~t%%    Nc                 |    t        |      }	 || j                  |<   |S # t        $ r}||i| _        Y d}~|S d}~ww xY w)zNote object for later retrieval as a Python object pointer
        
        This is the registration point for "original object return", returns 
        a void pointer to the Python object, though this is, effectively, an 
        opaque value.
        N)iddataPointersAttributeError)r
   objectidentityerrs       r   
noteObjectzGLUStruct.noteObject   sP     f:	5,2Dx)   	5"*F 4D	5s    	;	6;c                     t        |t              r|}n|y	 |j                  }	 | j                  |   S # t        $ r}|d   }Y d}~#d}~ww xY w# t
        t        f$ r}|cY d}~S d}~ww xY w)z<Given a void-pointer, try to find our original Python objectNr   )
isinstancer   valuer   r   KeyError)r
   voidPointerr   r   s       r   originalObjectzGLUStruct.originalObject*   sw    {M2"H *&,,	$$h00 " *&q>* ( 		s1   4 A 	AAAA*A%A*%A*c                    | j                   j                  |      }|st        d|      | j                  j                  |      }| t	        | |      |      } ||      }	  | j
                  |   | ||       t	        | dd      i | _	        || j                  |<   |S # t        j                  $ r}|xj                  ||fz  c_         d}~ww xY w)z-Register a callback for this structure objectz*Don't have a registered callback type for N	callbacks)
CALLBACK_TYPESget
ValueErrorWRAPPER_METHODSgetattrCALLBACK_FUNCTION_REGISTRARSr   ArgumentErrorargsr   )r
   whichfunctioncallbackTypewrapperMethod	cCallbackr   s          r   addCallbackzGLUStruct.addCallback9   s    **..7 
 ,,00%9$2wtM2H>H (,		4D--e4dE9N D+t-5DN"+ ## 	HHy))H	s   $B   C3CCc                 Z    |j                  |f      }t        |      D ]
  }||   ||<    |S )z8Copy length values from ptr into new array of given type)zerosrange)r
   ptrlengthtyperesultis         r   
ptrAsArrayzGLUStruct.ptrAsArrayR   s7    fY(v 	AAF1I	r   )__name__
__module____qualname____doc__r   property_as_parameter_r   r#   r!   r   r   r+   r4    r   r   r   r      s<    & z+NN#' O2r   r   )r8   r   weakrefOpenGL._bytesr   r   r   r   r;   r   r   <module>r>      s    4   -Q Qr   