SPKFactory Class Reference

A singleton class that allows to easily define, create, destroy and organize SPARK objects (Registerable). More...

List of all members.

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.
Registerablecopy (SPK_ID ID)
 Creates a new Registerable object which is a copy of the object at the given ID.
Registerablecopy (const Registerable *registerable)
 Creates a new Registerable object which is a copy of the object.
Registerableget (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.
RegisterablefindByName (const std::string &name)
 Finds a registerable by name in the factory.

Static Public Member Functions

static SPKFactorygetInstance ()
 Returns the unique instance of the SPKFactory.

Detailed Description

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 :

Since:
1.03.00

Definition at line 117 of file SPK_Factory.h.


Member Function Documentation

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()).

Parameters:
registerable : the registered Registerable to copy
Returns:
a registered copy of the Registerable or NULL if the passed object is not registered
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.

Parameters:
ID : the ID of the Registerable to copy
Returns:
a registered copy of the Registerable or NULL if the passed ID is not registered
SPK_ID create ( const Registerable base  ) 

Creates a registered Registerable from the passed Registerable.

Parameters:
base : The Registerable to create the new registered Registerable from
Returns:
the ID of the new registered object
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.

Parameters:
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
Returns:
true if the Registerable has been deleted, false if not
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.

Parameters:
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
Returns:
true if the Registerable has been deleted, false if not
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.

Parameters:
name : the name of the registerable to find in the factory
Returns:
the first registerable with that name or NULL of none is found
Since:
1.05.00
Registerable* get ( SPK_ID  ID  ) 

Gets the Registerable of the given ID.

If the ID is not registered, NULL is returned

Parameters:
ID : the ID of the Registerable to get
Returns:
the Registerable with the passed ID or NULL if the ID is not registered
static SPKFactory& getInstance (  )  [static]

Returns the unique instance of the SPKFactory.

Returns:
the unique instance of the SPKFactory
size_t getNbObjects (  )  const

Returns the number of Regiterable objects registered in the SPKFactory.

Returns:
the number of Regiterable objects registered in the SPKFactoty

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()).

Parameters:
registerable : the Registerable to trace
void trace ( SPK_ID  ID  ) 

Trace information on the Registerable with the given ID.

Parameters:
ID : the ID of the Registerable to trace
void traceAll (  ) 

Trace information on all the registered Registerable within the SPKFactory.


Generated on Wed Apr 27 21:09:25 2011 for SPARK Particle Engine by  doxygen 1.6.1