![]() |
Base class for all lifetime managed singletons.The Singleton class represents the base class for all lifetime managed singletons of the Blaze library. Classes, which are supposed to be implemented in terms of the singleton pattern, only have to derive from this class in order to gain all basic characteristics of a singleton: More...
#include <Singleton.h>
Inherits blaze::NonCopyable.
Public Types | |
typedef Singleton< T, D1, D2, D3, D4, D5, D6, D7, D8 > | SingletonType |
Type of this Singleton instance. | |
Public Member Functions | |
typedef | BLAZE_TYPELIST_8 (D1, D2, D3, D4, D5, D6, D7, D8) Dependencies |
Type list of all lifetime dependencies. | |
Static Public Member Functions | |
Instance function | |
static std::shared_ptr< T > | instance () |
Protected Member Functions | |
Singleton () | |
Constructor for the Singleton class. More... | |
~Singleton () | |
Destructor for the Singleton class. | |
Private Attributes | |
Member variables | |
std::shared_ptr< D1 > | dependency1_ |
Handle to the first lifetime dependency. | |
std::shared_ptr< D2 > | dependency2_ |
Handle to the second lifetime dependency. | |
std::shared_ptr< D3 > | dependency3_ |
Handle to the third lifetime dependency. | |
std::shared_ptr< D4 > | dependency4_ |
Handle to the fourth lifetime dependency. | |
std::shared_ptr< D5 > | dependency5_ |
Handle to the fifth lifetime dependency. | |
std::shared_ptr< D6 > | dependency6_ |
Handle to the sixth lifetime dependency. | |
std::shared_ptr< D7 > | dependency7_ |
Handle to the seventh lifetime dependency. | |
std::shared_ptr< D8 > | dependency8_ |
Handle to the eighth lifetime dependency. | |
Base class for all lifetime managed singletons.
The Singleton class represents the base class for all lifetime managed singletons of the Blaze library. Classes, which are supposed to be implemented in terms of the singleton pattern, only have to derive from this class in order to gain all basic characteristics of a singleton:
The only prerequisite for classes deriving from the Singleton class template is the existance of a default constructor. In case no default constructor is available, the Blaze singleton functionality cannot be used!
When using the Singleton base class, lifetime dependencies between classes can be expressed very conveniently. The following example demonstrates this by means of the MySingleton class, which defines a lifetime dependency on the Logger class, which represents the core of the Blaze logging functionality:
In order to make a specific class a singleton, two modifications have to be applied to this class:
|
inlineexplicitprotected |
Constructor for the Singleton class.
In case a cyclic lifetime dependency is detected, a compilation error is created.