Source code for ska_sdp_piper.piper.named_instance
[docs]
class NamedInstance(type):
"""
Metaclass to manage named instances
Attributes
----------
_instances: dict
Mapping between cls, name and instance
"""
_instances = {}
[docs]
@classmethod
def get_instance(cls, name):
return cls._instances.get(name, None)
def __call__(cls, name, *args, **kwargs):
"""
Creates mapping between cls, name and instance of cls
Parameters
----------
cls: class
Class to instantiate
name: str
Name of the instance.
*args
Additional args
**kwargs
Additional named args
Returns
-------
Instance of cls
"""
new_instance = super(NamedInstance, cls).__call__(
name, *args, **kwargs
)
cls._instances[name] = new_instance
return new_instance