A singleton class that allows to easily define, create, destroy and organize SPARK objects (Registerable). More...
Public Member Functions | |
size_t | getNbObjects () const |
Returns the number of Regiterable objects registered in the SPKFactory. | |
SPK_ID | create (const Registerable &base) |
Creates a registered Registerable from the passed Registerable. | |
Registerable * | copy (SPK_ID ID) |
Creates a new Registerable object which is a copy of the object at the given ID. | |
Registerable * | copy (const Registerable *registerable) |
Creates a new Registerable object which is a copy of the object. | |
Registerable * | get (SPK_ID ID) |
Gets the Registerable of the given ID. | |
bool | destroy (SPK_ID ID, bool checkNbReferences=true) |
Destroys the Registerable with the given ID and all its destroyable children. | |
bool | destroy (Registerable *registerable, bool checkNbReferences=true) |
Destroys the Registerable and all its destroyable children. | |
void | destroyAll () |
Destroys all the registered Registerable in the SPKFactory. | |
void | trace (SPK_ID ID) |
Trace information on the Registerable with the given ID. | |
void | trace (const Registerable *registerable) |
Trace information on the Registerable. | |
void | traceAll () |
Trace information on all the registered Registerable within the SPKFactory. | |
Registerable * | findByName (const std::string &name) |
Finds a registerable by name in the factory. | |
Static Public Member Functions | |
static SPKFactory & | getInstance () |
Returns the unique instance of the SPKFactory. |
A singleton class that allows to easily define, create, destroy and organize SPARK objects (Registerable).
A Registerable can either be registered or not. A Registerable created with the SPKFactory becomes registered : it is given a unique ID and is stored within a map in the SPKFactory.
the SPKFactory allows the correct copy of a Registerable with all its children Registerable. Children registerable are only copied within the given Registerable if they are not shared (see Registerable) else only the reference to the shared Registerable is copied
Moreover, destruction of Registerable and all children is very easy with the factory. Destroying a Registerable will destroy and all its children which are destroyable and only referenced within the Registerable being destroyed.
Note that the process is recursive through the tree, so destroyable children of destroyable children will be destroyed as well and so on.
4 main actions are performed by the SPKFactory :
Note that macros are implemented to ease the syntax :
Definition at line 117 of file SPK_Factory.h.
Registerable* copy | ( | const Registerable * | registerable | ) |
Creates a new Registerable object which is a copy of the object.
If the passed Registerable is NULL or not registered, NULL is returned.
Note that this function call internally copy(registerable->getSPKID()).
registerable | : the registered Registerable to copy |
Registerable* copy | ( | SPK_ID | ID | ) |
Creates a new Registerable object which is a copy of the object at the given ID.
If no Registerable with this ID is registered, NULL is returned.
ID | : the ID of the Registerable to copy |
SPK_ID create | ( | const Registerable & | base | ) |
Creates a registered Registerable from the passed Registerable.
base | : The Registerable to create the new registered Registerable from |
bool destroy | ( | Registerable * | registerable, | |
bool | checkNbReferences = true | |||
) |
Destroys the Registerable and all its destroyable children.
If the Registerable is NULL or is not registered, nothing is destroyed and false is returned.
Note that this function call internally destroy(registerable->getSPKID()).
see destroy(SPK_ID,bool) for more information.
registerable | the Registerable to destroy | |
checkNbReferences | : true to destroy only a Registerable with no references in the SPKFactory (safer), false not to perform the check |
bool destroy | ( | SPK_ID | ID, | |
bool | checkNbReferences = true | |||
) |
Destroys the Registerable with the given ID and all its destroyable children.
If the ID is not registered, nothing is destroyed and false is returned.
The checkNbReferences boolean tells the factory if the number of references of the Registerable to be destroyed has to be checked.
If set to true, the Registerable will be destroyed only if the number or references within the SPKFactory (ie in all registered object in the SPKFactory) is 0.
If set to false, the Registerable will be destroyed in any case. Meaning that any reference within the SPKFactory becomes invalid.
ID | : the ID of the Registerable to destroy | |
checkNbReferences | : true to destroy only a Registerable with no references in the SPKFactory (safer), false not to perform the check |
void destroyAll | ( | ) |
Destroys all the registered Registerable in the SPKFactory.
Registerable* findByName | ( | const std::string & | name | ) |
Finds a registerable by name in the factory.
Note that this method only checks registerables in the SPKFactory.
This method does not call the Registerable::findByName(const string&) of the registerables to check recursively.
name | : the name of the registerable to find in the factory |
Registerable* get | ( | SPK_ID | ID | ) |
Gets the Registerable of the given ID.
If the ID is not registered, NULL is returned
ID | : the ID of the Registerable to get |
static SPKFactory& getInstance | ( | ) | [static] |
Returns the unique instance of the SPKFactory.
size_t getNbObjects | ( | ) | const |
Returns the number of Regiterable objects registered in the SPKFactory.
Definition at line 270 of file SPK_Factory.h.
void trace | ( | const Registerable * | registerable | ) |
Trace information on the Registerable.
Note that this function call internally trace(registerable->getSPKID()).
registerable | : the Registerable to trace |
void trace | ( | SPK_ID | ID | ) |
Trace information on the Registerable with the given ID.
ID | : the ID of the Registerable to trace |
void traceAll | ( | ) |
Trace information on all the registered Registerable within the SPKFactory.