diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-11-20 16:38:51 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-11-20 16:38:51 +0100 |
commit | d002476c5e6b8f6bc728063fc8e7ce74da562e57 (patch) | |
tree | 0df9fb41ec09a96b6498a691d36164a6b4a6a7ca /src/Common | |
parent | 0a1df98c0420e9ac097622f2bddcd73a6488ed52 (diff) | |
download | mad-d002476c5e6b8f6bc728063fc8e7ce74da562e57.tar mad-d002476c5e6b8f6bc728063fc8e7ce74da562e57.zip |
SingletonPtr ueberarbeitet
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Configurable.h | 4 | ||||
-rw-r--r-- | src/Common/Initializable.h | 4 | ||||
-rw-r--r-- | src/Common/SingletonPtr.h | 37 |
3 files changed, 34 insertions, 11 deletions
diff --git a/src/Common/Configurable.h b/src/Common/Configurable.h index 90641a0..47f919d 100644 --- a/src/Common/Configurable.h +++ b/src/Common/Configurable.h @@ -20,15 +20,13 @@ #ifndef MAD_COMMON_CONFIGURABLE_H_ #define MAD_COMMON_CONFIGURABLE_H_ -#include "Initializable.h" - namespace Mad { namespace Common { class ConfigEntry; class ConfigManager; -class Configurable : virtual public Initializable { +class Configurable { public: virtual ~Configurable() {} diff --git a/src/Common/Initializable.h b/src/Common/Initializable.h index 27ab5bf..9f177da 100644 --- a/src/Common/Initializable.h +++ b/src/Common/Initializable.h @@ -25,8 +25,12 @@ namespace Mad { namespace Common { +template <typename T> class SingletonPtr; + class Initializable { private: + template <typename T> friend class SingletonPtr; + static std::stack<Initializable*> initializedObjects; static bool logInit; diff --git a/src/Common/SingletonPtr.h b/src/Common/SingletonPtr.h index ea4eda1..03d0040 100644 --- a/src/Common/SingletonPtr.h +++ b/src/Common/SingletonPtr.h @@ -21,6 +21,8 @@ #define MAD_COMMON_SINGLETONPTR_H_ #include "Initializable.h" +#include "Configurable.h" +#include "ConfigManager.h" namespace Mad { namespace Common { @@ -32,23 +34,42 @@ class SingletonPtr : public virtual Initializable { protected: virtual void doInit() { - if(ptr) - delete ptr; - ptr = new T(); Initializable *in = dynamic_cast<Initializable*>(ptr); - if(in) - in->init(); + if(in) { + in->initialized = true; + in->doInit(); + } + + Configurable *c = dynamic_cast<Configurable*>(ptr); + if(c) + ConfigManager::get()->registerConfigurable(c); + + if(in) { + initializing = false; + initialized = true; + } } - public: - SingletonPtr() : ptr(0) {} + virtual void doDeinit() { + Configurable *c = dynamic_cast<Configurable*>(ptr); + if(c) + ConfigManager::get()->unregisterConfigurable(c); + + Initializable *in = dynamic_cast<Initializable*>(ptr); + if(in) { + in->doDeinit(); + in->initialized = false; + } - virtual ~SingletonPtr() { delete ptr; + ptr = 0; } + public: + SingletonPtr() : ptr(0) {} + T *get() { if(!ptr) init(); |