PLCnext API Documentation 23.3.0.32
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | List of all members
Arp::Singleton< Derived > Class Template Reference

This class implements the singleton pattern. More...

#include <Singleton.hxx>

Static Public Member Functions

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)
 Gets a pointer to the singleton instance. More...
 
static void DisposeInstance (void)
 Disposes this singleton instance. More...
 

Protected Types

typedef Singleton< Derived > SingletonBase
 Defines this type to be used from derived classes.
 

Protected Member Functions

 Singleton (void)=default
 The protected default constructor.
 
 ~Singleton (void)=default
 The protected default destructor.
 

Static Protected Member Functions

static void SetInstance (Instance *pOther)
 Sets the singleton instance. More...
 
static void AssignInstanceFrom (Instance &other)
 Assigns the singleton instance from another singleton instance of the same type. More...
 

Detailed Description

template<class Derived>
class Arp::Singleton< Derived >

This class implements the singleton pattern.

Template Parameters
DerivedThe 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

Member Function Documentation

◆ 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
otherThe 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>
Singleton< Derived >::Instance & Arp::Singleton< Derived >::CreateInstance ( Args &&...  args)
inlinestatic

Creates this singleton instance.

Parameters
argsThe 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
TThe type to create. Usually this is the derived type, but it might also be a polymorphic type.
ArgsThe argument list must comply to a constructor with a matching signature.

◆ DisposeInstance()

template<class Derived >
void Arp::Singleton< Derived >::DisposeInstance ( void  )
inlinestatic

Disposes this singleton instance.

Deletes the singleton instance pointer.

◆ GetInstance()

template<class Derived >
Derived & Arp::Singleton< Derived >::GetInstance ( void  )
inlinestatic

Gets a reference of the singleton instance.

Returns
The singleton instance as reference.
Exceptions
ExceptionIf the singleton instance was not created yet.

◆ GetInstancePtr()

template<class Derived >
Derived * Arp::Singleton< Derived >::GetInstancePtr ( void  )
inlinestatic

Gets a pointer to the singleton instance.

Returns
The singleton instance as pointer, if it was created yet, otherwise nullptr.

◆ IsCreated()

template<class Derived >
bool Arp::Singleton< Derived >::IsCreated ( void  )
inlinestatic

Determines if this singleton instance is create yet.

Returns
true if this singleton was created yet, otherwise false.

◆ SetInstance()

template<class Derived >
void Arp::Singleton< Derived >::SetInstance ( Instance *  pOther)
inlinestaticprotected

Sets the singleton instance.

Parameters
pOtherThe singleton instance to assign to this instance.

For internal use only.


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