From d033400614e7e2c0ff49e5100c81e937e5818e74 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 28 Jul 2018 13:47:51 +0800 Subject: *update --- src/libjin/Common/Singleton.h | 38 ------------------------------------ src/libjin/Common/Singleton.hpp | 37 +++++++++++++++++++++++++++++++++++ src/libjin/Common/Subsystem.h | 43 ----------------------------------------- src/libjin/Common/Subsystem.hpp | 43 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 81 deletions(-) delete mode 100644 src/libjin/Common/Singleton.h create mode 100644 src/libjin/Common/Singleton.hpp delete mode 100644 src/libjin/Common/Subsystem.h create mode 100644 src/libjin/Common/Subsystem.hpp (limited to 'src/libjin/Common') diff --git a/src/libjin/Common/Singleton.h b/src/libjin/Common/Singleton.h deleted file mode 100644 index ff8a9ce..0000000 --- a/src/libjin/Common/Singleton.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __JIN_SINGLETON_H -#define __JIN_SINGLETON_H - -namespace jin -{ - template - class Singleton - { - public: - static T* get() - { - if (_instance == nullptr) - _instance = new T; - return _instance; - } - static void destroy() - { - delete _instance; - _instance = nullptr; - } - protected: - Singleton() {}; - virtual ~Singleton() {}; - private: - Singleton(const Singleton&); - Singleton& operator = (const Singleton&); - - static T* _instance; - }; - - template T* Singleton::_instance = nullptr; - -#define SINGLETON(T) \ - friend Singleton - -} // jin - -#endif \ No newline at end of file diff --git a/src/libjin/Common/Singleton.hpp b/src/libjin/Common/Singleton.hpp new file mode 100644 index 0000000..c3ce467 --- /dev/null +++ b/src/libjin/Common/Singleton.hpp @@ -0,0 +1,37 @@ +#ifndef __JIN_SINGLETON_H +#define __JIN_SINGLETON_H + +namespace jin +{ + template + class Singleton + { + public: + static T* get() + { + if (_instance == nullptr) + _instance = new T; + return _instance; + } + static void destroy() + { + delete _instance; + _instance = nullptr; + } + protected: + Singleton() {}; + virtual ~Singleton() {}; + static T* _instance; + private: + Singleton(const Singleton&); + Singleton& operator = (const Singleton&); + }; + + template T* Singleton::_instance = nullptr; + +#define SINGLETON(T) \ + friend Singleton + +} // jin + +#endif // __JIN_SINGLETON_H \ No newline at end of file diff --git a/src/libjin/Common/Subsystem.h b/src/libjin/Common/Subsystem.h deleted file mode 100644 index 8a4ecf6..0000000 --- a/src/libjin/Common/Subsystem.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __JIN_COMMON_SUBSYSTEM_H -#define __JIN_COMMON_SUBSYSTEM_H - -#include "singleton.h" -#include "../utils/macros.h" - -namespace jin -{ - - template - class Subsystem : public Singleton - { - public: - struct Setting {}; - typedef Setting SettingBase; - - bool init(const SettingBase* setting) - { - static bool success = initSystem(setting); - return success; - } - - void quit() - { - CALLONCE(quitSystem()); - destroy(); - } - - protected: - - Subsystem() {}; - virtual ~Subsystem() {}; - - SINGLETON(System); - - virtual onlyonce bool initSystem(const Setting* setting) = 0; - virtual onlyonce void quitSystem() = 0; - - }; - -} // jin - -#endif \ No newline at end of file diff --git a/src/libjin/Common/Subsystem.hpp b/src/libjin/Common/Subsystem.hpp new file mode 100644 index 0000000..f4e270b --- /dev/null +++ b/src/libjin/Common/Subsystem.hpp @@ -0,0 +1,43 @@ +#ifndef __JIN_COMMON_SUBSYSTEM_H +#define __JIN_COMMON_SUBSYSTEM_H + +#include "singleton.hpp" +#include "../utils/macros.h" + +namespace jin +{ + + template + class Subsystem : public Singleton + { + public: + struct Setting {}; + typedef Setting SettingBase; + + bool init(const SettingBase* setting) + { + static bool success = initSystem(setting); + return success; + } + + void quit() + { + CALLONCE(quitSystem()); + destroy(); + } + + protected: + + Subsystem() {}; + virtual ~Subsystem() {}; + + SINGLETON(System); + + virtual onlyonce bool initSystem(const Setting* setting) = 0; + virtual onlyonce void quitSystem() = 0; + + }; + +} // jin + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0