
The singleton instance may be accessed through the getInstance() function. Singleton classes should be derived from this template in a manner similar to
class MySingleton : public Singleton<MySingleton> {...};
Friendly typedef their friend. This allows the Lifetime policies access to the class' ctor. Note, however, that the fact that only one instance may exist at a time remains untouched by the ctor access modifier. Attempts to create a second instance will lead to an assertion failure. Lifetime policy manages creation and destruction of the singleton instance. Developers may create their own policies to modify this behavior. This template assumes the Lifetime policy to have two member functions: static void initInstance()
static void destroyedError()
Automatic.
| T | the inheriting class | |
| Lifetime | the lifetime policy |
Static Public Member Functions | |
| static T * | getInstance () |
| accesses the singleton instance | |
| static bool | isActive () |
| checks if the singleton is active | |
| static bool | isDestroyed () |
| checks if the singleton is destroyed | |
| static bool | isVirgin () |
| checks if the singleton has not been initialized | |
Protected Types | |
| typedef Lifetime< T > | Friendly |
Protected Member Functions | |
| Singleton () | |
| virtual | ~Singleton () |
|
|||||
|
subclasses should declare this type their friend in order to allow access to ctor and dtor, as those should generally be made private. |
|
|||||||||
|
|
|
|||||||||
|
|
|
|||||||||
|
accesses the singleton instance The exact operation executed by calling this function is determined by the singleton policies.
|
|
|||||||||
|
checks if the singleton is active
|
|
|||||||||
|
checks if the singleton is destroyed
This function returns
|
|
|||||||||
|
checks if the singleton has not been initialized A singleton is not initialized if no instance exists and no instance has been destroyed.
|
1.4.3