PLCnext API Documentation 25.0.2.69
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | List of all members
Arp::Base::Core::Singleton< T > Class Template Reference

This class implements the singleton pattern. More...

#include <Singleton.hxx>

Public Member Functions

 ARP_DEPRECATED ("Use Singleton<T>::GetInstance() or Singleton<T>::IsCreated() yet.") static Instance *GetInstancePtr(void)
 

Static Public Member Functions

template<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 void DisposeInstance (void)
 Disposes this singleton instance. More...
 

Protected Types

using SingletonBase = Singleton< T >
 Defines this type to be used from derived classes.
 

Protected Member Functions

 Singleton (void)
 The protected default constructor.
 
 Singleton (const Singleton &arg)=delete
 
Singletonoperator= (const Singleton &arg)=delete
 
 Singleton (Singleton &&arg)=delete
 
Singletonoperator= (Singleton &&arg)=delete
 
 ~Singleton (void)
 The protected destructor.
 

Static Protected Member Functions

static Ptr & GetStaticInstancePtr (void)
 
static void SetInstance (T *pInstance)
 DEPRECATED. More...
 

Detailed Description

template<class T>
class Arp::Base::Core::Singleton< T >

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

◆ CreateInstance()

template<class T >
template<typename ... Args>
Singleton< T >::Instance & Arp::Base::Core::Singleton< T >::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.
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 T >
void Arp::Base::Core::Singleton< T >::DisposeInstance ( void  )
inlinestatic

Disposes this singleton instance.

Deletes the singleton instance pointer.

◆ GetInstance()

template<class T >
Singleton< T >::Instance & Arp::Base::Core::Singleton< T >::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.

◆ IsCreated()

template<class T >
bool Arp::Base::Core::Singleton< T >::IsCreated ( void  )
inlinestatic

Determines if this singleton instance is create yet.

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

◆ SetInstance()

template<class T >
void Arp::Base::Core::Singleton< T >::SetInstance ( T *  pInstance)
inlinestaticprotected

DEPRECATED.

Do not use this operation any more.


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