Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
BIAS::Singleton< T > Class Template Reference

Simple singleton implementation for multithreaded applications. More...

#include <Base/Common/Singleton.hh>

+ Inheritance diagram for BIAS::Singleton< T >:
+ Collaboration diagram for BIAS::Singleton< T >:

Static Public Member Functions

static T * GetInstance ()
 

Protected Member Functions

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

Static Protected Member Functions

static void DeleteInstance_ ()
 
static pthread_mutex_t * Mutex_ ()
 

Static Protected Attributes

static T * Instance_ = NULL
 static members More...
 

Detailed Description

template<class T>
class BIAS::Singleton< T >

Simple singleton implementation for multithreaded applications.

  To use this template to create a singleton of class MyClass do the following:

  /code

  #include <Base/Common/Singleton.hh>

  class MyClass :public Singleton<MyClass> {
  public: 

some functionality of class MyClass void foo();

....

constructor must be protected to let parent class access, but not ordinary users protected: make sure that class MyClass cannot be used as non-singleton by declaring constructors and copy operator private MyClass(); MyClass(const &MyClass); MyClass& operator=(const &MyClass); };

/ exemplary usage MyClassSingleton::GetInstance()->foo();

/endcode

The code wraps a previous defined class MyClass as a singleton. The Singleton class exposes a single function GetInstance() returning a pointer to MyClass. This function creates the single instance of MyClass if it is not already present and registers the DeleteInstance_() function with the atexit() function from the stdlib resulting in automatic destruction of the singleton when the application terminates.

Author
woelk 10/2007
Examples:
ExampleSingleton.cpp.

Definition at line 86 of file Singleton.hh.

Constructor & Destructor Documentation

template<class T >
BIAS::Singleton< T >::Singleton ( )
protected

Definition at line 120 of file Singleton.hh.

template<class T>
BIAS::Singleton< T >::Singleton ( const Singleton< T > &  t)
protected

Definition at line 125 of file Singleton.hh.

template<class T >
BIAS::Singleton< T >::~Singleton ( )
protected

Definition at line 130 of file Singleton.hh.

Member Function Documentation

template<class T >
void BIAS::Singleton< T >::DeleteInstance_ ( )
staticprotected

Definition at line 188 of file Singleton.hh.

References BIAS::SingletonDebugOutput_.

template<class T >
T * BIAS::Singleton< T >::GetInstance ( )
static
Examples:
ExampleProgressSemaphore.cpp, and ExampleSingleton.cpp.

Definition at line 152 of file Singleton.hh.

References BIAS::SingletonDebugOutput_.

template<class T >
pthread_mutex_t * BIAS::Singleton< T >::Mutex_ ( )
staticprotected

Definition at line 143 of file Singleton.hh.

template<class T >
Singleton< T > & BIAS::Singleton< T >::operator= ( const Singleton< T > &  t)
protected

Definition at line 135 of file Singleton.hh.

Member Data Documentation

template<class T>
T * BIAS::Singleton< T >::Instance_ = NULL
staticprotected

static members

Definition at line 98 of file Singleton.hh.


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