PARTONS  
PARtonic Tomography Of Nucleon Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PARTONS::BaseObjectRegistry Class Reference

The Registry is the analog of a phonebook, which lists all available objects (modules or services most of the time) identified by a unique integer identifier or by a unique string (class name) for translation. More...

Public Member Functions

virtual ~BaseObjectRegistry ()
 Default destructor. More...
 
unsigned int registerBaseObject (BaseObject *pBaseObject)
 Store a unique instance of a module identified by a unique string character key. More...
 
void resolveBaseObjectDependencies ()
 Some objects like modules depend on each other. More...
 
BaseObjectget (unsigned int classId) const
 Try to find stored object identified by its unique class identifier. More...
 
BaseObjectget (const std::string &className) const
 Try to find stored object identified by its class name. More...
 
virtual std::string toString () const
 Print information about current state of the registry (size of the registry, which objects are stored, ...). More...
 
size_t size () const
 Return the size of the registry. More...
 
unsigned int getObjectClassIdByClassName (const std::string &className)
 

Static Public Member Functions

static BaseObjectRegistrygetInstance ()
 Static function to be able to retrieve a unique instance pointer of this class anywhere in the code. More...
 

Private Member Functions

 BaseObjectRegistry ()
 Private default constructor for a unique instance. More...
 
unsigned int getUniqueClassId ()
 For performance purposes, it's faster to compare two integers than two strings when we search for an object in the registry. More...
 
BaseObjectisAvailable (const std::string &className) const
 Try to find an object into the registry by its class name. More...
 
BaseObjectisAvailable (const unsigned int classId) const
 Try to find an object into the registry by its class identifier. More...
 
BaseObjectgetLastAvailableObjectIdentifiedByClassName () const
 Return last referenced object by the iterator on m_translateList. More...
 
BaseObjectgetLastAvailableObjectIdentifiedByClassId () const
 Return last referenced object by the iterator on m_baseObjectList. More...
 
 BaseObjectRegistry (BaseObjectRegistry const &other)
 
BaseObjectRegistryoperator= (BaseObjectRegistry const &other)
 

Private Attributes

sf::Mutex m_mutex
 Because of PARTONS is a program using threads we must ensure that only one object manipulates the registry at the same time to avoid memory access violation. More...
 
std::map< unsigned int, BaseObject * > m_baseObjectList
 List of registered objects identified by their unique integer identifier. More...
 
std::map< std::string, BaseObject * > m_translateList
 List of registered objects identified by their class name. More...
 
std::map< std::string, unsigned int > m_classIdByClassName
 Translation map between class id and class name. More...
 

Static Private Attributes

static BaseObjectRegistrym_pInstance = 0
 Private pointer of this class for a unique instance. More...
 
static unsigned int m_uniqueClassIdCounter = 0
 Increment unique class identifier. More...
 

Detailed Description

The Registry is the analog of a phonebook, which lists all available objects (modules or services most of the time) identified by a unique integer identifier or by a unique string (class name) for translation.

And only one species of each.

From the point of view of software engineering, the registry corresponds to the singleton design pattern which ensures that it is unique. When a new module or services are created, the first thing to do is to call this unique instance, and to register the new module or services with a name provided by the developer of the class. In turn the Registry gives a unique identifier encoded in a integer variable for performance purposes. Registry stores pointers to all objects in a generic way, i.e. whatever their nature are: pointers to GPDModule, to RunningAlphaStrongModule, to AutomationService, etc. This is achieved by requiring all objects to derive from a single parent class named BaseObject.

Constructor & Destructor Documentation

◆ ~BaseObjectRegistry()

PARTONS::BaseObjectRegistry::~BaseObjectRegistry ( )
virtual

Default destructor.

◆ BaseObjectRegistry() [1/2]

PARTONS::BaseObjectRegistry::BaseObjectRegistry ( )
private

Private default constructor for a unique instance.

◆ BaseObjectRegistry() [2/2]

PARTONS::BaseObjectRegistry::BaseObjectRegistry ( BaseObjectRegistry const &  other)
private

Member Function Documentation

◆ get() [1/2]

BaseObject * PARTONS::BaseObjectRegistry::get ( const std::string &  className) const

Try to find stored object identified by its class name.

Parameters
className
Returns
reference to object in memory or throw an exception

◆ get() [2/2]

BaseObject * PARTONS::BaseObjectRegistry::get ( unsigned int  classId) const

