PARTONS
|
PARtonic Tomography Of Nucleon Software
|
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... | |
BaseObject * | get (unsigned int classId) const |
Try to find stored object identified by its unique class identifier. More... | |
BaseObject * | get (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 BaseObjectRegistry * | getInstance () |
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... | |
BaseObject * | isAvailable (const std::string &className) const |
Try to find an object into the registry by its class name. More... | |
BaseObject * | isAvailable (const unsigned int classId) const |
Try to find an object into the registry by its class identifier. More... | |
BaseObject * | getLastAvailableObjectIdentifiedByClassName () const |
Return last referenced object by the iterator on m_translateList. More... | |
BaseObject * | getLastAvailableObjectIdentifiedByClassId () const |
Return last referenced object by the iterator on m_baseObjectList. More... | |
BaseObjectRegistry (BaseObjectRegistry const &other) | |
BaseObjectRegistry & | operator= (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 BaseObjectRegistry * | m_pInstance = 0 |
Private pointer of this class for a unique instance. More... | |
static unsigned int | m_uniqueClassIdCounter = 0 |
Increment unique class identifier. More... | |
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.
|
virtual |
Default destructor.
|
private |
Private default constructor for a unique instance.
|
private |
BaseObject * PARTONS::BaseObjectRegistry::get | ( | const std::string & | className | ) | const |
Try to find stored object identified by its class name.
className |
BaseObject * PARTONS::BaseObjectRegistry::get | ( | unsigned int | classId | ) | const |
Try to find stored object identified by its unique class identifier.
classId |
|
static |
Static function to be able to retrieve a unique instance pointer of this class anywhere in the code.
|
private |
Return last referenced object by the iterator on m_baseObjectList.
|
private |
Return last referenced object by the iterator on m_translateList.
unsigned int PARTONS::BaseObjectRegistry::getObjectClassIdByClassName | ( | const std::string & | className | ) |
|
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.
|
private |
Try to find an object into the registry by its class name.
className |
|
private |
Try to find an object into the registry by its class identifier.
classId |
|
private |
unsigned int PARTONS::BaseObjectRegistry::registerBaseObject | ( | BaseObject * | pBaseObject | ) |
Store a unique instance of a module identified by a unique string character key.
pBaseObject | an instance of the module built by its default constructor. |
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_t PARTONS::BaseObjectRegistry::size | ( | ) | const |
Return the size of the registry.
How many objects are stored.
|
virtual |
Print information about current state of the registry (size of the registry, which objects are stored, ...).
|
private |
List of registered objects identified by their unique integer identifier.
|
private |
Translation map between class id and class name.
|
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.
|
staticprivate |
Private pointer of this class for a unique instance.
|
private |
List of registered objects identified by their class name.
|
staticprivate |
Increment unique class identifier.