API Guides > ConceptRT 3.x
Singleton< T > Class Template Reference

Singleton is a pattern that allows only one instance of a class. More...

Detailed Description

template<class T>
class ConceptRT::Singleton< T >

Singleton is a pattern that allows only one instance of a class.

Example :

class Example: public Singleton<Example>;
{
SINGLETON_CONSTRUCTOR(Example) {} // mandatory Either SINGLETON_CONSTRUCTOR(Example) {} or Either SINGLETON_CONSTRUCTOR(Example); with Example::Example() { code }
public:
};
Warning
Constructor must be declared in private and the parent class must be friend. Use SINGLETON_CONSTRUCTOR to simplify code.

Static Public Member Functions

static T * GetInstancePointer ()
 Gets the instance pointer. More...
 
static T & GetInstance ()
 Gets the instance. More...
 
static void DeleteInstance (bool allowNewCreation=false)
 Deletes the instance. More...
 
static bool IsCreated ()
 Query if the singleton instance has already been created. More...
 

Methods Documentation

void DeleteInstance ( bool  allowNewCreation = false)
static

Deletes the instance.

Parameters
allowNewCreation(optional) allow new creation after deletion is explicitly called. Default = false.
Warning
Non-Deterministic: Will delete the object if created. Determinism when using ConceptRT library can be ensure by using Context Time Critical mechanisms. Do nothing if the object has not been created first. If allowNewCreation is false, the singleton won't be able to be created after this call.
T & GetInstance ( )
static

Gets the instance.

Returns
The instance.
Warning
Non-Deterministic: May create the object if not yet created. Determinism when using ConceptRT library can be ensure by using Context Time Critical mechanisms.
RT Exceptions:

RT_ERROR_SINGLETON_RE_CREATION_NOT_ALLOWED

RT_ERROR_NEW_INSTANCE_NOT_ABLE_TO_CREATE

RT_ERROR_NON_DETERMINISTIC_CODE_NOT_ALLOWED

T * GetInstancePointer ( )
static

Gets the instance pointer.

Returns
The instance pointer.
Warning
Non-Deterministic: May create the object if not yet created. Determinism when using ConceptRT library can be ensure by using Context Time Critical mechanisms.
RT Exceptions:

RT_ERROR_SINGLETON_RE_CREATION_NOT_ALLOWED

RT_ERROR_NEW_INSTANCE_NOT_ABLE_TO_CREATE

bool IsCreated ( )
static

Query if the singleton instance has already been created.

Returns
true if created.