Try to find stored object identified by its unique class identifier.

Parameters
classId
Returns
reference to object in memory or throw an exception

◆ getInstance()

BaseObjectRegistry * PARTONS::BaseObjectRegistry::getInstance ( )
static

Static function to be able to retrieve a unique instance pointer of this class anywhere in the code.

Returns
a unique instance of this class

◆ getLastAvailableObjectIdentifiedByClassId()

BaseObject* PARTONS::BaseObjectRegistry::getLastAvailableObjectIdentifiedByClassId ( ) const
private

Return last referenced object by the iterator on m_baseObjectList.

Returns
Reference to the object in memory.

◆ getLastAvailableObjectIdentifiedByClassName()

BaseObject* PARTONS::BaseObjectRegistry::getLastAvailableObjectIdentifiedByClassName ( ) const
private

Return last referenced object by the iterator on m_translateList.

Returns
Reference to the object in memory.

◆ getObjectClassIdByClassName()

unsigned int PARTONS::BaseObjectRegistry::getObjectClassIdByClassName ( const std::string &  className)

◆ getUniqueClassId()

unsigned int PARTONS::BaseObjectRegistry::getUniqueClassId ( )
private

For performance purposes, it's faster to compare two integers than two strings when we search for an object in the registry.

This method return a unique integer identifier when a new class object is added to the registry. It's just an integer incremented one by one.

Returns
Unique identifier by class.

◆ isAvailable() [1/2]

BaseObject * PARTONS::BaseObjectRegistry::isAvailable ( const std::string &  className) const
private

Try to find an object into the registry by its class name.

Parameters
className
Returns
Pointer to object if class name found into registry, NULL else.

◆ isAvailable() [2/2]

BaseObject * PARTONS::BaseObjectRegistry::isAvailable ( const unsigned int  classId) const
private

Try to find an object into the registry by its class identifier.

Parameters
classId
Returns
Pointer to object if class name found into registry, NULL else.

◆ operator=()

BaseObjectRegistry& PARTONS::BaseObjectRegistry::operator= ( BaseObjectRegistry const &  other)
private

◆ registerBaseObject()

unsigned int PARTONS::BaseObjectRegistry::registerBaseObject ( BaseObject pBaseObject)

Store a unique instance of a module identified by a unique string character key.

Parameters
pBaseObjectan instance of the module built by its default constructor.
Returns
A unique identifier by class

◆ resolveBaseObjectDependencies()

void PARTONS::BaseObjectRegistry::resolveBaseObjectDependencies ( )

Some objects like modules depend on each other.

But it is impossible to guarantee the order in which they are added to the registry will be made upon the resolution of statics variables (mechanism of self-registration) So we need to perform this task just before the use of PARTONS software to resolve dependencies between all kind of registered objects.

◆ size()

size_t PARTONS::BaseObjectRegistry::size ( ) const

Return the size of the registry.

How many objects are stored.

Returns
Registry size.

◆ toString()

std::string PARTONS::BaseObjectRegistry::toString ( ) const
virtual

Print information about current state of the registry (size of the registry, which objects are stored, ...).

Returns
string

Member Data Documentation

◆ m_baseObjectList

std::map<unsigned int, BaseObject*> PARTONS::BaseObjectRegistry::m_baseObjectList
private

List of registered objects identified by their unique integer identifier.

◆ m_classIdByClassName

std::map<std::string, unsigned int> PARTONS::BaseObjectRegistry::m_classIdByClassName
private

Translation map between class id and class name.

◆ m_mutex

sf::Mutex PARTONS::BaseObjectRegistry::m_mutex
mutableprivate

Because of PARTONS is a program using threads we must ensure that only one object manipulates the registry at the same time to avoid memory access violation.

It's performed by a mechanism called mutex or semaphore.

◆ m_pInstance

BaseObjectRegistry * PARTONS::BaseObjectRegistry::m_pInstance = 0
staticprivate

Private pointer of this class for a unique instance.

◆ m_translateList

std::map<std::string, BaseObject*> PARTONS::BaseObjectRegistry::m_translateList
private

List of registered objects identified by their class name.

◆ m_uniqueClassIdCounter

unsigned int PARTONS::BaseObjectRegistry::m_uniqueClassIdCounter = 0
staticprivate

Increment unique class identifier.


The documentation for this class was generated from the following files: