o
    i                     @  sv   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZmZmZ edZdd	 ZG d
d dZdS )    )annotations)
namedtuple)Iterable)	iskeyword)dedentindent)AnyCallableTypeVarTc                 C  s   |   ot|  S )zNReturns True if `name` is a valid Python variable name and also not a keyword.)isidentifierr   )name r   ]/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/utils/component_store.pyis_variable   s   r   c                   @  s   e Zd ZdZeddZd'd	d
Zd(ddZd)ddZe	d*ddZ
d+ddZd,ddZd-ddZdd  Zd.d"d#Zd.d$d%Zd&S )/ComponentStorea  
    Represents a storage object for other objects (specifically functions) keyed to a name with a description.

    These objects act as global named places for storing components for objects parameterised by component names.
    Typically this is functions although other objects can be added. Printing a component store will produce a
    list of members along with their docstring information if present.

    Example:

    .. code-block:: python

        TestStore = ComponentStore("Test Store", "A test store for demo purposes")

        @TestStore.add_def("my_func_name", "Some description of your function")
        def _my_func(a, b):
            '''A description of your function here.'''
            return a * b

        print(TestStore)  # will print out name, description, and 'my_func_name' with the docstring

        func = TestStore["my_func_name"]
        result = func(7, 6)

    
_Component)descriptionvaluer   strr   returnNonec                 C  s8   i | _ || _|| _d| d| d| jpd  | _d S )NComponent Store '': 
 )
componentsr   r   __doc__strip)selfr   r   r   r   r   __init__8   s   &zComponentStore.__init__descr   r   c                 C  s&   t |std| ||| j|< |S )zGStore the object `value` under the name `name` with description `desc`.z1Name of component must be valid Python identifier)r   
ValueErrorr   r   )r   r   r!   r   r   r   r   add?   s   zComponentStore.addr	   c                   s    fdd}|S )z]Returns a decorator which stores the decorated function under `name` with description `desc`.c                   s     | S )z'Decorator to add a function to a store.)r#   )funcr!   r   r   r   r   decoJ   s   z$ComponentStore.add_def.<locals>.decor   )r   r   r!   r&   r   r%   r   add_defG   s   zComponentStore.add_deftuple[str, ...]c                 C  
   t | jS )z-
        Produces all factory names.
        )tupler   r   r   r   r   namesP   s   
zComponentStore.namesboolc                 C  s
   || j v S )z)Returns True if the given name is stored.)r   r   r   r   r   r   __contains__X      
zComponentStore.__contains__intc                 C  r)   )z(Returns the number of stored components.)lenr   r+   r   r   r   __len__\   r0   zComponentStore.__len__r   c                 c  s&    | j  D ]
\}}||jfV  qdS )zYields name/component pairs.N)r   itemsr   )r   kvr   r   r   __iter__`   s   zComponentStore.__iter__c                 C  s   d| j  d| j d}| j D ]5\}}|d| d7 }t|jdr=|jjr=tt|jj	d
 d}|d| d7 }q|d	|j 7 }q|S )
Nr   r   z
Available components:z
* :r   r   z     )r   r   r   r4   hasattrr   r   r   r   lstriprstrip)r   resultr5   r6   docr   r   r   __str__e   s   zComponentStore.__str__r   c                 C  s    || j v r| j | jS | |S )/Returns the stored object under the given name.)r   r   __getattribute__r.   r   r   r   __getattr__r   s   

zComponentStore.__getattr__c                 C  s&   || j v r| j | jS td| d)r@   zComponent 'z' not found)r   r   r"   r.   r   r   r   __getitem__y   s   
zComponentStore.__getitem__N)r   r   r   r   r   r   )r   r   r!   r   r   r   r   r   )r   r   r!   r   r   r	   )r   r(   )r   r   r   r-   )r   r1   )r   r   )r   r   r   r   )__name__
__module____qualname__r   r   r   r    r#   r'   propertyr,   r/   r3   r7   r?   rB   rC   r   r   r   r   r      s    



	



r   N)
__future__r   collectionsr   collections.abcr   keywordr   textwrapr   r   typingr   r	   r
   r   r   r   r   r   r   r   <module>   s   