summaryrefslogtreecommitdiffstats
path: root/src/common/singleton.h
diff options
context:
space:
mode:
authorPiotr Dziwiński <piotr.dziwinski@nsn.com>2013-02-16 22:37:43 +0100
committerPiotr Dziwiński <piotr.dziwinski@nsn.com>2013-02-17 12:11:56 +0100
commit001d37b257b126dd6ef1dced70f94ff3d2806d28 (patch)
tree1025979c635c899f196d606f7d74170e33ef4f3a /src/common/singleton.h
parent45040318b026f8864d244e39f1703685ad688470 (diff)
downloadcolobot-001d37b257b126dd6ef1dced70f94ff3d2806d28.tar.gz
colobot-001d37b257b126dd6ef1dced70f94ff3d2806d28.tar.bz2
colobot-001d37b257b126dd6ef1dced70f94ff3d2806d28.zip
CInstanceManager refactoring
* removed classes managed by CInstanceManager except for CObject, CPyro, CBrain and CPhysics because of dependencies * refactored instance searching to use existing singleton instances of CApplication, CEngine and CRobotMain and calling their getter functions
Diffstat (limited to 'src/common/singleton.h')
-rw-r--r--src/common/singleton.h77
1 files changed, 47 insertions, 30 deletions
diff --git a/src/common/singleton.h b/src/common/singleton.h
index c1b28d9..25e1648 100644
--- a/src/common/singleton.h
+++ b/src/common/singleton.h
@@ -26,34 +26,51 @@
template<typename T> class CSingleton
{
- protected:
- static T* mInstance;
-
- public:
- static T& GetInstance() {
- assert(mInstance != nullptr);
- return *mInstance;
- }
-
- static T* GetInstancePointer() {
- assert(mInstance != nullptr);
- return mInstance;
- }
-
- static bool IsCreated() {
- return mInstance != nullptr;
- }
-
- CSingleton() {
- assert(mInstance == nullptr);
- mInstance = static_cast<T *>(this);
- }
-
- virtual ~CSingleton() {
- mInstance = nullptr;
- }
-
- private:
- CSingleton& operator=(const CSingleton<T> &);
- CSingleton(const CSingleton<T> &);
+protected:
+ static T* m_instance;
+
+public:
+ static T& GetInstance()
+ {
+ assert(m_instance != nullptr);
+ return *m_instance;
+ }
+
+ static T* GetInstancePointer()
+ {
+ assert(m_instance != nullptr);
+ return m_instance;
+ }
+
+ static bool IsCreated()
+ {
+ return m_instance != nullptr;
+ }
+
+ CSingleton()
+ {
+ assert(m_instance == nullptr);
+ m_instance = static_cast<T *>(this);
+ }
+
+ virtual ~CSingleton()
+ {
+ m_instance = nullptr;
+ }
+
+ #ifdef TESTS
+ static void ReplaceInstance(T* newInstance)
+ {
+ assert(newInstance != nullptr);
+
+ if (m_instance != nullptr)
+ delete m_instance;
+
+ m_instance = newInstance;
+ }
+ #endif
+
+private:
+ CSingleton& operator=(const CSingleton<T> &);
+ CSingleton(const CSingleton<T> &);
};