PLCnext API Documentation 23.6.0.37
Static Public Member Functions | Protected Types | Protected Member Functions | List of all members
Arp::AppDomainSingleton< Derived > Class Template Reference

This class implements the singleton pattern for singletons with process wide scope. More...

#include <AppDomainSingleton.hxx>

Inheritance diagram for Arp::AppDomainSingleton< Derived >:
Inheritance graph

Static Public Member Functions

template<class T = Instance, class ... Args>
static Derived & CreateInstance (Args &&... args)
 Creates this singleton instance. More...
 
static bool IsCreated (void)
 Determines if this singleton instance is created yet. More...
 
static Derived & GetInstance (void)
 Gets a reference of the singleton instance. More...
 
static Derived * GetInstancePtr (void)
 Depreacated! Gets a pointer to the singleton instance. More...
 
static void DisposeInstance (void)
 Disposes this singleton instance. More...
 

Protected Types

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

Protected Member Functions

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

Detailed Description

template<class Derived>
class Arp::AppDomainSingleton< Derived >

This class implements the singleton pattern for singletons with process wide scope.

Template Parameters
DerivedThe class to apply the singleton pattern to.

Derive your own class called MyClass from AppDomainSingleton<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

◆ CreateInstance()

template<class Derived >
template<class T , class ... Args>
Derived & Arp::AppDomainSingleton< Derived >::CreateInstance ( Args &&...  args)
inlinestatic

Creates this 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 match a constructor's signature of T .
Parameters
argsThe arguments passed to the constructor of T . Thus there must exists a constructor of T with a matching signature.
Returns
The new created singleton instance as reference.

◆ DisposeInstance()

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

Disposes this singleton instance.

Deletes the singleton instance pointer.

◆ GetInstance()

template<class Derived >
Derived & Arp::AppDomainSingleton< 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::AppDomainSingleton< Derived >::GetInstancePtr ( void  )
inlinestatic

Depreacated! 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()

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

Determines if this singleton instance is created yet.

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

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