Ceylan::Singleton Class Reference

This helper class ensures that one and only one instance of a particular class exists, so that this instance is necessarily shared by all its users. More...

#include <CeylanSingleton.h>

Collaboration diagram for Ceylan::Singleton:

Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static SingletonGetSingleton ()
 Returns the one and only one Singleton instance available.
static void DeleteSingleton ()
 Removes the shared Singleton.

Protected Member Functions

 Singleton ()
 Basic constructor.
virtual ~Singleton () throw ()
 Basic virtual destructor.

Private Member Functions

 Singleton (const Singleton &source)
 Copy constructor made private to ensure that it will never be called.
Singletonoperator= (const Singleton &source)
 Assignment operator made private to ensure that it will never be called.

Static Private Attributes

static Singleton_InternalSingleton = 0
 The internal single instance.


Detailed Description

This helper class ensures that one and only one instance of a particular class exists, so that this instance is necessarily shared by all its users.

This class should be templated so that it can be used with any class that has to have only one instance at any time.

Another possible implementation would be:

static AClass::singleton() { static AClass singleton ; return singleton ; }

Note:
This implementation is mainly for explanation purpose.

Definition at line 74 of file CeylanSingleton.h.


Constructor & Destructor Documentation

Singleton::Singleton (  )  [protected]

Basic constructor.

Definition at line 109 of file CeylanSingleton.cc.

References Ceylan::toString().

Referenced by GetSingleton().

Singleton::~Singleton (  )  throw () [protected, virtual]

Basic virtual destructor.

Definition at line 119 of file CeylanSingleton.cc.

References Ceylan::toString().

Ceylan::Singleton::Singleton ( const Singleton source  )  [private]

Copy constructor made private to ensure that it will never be called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.

Note:
Made to avoid unwanted hidden clone of the Singleton.


Member Function Documentation

void Singleton::DeleteSingleton (  )  [static]

Removes the shared Singleton.

Definition at line 88 of file CeylanSingleton.cc.

Singleton & Singleton::GetSingleton (  )  [static]

Returns the one and only one Singleton instance available.

The returned value is a reference and not a pointer, to avoid any abnormal deallocation by its users, that should never deallocate the Singleton.

Definition at line 60 of file CeylanSingleton.cc.

References Singleton(), and Ceylan::toString().

Singleton& Ceylan::Singleton::operator= ( const Singleton source  )  [private]

Assignment operator made private to ensure that it will never be called.

The compiler should complain whenever this undefined operator is called, implicitly or not.


Member Data Documentation

Singleton * Singleton::_InternalSingleton = 0 [static, private]

The internal single instance.

Definition at line 135 of file CeylanSingleton.h.


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

Generated on Thu Jun 4 20:40:08 2009 for Ceylan by  doxygen 1.5.8