ANNA Suite  2020b
Multipurpose development suite for Telco applications
Static Public Member Functions | List of all members
anna::Singleton< T > Class Template Reference

#include <Singleton.hpp>

Inheritance diagram for anna::Singleton< T >:
Inheritance graph
[legend]

Static Public Member Functions

static T & instantiate ()
 
static void release ()
 

Detailed Description

template<class T>
class anna::Singleton< T >

Singleton pattern. Limits the use to a unique class instance.

Default constructor for T must be private in order to avoid external instantiation. Following, an example using class A:

On A class header file, we will have:

...
...
class A : public anna::Singleton <A> {
public:
// getters
int getData () const { return a_data; }
// setters
void setOtherData (const ASD& otherData) { a_otherData = otherData; }
// operators
....
// methods
...
private:
int a_data;
ASD a_otherData;
A ();
friend class functions::Singleton <A>;
};

To use A class:

#include <A.h>
...
...
void anyClass::anyFunction () noexcept(false)
{
A& a (A::instantiate ());
cout << a.getData () << endl;
}

Member Function Documentation

◆ instantiate()

template<class T>
static T& anna::Singleton< T >::instantiate ( )
inlinestatic
Returns
Class instance provided on template creation.
81 { return *alloc(true); }

◆ release()

template<class T>
static void anna::Singleton< T >::release ( )
inlinestatic

Release the class instance provided in this template creation. If no instance has been created, this will be ignored. This method only have to be used during the program termination.

88 { alloc(false); }

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