a
    §ˆcb  ã                   @   s2   d Z ddlmZ G dd„ deƒZeƒ Zdd„ ZdS )z8 Helper functions to automatically generate unique IDs. é    )ÚWeakKeyDictionaryc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_ObjectCounterz Counts objects. c                 C   s   t ƒ | _d S )N)r   Ú_objects_registry)Úself© r   úX/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/util/id_helper.pyÚ__init__   s    z_ObjectCounter.__init__c                 C   s   || j v r| j | }nd}|S )z\ Return the number of times an object was seen.

        Objects must be hashable.

        r   )r   ©r   ÚobjÚcountr   r   r   Ú	get_count   s    
z_ObjectCounter.get_countc                 C   s"   |   |¡}|d | j|< | j| S )zi Increase and return the number of times an object was seen.

        Objects must be hashable.

        é   )r   r   r	   r   r   r   Ú
next_count%   s    
z_ObjectCounter.next_countN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s   r   c                 C   s&   | j }|j}t |¡}|d t|ƒ S )z¯ Return a unique ID of the form ClassName_X, where X is an integer.

    It is only guaranteed that IDs are unique to a specific Python session, not
    across sessions.

    Ú_)Ú	__class__r   Úobject_counterr   Ústr)ÚobjectÚclass_ÚnameÚnumberr   r   r   Úget_unique_id5   s    
r   N)r   Úweakrefr   r   r   r   r   r   r   r   r   Ú<module>   s   !