Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ONE::util::Singleton< T, Lifetime > Class Template Reference

Inheritance diagram for ONE::util::Singleton< T, Lifetime >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class T, template< class > class Lifetime = Automatic>
class ONE::util::Singleton< T, Lifetime >

template for classes that allow only one active instance.

The singleton instance may be accessed through the getInstance() function. Singleton classes should be derived from this template in a manner similar to

 class MySingleton : public Singleton<MySingleton> {...}; 
Such classes should have a private constructor and declare the Friendly typedef their friend. This allows the Lifetime policies access to the class' ctor. Note, however, that the fact that only one instance may exist at a time remains untouched by the ctor access modifier. Attempts to create a second instance will lead to an assertion failure.
The Lifetime policy manages creation and destruction of the singleton instance. Developers may create their own policies to modify this behavior. This template assumes the Lifetime policy to have two member functions:
 static void initInstance() 
which is called when the singleton has not yet been instantiated, and
 static void destroyedError() 
which is called when a user tries to access the instance after it has been destroyed. The default lifetime policy is Automatic.

Parameters:
T the inheriting class
Lifetime the lifetime policy
Author:
Daniel Seibert


Static Public Member Functions

static T * getInstance ()
 accesses the singleton instance
static bool isActive ()
 checks if the singleton is active
static bool isDestroyed ()
 checks if the singleton is destroyed
static bool isVirgin ()
 checks if the singleton has not been initialized

Protected Types

typedef Lifetime< T > Friendly

Protected Member Functions

 Singleton ()
virtual ~Singleton ()


Member Typedef Documentation

template<class T, template< class > class Lifetime = Automatic>
typedef Lifetime<T> ONE::util::Singleton< T, Lifetime >::Friendly [protected]
 

subclasses should declare this type their friend in order to allow access to ctor and dtor, as those should generally be made private.


Constructor & Destructor Documentation

template<class T, template< class > class Lifetime>
ONE::util::Singleton< T, Lifetime >::Singleton  )  [inline, protected]
 

template<class T, template< class > class Lifetime>
ONE::util::Singleton< T, Lifetime >::~Singleton  )  [inline, protected, virtual]
 


Member Function Documentation

template<class T, template< class > class Lifetime>
T * ONE::util::Singleton< T, Lifetime >::getInstance  )  [inline, static]
 

accesses the singleton instance

The exact operation executed by calling this function is determined by the singleton policies.

Returns:
a pointer to the singleton instance

template<class T, template< class > class Lifetime>
bool ONE::util::Singleton< T, Lifetime >::isActive  )  [inline, static]
 

checks if the singleton is active

Returns:
if the singleton is instantiated

template<class T, template< class > class Lifetime>
bool ONE::util::Singleton< T, Lifetime >::isDestroyed  )  [inline, static]
 

checks if the singleton is destroyed

This function returns true if an instance existed and was destroyed. Note that in some cases it is possible to revive a singleton.

Returns:
if the singleton is destroyed

template<class T, template< class > class Lifetime>
bool ONE::util::Singleton< T, Lifetime >::isVirgin  )  [inline, static]
 

checks if the singleton has not been initialized

A singleton is not initialized if no instance exists and no instance has been destroyed.

Returns:
if the singleton is untouched


Generated on Wed Sep 7 19:03:33 2005 for ONEngine by  doxygen 1.4.3