Blaze  3.6
Public Types | Protected Member Functions | List of all members
blaze::Singleton< T, D1, D2, D3, D4, D5, D6, D7, D8 > Class Template Reference

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

using SingletonType = Singleton< T, D1, D2, D3, D4, D5, D6, D7, D8 >
 Type of this Singleton instance.
 
using Dependencies = TypeList< D1, D2, D3, D4, D5, D6, D7, D8 >
 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.
 

Detailed Description

template<typename T, typename D1 = NullType, typename D2 = NullType, typename D3 = NullType, typename D4 = NullType, typename D5 = NullType, typename D6 = NullType, typename D7 = NullType, typename D8 = NullType>
class blaze::Singleton< T, D1, D2, D3, D4, D5, D6, D7, D8 >

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 another singleton called Logger:

// Definition of the MySingleton class
class MySingleton : private Singleton<MySingleton,Logger>
{
private:
MySingleton();
...
...
};

In order to make a specific class a singleton, two modifications have to be applied to this class:

  1. The class has to derive (publicly or non-publicly) from the Singleton class. In case the class derives publicly the instance() member function, which the class inherits from the Singleton class, is publicly accessible and provides a point of access to the singleton instance. In case the class derives non-publicly, the instance() function is not publicly accessible and therefore the class has to provide another point of access to the singleton instance.
    The first template parameter has to be the class itself. The following template parameters define lifetime dependencies of this class, i.e., specify on which singleton instances the class depends. It is possible to specify up to 8 lifetime dependencies. The example above demonstrates this for the MySingleton class, which is solely depending on another singleton called Logger.
  2. The class needs to befriend the Singleton via the blaze::BLAZE_BEFRIEND_SINGLETON macro. This macro provides a convenient way to express this friendship relation and works both in case the class derives publicly or non-publicly from the Singleton class. This friendship is necessary since in order to guarantee the uniqueness of the singleton instance the constructor of the deriving class must be declared in a non-public section of the class definition. However, in order for the Singleton class to provide the instance() function, the constructor must be accessible. This is achieved by the blaze::BLAZE_BEFRIEND_SINGLETON macro.

Constructor & Destructor Documentation

◆ Singleton()

template<typename T , typename D1 = NullType, typename D2 = NullType, typename D3 = NullType, typename D4 = NullType, typename D5 = NullType, typename D6 = NullType, typename D7 = NullType, typename D8 = NullType>
blaze::Singleton< T, D1, D2, D3, D4, D5, D6, D7, D8 >::Singleton ( )
inlineexplicitprotected

Constructor for the Singleton class.

In case a cyclic lifetime dependency is detected, a compilation error is created.


The documentation for this class was generated from the following file: