a
    i‚j#  ã                   @   s,   d Z ddlZddlmZ G dd„ deƒZdS )z~Base class for the various Python data-format storage type APIs

Data-type handlers are specified using OpenGL.plugins module
é    N)Úpluginsc                   @   s´   e Zd ZdZi Zi ZdZdZdZdZ	dZ
ddgZg Zdd„ Zed	d
„ ƒZedd„ ƒZeeƒZddd„Zdd„ Zd dd„Zdd„ Zd!dd„Zdd„ Zd"dd„Zd#dd„Zd$dd„ZdS )%ÚFormatHandlerzÝAbstract class describing the handler interface

    Each data-type handler is responsible for providing a number of methods
    which allow it to manipulate (and create) instances of the data-type
    it represents.
    N© FÚnumpyZctypesarraysc                 C   s   t j ¡ D ]}|  |¡ q
dS )z8Load all OpenGL.plugins-registered FormatHandler classesN)r   r   ÚallÚ
loadPlugin)ÚclsÚ
entrypointr   r   úY/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/arrays/formathandler.pyÚloadAll   s    zFormatHandler.loadAllc           
   
   C   s®   |j sªddlm} z| ¡ }W nl tyŠ } zTddlm} ddlm} | 	d¡}|r\|j
}n|j}|d|j| |¡ƒ W Y d}~n"d}~0 0 |ƒ }	|	| ¡ |j< |	S d|_ dS )	z,Load a single entry-point via plugins moduler   ©ÚArrayDatatype)Úlogs)ÚWARN_ON_FORMAT_UNAVAILABLEzOpenGL.formathandlerz5Unable to load registered array format handler %s:
%sNT)ZloadedÚOpenGL.arrays.arraydatatyper   ÚloadÚImportErrorÚOpenGLr   ZOpenGL._configflagsr   ZgetLogÚwarnÚinfoÚnameZgetExceptionÚgetRegistry)
r   r	   r   Zplugin_classÚerrr   r   Ú_logZlogFuncÚhandlerr   r   r
   r   !   s(    
ýzFormatHandler.loadPluginc              
   C   s”   ddl m} | ¡ }z
|| W S  tyŽ } zXd|j|jf }| j |¡}|rl|  |¡ || W  Y d}~S td|f ƒ‚W Y d}~n
d}~0 0 dS )zLookup handler by data-typer   r   z%s.%sNz)Unable to find data-format handler for %s)	r   r   r   ÚKeyErrorÚ
__module__Ú__name__ÚLAZY_TYPE_REGISTRYÚgetr   )r   Útyper   Úregistryr   ÚkeyÚpluginr   r   r
   Ú
typeLookup>   s    

zFormatHandler.typeLookupc                 C   s    ddl m} | ¡  | |¡ dS )z5Register this class as handler for given set of typesr   r   N)r   r   r   Úregister)ÚselfÚtypesr   r   r   r
   r%   P   s    zFormatHandler.registerc                 C   s   ddl m} | ¡  | ¡ dS )z8Register this handler as the default return-type handlerr   r   N)r   r   r   ÚregisterReturn)r&   r   r   r   r
   r(   V   s    zFormatHandler.registerReturnc                 C   s   dS )z!Convert to a ctypes pointer valueNr   ©r&   ÚvalueZtypeCoder   r   r
   Ú
from_param\   s    zFormatHandler.from_paramc                 C   s   dS )zreturn long for pointer valueNr   ©r&   r*   r   r   r
   ÚdataPointer_   s    zFormatHandler.dataPointerc                 C   s   dS )z.Given a value, convert to array representationNr   r)   r   r   r
   ÚasArrayb   s    zFormatHandler.asArrayc                 C   s   dS )z=Given a value, guess OpenGL type of the corresponding pointerNr   r,   r   r   r
   ÚarrayToGLTypee   s    zFormatHandler.arrayToGLTypec                 C   s   dS )z6Given a data-value, calculate dimensions for the arrayNr   r)   r   r   r
   Ú	arraySizeh   s    zFormatHandler.arraySizec                 C   s   | j durdS dS )z-Determine unit size of an array (if possible)N)ÚbaseTyper)   r   r   r
   ÚunitSizek   s    
zFormatHandler.unitSizec                 C   s   dS )z<Determine dimensions of the passed array value (if possible)Nr   r)   r   r   r
   Ú
dimensionsp   s    zFormatHandler.dimensions)N)N)N)N)N)N)r   r   Ú__qualname__Ú__doc__r   ZHANDLER_REGISTRYr1   ZtypeConstantZHANDLED_TYPESZpreferredOutputZisOutputZGENERIC_OUTPUT_PREFERENCESZALL_OUTPUT_HANDLERSr   Úclassmethodr   r$   r%   r(   r+   r-   r.   r/   r0   r2   r3   r   r   r   r
   r   
   s2   






r   )r5   Úctypesr   r   Úobjectr   r   r   r   r
   Ú<module>   s   