Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Singleton Class Template Reference

Allows for one instance of a class - Can decide when created and when destroyed. More...

#include <Singleton.h>

Inheritance diagram for Singleton:

Inheritance graph
[legend]
Collaboration diagram for Singleton:

Collaboration graph
[legend]
List of all members.

Public Methods

 Singleton ()
 ~Singleton ()

Static Public Methods

T & GetSingleton ()
T * GetSingletonPtr ()

Detailed Description

template<typename T>
class Singleton< T >

Allows for one instance of a class - Can decide when created and when destroyed.


Constructor & Destructor Documentation

template<typename T>
Singleton< T >::Singleton   [inline]
 

00025     {
00026         assert(!ms_Singleton && "Pointer to ms_Singleton is NULL");
00027         int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
00028         ms_Singleton = (T*)((int)this + offset);
00029     }

template<typename T>
Singleton< T >::~Singleton   [inline]
 

00032     {
00033         assert(ms_Singleton && "Nothing to destroy");
00034         ms_Singleton = 0;
00035     }


Member Function Documentation

template<typename T>
T& Singleton< T >::GetSingleton   [inline, static]
 

00038     {
00039         assert(ms_Singleton && "Singleton not initialized correctly");
00040         return (*ms_Singleton);
00041     }

template<typename T>
T* Singleton< T >::GetSingletonPtr   [inline, static]
 

00044     {
00045         return (ms_Singleton);
00046     }


The documentation for this class was generated from the following file:
Generated on Mon Oct 22 20:19:21 2001 for University People Management System by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001