diff options
author | chai <chaifix@163.com> | 2018-12-06 17:26:07 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-12-06 17:26:07 +0800 |
commit | 4486beab7beb6a80ba6a89bfa73c0fbc9708ca74 (patch) | |
tree | deccf075c5236a03a8e0c715445367d47cd0f99d /src/libjin/common/je_singleton.hpp | |
parent | b3712ebdf148bd8d2d31e70734a4b7923f6038f8 (diff) |
*singleton
Diffstat (limited to 'src/libjin/common/je_singleton.hpp')
-rw-r--r-- | src/libjin/common/je_singleton.hpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libjin/common/je_singleton.hpp b/src/libjin/common/je_singleton.hpp index ba13b80..51dc9c5 100644 --- a/src/libjin/common/je_singleton.hpp +++ b/src/libjin/common/je_singleton.hpp @@ -2,6 +2,7 @@ #define __JE_SINGLETON_H__ #include "je_object.h" +#include "je_exception.h" namespace JinEngine { @@ -38,7 +39,12 @@ namespace JinEngine /// /// Singleton constructor. /// - Singleton() {}; + Singleton() + { + // Check singleton. + if (_instance) + throw Exception("This is a singleton."); + }; /// /// Singleton destructor. @@ -70,12 +76,8 @@ namespace JinEngine /// /// Singleton instance. /// - template<class T> T* Singleton<T>::_instance = nullptr; - - /// - /// Singleton notation. - /// - #define singleton(T) friend Singleton<T> + template<class T> + T* Singleton<T>::_instance = nullptr; } // namespace JinEngine |