aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Common/je_singleton.hpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-21 13:37:27 +0800
committerchai <chaifix@163.com>2018-10-21 13:37:27 +0800
commit066e5987c515dfc34537d73ca9d2a81ddd1f9e1b (patch)
treeec45fe523daa4f9e8a30db0a045a0eb9cee84822 /src/libjin/Common/je_singleton.hpp
parent3292019e55dd02a96420e72bad88711fd36ef249 (diff)
*注释
Diffstat (limited to 'src/libjin/Common/je_singleton.hpp')
-rw-r--r--src/libjin/Common/je_singleton.hpp49
1 files changed, 46 insertions, 3 deletions
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 T>
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<class T> T* Singleton<T>::_instance = nullptr;
-#define singleton(T) friend Singleton<T>
+ ///
+ /// Singleton notation.
+ ///
+ #define singleton(T) friend Singleton<T>
} // namespace JinEngine