B
      ›\h  ã               @   s8   d dl mZmZ d dlZd dlmZ G dd„ deƒZdS )é    )Úprint_functionÚabsolute_importN)Útypesc               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚDataModelManagerzBManages mapping of FE types to their corresponding data model
    c             C   s   i | _ t ¡ | _d S )N)Ú	_handlersÚweakrefÚWeakKeyDictionaryÚ_cache)Úself© r   ú6lib/python3.7/site-packages/numba/datamodel/manager.pyÚ__init__   s    zDataModelManager.__init__c             C   s   t |tjƒst‚|| j|< dS )zNRegister the datamodel factory corresponding to a frontend-type class
        N)Ú
issubclassr   ZTypeÚAssertionErrorr   )r
   Z	fetypeclsÚhandlerr   r   r   Úregister   s    zDataModelManager.registerc             C   sF   y
| j | S  tk
r   Y nX | jt|ƒ }|| |ƒ }| j |< |S )zMReturns the corresponding datamodel given the frontend-type instance
        )r	   ÚKeyErrorr   Útype)r
   Úfetyper   Zmodelr   r   r   Úlookup   s    
zDataModelManager.lookupc             C   s
   |   |¡S )zShorthand for lookup()
        )r   )r
   r   r   r   r   Ú__getitem__#   s    zDataModelManager.__getitem__c             C   s   t ƒ }| j ¡ |_|S )z’
        Make a copy of the manager.
        Use this to inherit from the default data model and specialize it
        for custom target.
        )r   r   Úcopy)r
   Zdmmr   r   r   r   (   s    zDataModelManager.copyN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r      s   r   )Z
__future__r   r   r   Znumbar   Úobjectr   r   r   r   r   Ú<module>   s   