This class implements the singleton pattern.
More...
#include <Singleton.hxx>
|
| template<class T = Instance, class ... Args> |
| static Instance & | CreateInstance (Args &&... args) |
| | Creates this singleton instance. More...
|
| |
| static bool | IsCreated (void) |
| | Determines if this singleton instance is create yet. More...
|
| |
| static Instance & | GetInstance (void) |
| | Gets a reference of the singleton instance. More...
|
| |
| static Instance * | GetInstancePtr (void) |
| | Deprecated! Gets a pointer to the singleton instance. More...
|
| |
| static void | DisposeInstance (void) |
| | Disposes this singleton instance. More...
|
| |
|
|
typedef Singleton< Derived > | SingletonBase |
| | Defines this type to be used from derived classes.
|
| |
|
|
| Singleton (void)=default |
| | The protected default constructor.
|
| |
|
| ~Singleton (void)=default |
| | The protected default destructor.
|
| |
|
| static void | SetInstance (Instance *pOther) |
| | Depreacated! Sets the singleton instance. More...
|
| |
| static void | AssignInstanceFrom (Instance &other) |
| | Assigns the singleton instance from another singleton instance of the same type. More...
|
| |
template<class Derived>
class Arp::Singleton< Derived >
This class implements the singleton pattern.
- Template Parameters
-
| Derived | The class to apply the singleton pattern to. |
Derive your own class called MyClass from Singleton<MyClass> to apply the singleton pattern to this class.
This class uses CRTP (Curiously recurring template pattern) to implement an own singleton instance for each derived class. For CRTP see: https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
◆ AssignInstanceFrom()
template<class Derived >
| void Arp::Singleton< Derived >::AssignInstanceFrom |
( |
Instance & |
other | ) |
|
|
inlinestaticprotected |
Assigns the singleton instance from another singleton instance of the same type.
- Parameters
-
| other | The singleton instance to assign to this instance. |
For internal use only.
This operation is used to distribute a singleton from one dynamic shared libraray to another, all providing their own set of static variables.
◆ CreateInstance()
template<class Derived >
template<class T , class ... Args>
Creates this singleton instance.
- Parameters
-
| args | The arguments passed to the constructor of T. Thus there must exists a constructor with a matching signature. |
- Returns
- The new created singleton instance.
- Template Parameters
-
| T | The type to create. Usually this is the derived type, but it might also be a polymorphic type. |
| Args | The argument list must comply to a constructor with a matching signature. |
◆ DisposeInstance()
Disposes this singleton instance.
Deletes the singleton instance pointer.
◆ GetInstance()
Gets a reference of the singleton instance.
- Returns
- The singleton instance as reference.
- Exceptions
-
| Exception | If the singleton instance was not created yet. |
◆ GetInstancePtr()
Deprecated! Gets a pointer to the singleton instance.
- Returns
- The singleton instance as pointer, if it was created yet, otherwise
nullptr.
\ depreacated Use &GetInstance() instead.
◆ IsCreated()
Determines if this singleton instance is create yet.
- Returns
true if this singleton was created yet, otherwise false.
◆ SetInstance()
Depreacated! Sets the singleton instance.
- Parameters
-
| pOther | The singleton instance to assign to this instance. |
For internal use only.
- Deprecated:
- Do not use this operation any more.
The documentation for this class was generated from the following file: