Static Public Member Functions | Private Member Functions | Static Private Attributes

Singleton< T > Class Template Reference

A simple implementation of the Singleton pattern. More...

#include <Singleton.h>

List of all members.

Static Public Member Functions

static T & get ()
static void instantiateDerived (T *t)
static void clean ()

Private Member Functions

 Singleton ()
 ~Singleton ()
 Singleton (const Singleton &s)
Singleton< T > & operator= (const Singleton &s)

Static Private Attributes

static T * mInstance = 0

Detailed Description

template<typename T>
class Singleton< T >

A simple implementation of the Singleton pattern.

This is a very basic implementation of the Singleton pattern used for getting Singleton's to the core utilities in LoM.

Warning:
This class is not thread safe. Singletons must be instantiated from the main thread of any application that uses them.
Note:
Singleton offers only basic exception safety. If an exception occurs during instantiation of its internal type the exception will not be caught. In general practice using any of the core utility classes, an exception being thrown indicates a serious error that must be address by the client.
Warning:
Singleton offers a static member method Singleton::clean(). This should only ever be used when nothing is using the instance of T (e.g., at the end of a program.

Constructor & Destructor Documentation

template<typename T>
Singleton< T >::Singleton (  )  [inline, private]
template<typename T>
Singleton< T >::~Singleton (  )  [inline, private]
template<typename T>
Singleton< T >::Singleton ( const Singleton< T > &  s  )  [private]

Member Function Documentation

template<typename T>
static void Singleton< T >::clean (  )  [inline, static]

Frees any currently instantiated instances of T.

Warning:
This should only ever be called when no other instances are being used.
template<typename T>
static T& Singleton< T >::get (  )  [inline, static]

Gets an instance of the specified type T. If an instance hasn't yet been created, one is created.

template<typename T>
static void Singleton< T >::instantiateDerived ( T *  t  )  [inline, static]

Sets the internal type T to a type that derives from T.

Note:
This function expects that the parameter T is created in the function call (e.g., Singleton<T>::instantiateDerived(new T()).
Warning:
This function is only intended to be used in very special cases where the caller needs to instantiate an object that derives from type T.
If the caller needs a derived type T, this function must be called before Singleton::get();
Singleton takes ownership of whatever pointer is based into this function. Deleting it outside of the Singleton yields undefined behavior.
template<typename T>
Singleton<T>& Singleton< T >::operator= ( const Singleton< T > &  s  )  [private]

Member Data Documentation

template<typename T>
T * Singleton< T >::mInstance = 0 [static, private]

Internal instance of type T.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines