Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Singleton< T > Class Template Reference

Singleton class. More...

#include <Singleton.hxx>

Static Public Member Functions

static T * instance ()
 
static bool exists ()
 

Static Private Attributes

static T * instance_ = nullptr
 The singleton instance pointer.
 

Detailed Description

template<class T>
class Singleton< T >

Singleton class.

By inheriting from this class you declare that the descendants will have only a single instance in the running binary. This will allow accessing the running instance without passing around a pointer to it.

Usage:

class Foo;

class Foo: public Singleton<Foo> { ...as usual... };

DEFINE_SINGLETON_INSTANCE(Foo);

void appl_main() { Foo my_instance(constructor_args); }

somewhere else:

Foo::instance()->DoSomething();

Definition at line 65 of file Singleton.hxx.

Constructor & Destructor Documentation

◆ Singleton()

template<class T >
Singleton< T >::Singleton ( )
inline

Definition at line 67 of file Singleton.hxx.

◆ ~Singleton()

template<class T >
Singleton< T >::~Singleton ( )
inline

Definition at line 72 of file Singleton.hxx.

Member Function Documentation

◆ exists()

template<class T >
static bool Singleton< T >::exists ( )
inlinestatic
Returns
true if there is a class of this singleton instantiated.

Definition at line 83 of file Singleton.hxx.

◆ instance()

template<class T >
static T * Singleton< T >::instance ( )
inlinestatic
Returns
the singleton instance of this object.

Definition at line 77 of file Singleton.hxx.

Member Data Documentation

◆ instance_

template<class T >
T * Singleton< T >::instance_ = nullptr
staticprivate

The singleton instance pointer.

Definition at line 89 of file Singleton.hxx.


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