From 066e5987c515dfc34537d73ca9d2a81ddd1f9e1b Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 21 Oct 2018 13:37:27 +0800 Subject: =?UTF-8?q?*=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Common/je_singleton.hpp | 49 +++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'src/libjin/Common/je_singleton.hpp') diff --git a/src/libjin/Common/je_singleton.hpp b/src/libjin/Common/je_singleton.hpp index f37f3af..e981e7a 100644 --- a/src/libjin/Common/je_singleton.hpp +++ b/src/libjin/Common/je_singleton.hpp @@ -4,33 +4,76 @@ namespace JinEngine { + /// + /// Singleton base class. + /// template class Singleton { public: + /// + /// Get singleton. + /// + /// @param Singleton instance of class. + /// static T* get() { if (_instance == nullptr) _instance = new T; return _instance; } + + /// + /// Destroy instance of singleton. + /// static void destroy() { delete _instance; _instance = nullptr; } + protected: + /// + /// Singleton constructor. + /// Singleton() {}; + + /// + /// Singleton destructor. + /// virtual ~Singleton() {}; + + /// + /// Singleton instance. + /// static T* _instance; + private: - Singleton(const Singleton&); - Singleton& operator = (const Singleton&); + /// + /// Singleton copy constructor. + /// + /// @param singleton Singleton of class. + /// + Singleton(const Singleton& singleton); + + /// + /// Singleton assignment. + /// + /// @param singleton Singleton of class. + /// + Singleton& operator = (const Singleton& singleton); + }; + /// + /// Singleton instance. + /// template T* Singleton::_instance = nullptr; -#define singleton(T) friend Singleton + /// + /// Singleton notation. + /// + #define singleton(T) friend Singleton } // namespace JinEngine -- cgit v1.1-26-g67d0