#include <Singleton.h>
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 |
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.
| 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 }
| 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 }
| static boost::shared_ptr<T> pcce::Singleton< T >::Get | ( | ) | [inline, static] |
Definition at line 73 of file Singleton.h.
References PCCE_THROW, pcce::Singleton< T >::sMutex, and pcce::Singleton< T >::sT.
Referenced by pcce::EventConnectionManager::AddHandler(), pcce::SoundStream::DoDispatchEvent(), pcce::SoundBuffer::DoDispatchEvent(), pcce::Scene::GetGameObject(), pcce::Protocce::Initialize(), pcce::InputTranslator::ReceiveKeyboardInput(), pcce::InputTranslator::ReceiveMouseButtonInput(), pcce::InputTranslator::ReceiveMouseMoveInput(), pcce::Scene::RemoveEntity(), pcce::Protocce::RunGame(), pcce::SetActiveInputTranslator(), pcce::EventType< pcce::SoundStreamEvent >::sGetEventType(), pcce::Protocce::Shutdown(), pcce::IThreadedSubSystem::ThreadStart(), pcce::InputSubSystem::vInitialize(), pcce::IResource::~IResource(), pcce::IThreadedSubSystem::~IThreadedSubSystem(), and pcce::Scene::~Scene().
00073 { 00074 boost::mutex::scoped_lock lock(sMutex); 00075 if (!sT) { 00076 PCCE_THROW("Attempt to use unintialized singleton class"); 00077 } 00078 return sT; 00079 }
| 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.
boost::shared_ptr< T > pcce::Singleton< T >::sT [inline, static, private] |
Definition at line 53 of file Singleton.h.
Referenced by pcce::Singleton< T >::Get(), pcce::Singleton< T >::Initialize(), pcce::Singleton< T >::IsInitialized(), and pcce::Singleton< T >::Shutdown().
boost::mutex pcce::Singleton< T >::sMutex [inline, static, private] |
Definition at line 54 of file Singleton.h.
Referenced by pcce::Singleton< T >::Get(), pcce::Singleton< T >::Initialize(), pcce::Singleton< T >::IsInitialized(), and pcce::Singleton< T >::Shutdown().
1.5.5