RSC  0.7.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rsc::patterns::Singleton< T > Class Template Reference

This template class implements the singleton pattern. More...

#include <Singleton.h>

Inheritance diagram for rsc::patterns::Singleton< T >:
Inheritance graph
Collaboration diagram for rsc::patterns::Singleton< T >:
Collaboration graph

Public Member Functions

virtual ~Singleton ()
 

Static Public Member Functions

static T & getInstance ()
 Retrieve the singleton instance, creating it if necessary. More...
 
static void killInstance ()
 This function can be used to make sure the instance is deleted at a particular time. More...
 

Static Private Member Functions

static boost::shared_ptr< T > & getStorage ()
 
static boost::mutex & getInstanceMutex ()
 
static void createMutex (boost::mutex *&destination)
 

Detailed Description

template<typename T>
class rsc::patterns::Singleton< T >

This template class implements the singleton pattern.

To add singleton behavior to a class T, add Singleton<T> to its list of base classes.

Note
T has to contain a friend declaration for Singleton<T>.
This class is thread-safe and can be used in static initializations
For allowing the use inside static initialization code, the absurd amount of work for the mutex is necessary.
Author
Jan Moringen jmori.nosp@m.nge@.nosp@m.techf.nosp@m.ak.u.nosp@m.ni-bi.nosp@m.elef.nosp@m.eld.d.nosp@m.e

Definition at line 51 of file Singleton.h.

Constructor & Destructor Documentation

template<typename T >
rsc::patterns::Singleton< T >::~Singleton ( )
virtual

Definition at line 113 of file Singleton.h.

Member Function Documentation

template<typename T >
void rsc::patterns::Singleton< T >::createMutex ( boost::mutex *&  destination)
staticprivate

Definition at line 85 of file Singleton.h.

Referenced by rsc::patterns::Singleton< T >::getInstanceMutex().

Here is the caller graph for this function:

template<typename T >
T & rsc::patterns::Singleton< T >::getInstance ( )
static

Retrieve the singleton instance, creating it if necessary.

Returns
A reference to the instance.

Definition at line 99 of file Singleton.h.

template<typename T >
boost::mutex & rsc::patterns::Singleton< T >::getInstanceMutex ( )
staticprivate

Definition at line 90 of file Singleton.h.

References rsc::patterns::Singleton< T >::createMutex().

Here is the call graph for this function:

template<typename T >
boost::shared_ptr< T > & rsc::patterns::Singleton< T >::getStorage ( )
staticprivate

Definition at line 129 of file Singleton.h.

template<typename T >
void rsc::patterns::Singleton< T >::killInstance ( )
static

This function can be used to make sure the instance is deleted at a particular time.

You may need this function to enforce a certain order of destruction.

Note
The instance will be destroyed in any case but the order of destruction is unspecified then.

Definition at line 117 of file Singleton.h.


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