pcce::Singleton< T > Class Template Reference

Singleton template class. More...

#include <Singleton.h>

List of all members.

Static Public Member Functions

static void Initialize ()
static void Shutdown ()
static boost::shared_ptr< T > Get ()
static bool IsInitialized ()

Static Private Attributes

static boost::shared_ptr< T > sT
static boost::mutex sMutex


Detailed Description

template<class T>
class pcce::Singleton< T >

Singleton template class.

This is a template class to automatically create thread-safe singletons. T should be a class with a default constructor. Note: While the Singleton class itself is thread-safe, it can make no guarantees about the class it manages. That must be handled seperately.

Definition at line 51 of file Singleton.h.


Member Function Documentation

template<class T>
static void pcce::Singleton< T >::Initialize (  )  [inline, static]

Definition at line 56 of file Singleton.h.

References PCCE_THROW, pcce::Singleton< T >::sMutex, and pcce::Singleton< T >::sT.

00056                              {
00057       boost::mutex::scoped_lock lock(sMutex);
00058       if (sT) {
00059         PCCE_THROW("Attempt to reinitialize singleton class");
00060       }
00061       sT.reset(new T());
00062     }

template<class T>
static void pcce::Singleton< T >::Shutdown (  )  [inline, static]

Definition at line 63 of file Singleton.h.

References PCCE_THROW, pcce::Singleton< T >::sMutex, and pcce::Singleton< T >::sT.

00063                            {
00064       boost::mutex::scoped_lock lock(sMutex);
00065       if (!sT) {
00066         PCCE_THROW("Attempt to shutdown unintialized singleton class");
00067       }
00068       if (sT.use_count() != 1) {
00069         PCCE_THROW("Attempt to shutdown singleton class while still in use");
00070       }
00071       sT.reset();
00072     }

template<class T>
static boost::shared_ptr<T> pcce::Singleton< T >::Get (  )  [inline, static]

template<class T>
static bool pcce::Singleton< T >::IsInitialized (  )  [inline, static]

Definition at line 80 of file Singleton.h.

References pcce::Singleton< T >::sMutex, and pcce::Singleton< T >::sT.

00080                                 {
00081       boost::mutex::scoped_lock lock(sMutex);
00082       return sT;
00083     }


Member Data Documentation

template<class T>
boost::shared_ptr< T > pcce::Singleton< T >::sT [inline, static, private]

template<class T>
boost::mutex pcce::Singleton< T >::sMutex [inline, static, private]


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

Generated on Thu Mar 6 11:39:28 2008 for Protocce by  doxygen 1.5.5