cxxtools::Singleton< T, A > Class Template Reference

Singleton class template. More...

#include <cxxtools/singleton.h>

Public Types

typedef A Allocator

Static Public Member Functions

static T & instance ()
 Returns the instance of the singleton type.

Protected Member Functions

 Singleton ()
 Constructor.
 ~Singleton ()
 Destructor.

Detailed Description

template<typename T, typename A = std::allocator<T>>
class cxxtools::Singleton< T, A >

Singleton class template.

Parameters
TType of the singleton
AAllocator for type T

The Singleton class template can be used to easily implement the Singleton design pattern. It can either be used directly or as a base class. An allocator can be used to control how the singleton instance will be allocated.

The follwing example shows how to use the singleton as a base class:

class MySingleton : public Singleton<MySingleton>
{
friend class Singleton<MySingleton>;
// ...
};

Member Typedef Documentation

template<typename T , typename A = std::allocator<T>>
typedef A cxxtools::Singleton< T, A >::Allocator

Constructor & Destructor Documentation

template<typename T , typename A = std::allocator<T>>
cxxtools::Singleton< T, A >::Singleton ( )
inlineprotected

Constructor.

template<typename T , typename A = std::allocator<T>>
cxxtools::Singleton< T, A >::~Singleton ( )
inlineprotected

Destructor.

Member Function Documentation

template<typename T , typename A = std::allocator<T>>
static T& cxxtools::Singleton< T, A >::instance ( )
inlinestatic

Returns the instance of the singleton type.

When called for the first time, the singleton instance will be
created with the specified alloctaor. All subsequent calls wikk
return a reference to the previously created instance.
Returns
The singleton instance

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