[Orxonox-commit 1713] r6431 - code/branches/gamestate/src/libraries/util
rgrieder at orxonox.net
rgrieder at orxonox.net
Tue Dec 29 19:16:37 CET 2009
Author: rgrieder
Date: 2009-12-29 19:16:36 +0100 (Tue, 29 Dec 2009)
New Revision: 6431
Modified:
code/branches/gamestate/src/libraries/util/Singleton.h
Log:
Extended Singleton<T> with a exists() method.
Modified: code/branches/gamestate/src/libraries/util/Singleton.h
===================================================================
--- code/branches/gamestate/src/libraries/util/Singleton.h 2009-12-29 09:40:29 UTC (rev 6430)
+++ code/branches/gamestate/src/libraries/util/Singleton.h 2009-12-29 18:16:36 UTC (rev 6431)
@@ -50,10 +50,16 @@
//! Returns a reference to the singleton instance
static T& getInstance()
{
- assert(T::singletonPtr_s != 0);
+ assert(T::singletonPtr_s != NULL);
return *T::singletonPtr_s;
}
+ //! Tells whether the singleton has been created
+ static bool exists()
+ {
+ return (T::singletonPtr_s != NULL);
+ }
+
//! Update method called by ClassSingletonManager (if used)
void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); }
//! Empty update method for the static polymorphism
@@ -67,15 +73,15 @@
//! Constructor sets the singleton instance pointer
Singleton()
{
- assert(T::singletonPtr_s == 0);
+ assert(T::singletonPtr_s == NULL);
T::singletonPtr_s = static_cast<T*>(this);
}
//! Constructor resets the singleton instance pointer
~Singleton()
{
- assert(T::singletonPtr_s != 0);
- T::singletonPtr_s = 0;
+ assert(T::singletonPtr_s != NULL);
+ T::singletonPtr_s = NULL;
}
private:
More information about the Orxonox-commit
mailing list