MIRA
Public Types | Static Public Member Functions | List of all members
Singleton< T, TInstantiationPolicy, TCreationPolicy, TLifetimePolicy, TLockPolicy > Class Template Reference

A singleton template class that can be freely configured using policies that control the instantiation, creation, lifetime and thread-safety. More...

#include <utils/Singleton.h>

Inheritance diagram for Singleton< T, TInstantiationPolicy, TCreationPolicy, TLifetimePolicy, TLockPolicy >:
Inheritance graph
[legend]

Public Types

typedef Base::Type Type
 

Static Public Member Functions

static Typeinstance ()
 Returns a reference to the singleton instance. More...
 
static bool isDestroyed ()
 Returns true, if the singleton was already destroyed. More...
 

Detailed Description

template<typename T, template< class > class TInstantiationPolicy = singleton::LazyInstantiation, template< class > class TCreationPolicy = singleton::CreateUsingNew, template< class > class TLifetimePolicy = singleton::NormalLifetime, class TLockPolicy = singleton::MutexLock>
class mira::Singleton< T, TInstantiationPolicy, TCreationPolicy, TLifetimePolicy, TLockPolicy >

A singleton template class that can be freely configured using policies that control the instantiation, creation, lifetime and thread-safety.

Using this template class you can create singletons that meet all your needs by specifying different combination of policies as template parameters.

Instantiation Policies:

Creation Policies:

Lifetime Policies:

Lock Policies:

Example Usage:

class MySingleton : public Singleton<MySingleton,
singleton::LazyInstantiation,
singleton::CreateUsingNew,
singleton::NormalLifetime,
singleton::NoLock>
{
public:
...
void foo();
};
...
MySingleton::instance().foo();

For convenience some of commonly used policy combinations are provided by

Member Typedef Documentation

◆ Type

typedef Base::Type Type

Member Function Documentation

◆ instance()

static Type& instance ( )
inlinestatic

Returns a reference to the singleton instance.

Exceptions
XLogicalIf the singleton was already destroyed (dead reference) or not yet created (when using ExplicitInstantiation).

◆ isDestroyed()

static bool isDestroyed ( )
inlinestatic

Returns true, if the singleton was already destroyed.

Trying to access it will result in an exception.


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