diff options
Diffstat (limited to 'src/libjin/Common')
-rw-r--r-- | src/libjin/Common/Data.h | 15 | ||||
-rw-r--r-- | src/libjin/Common/Singleton.h | 38 | ||||
-rw-r--r-- | src/libjin/Common/Subsystem.h | 42 |
3 files changed, 95 insertions, 0 deletions
diff --git a/src/libjin/Common/Data.h b/src/libjin/Common/Data.h new file mode 100644 index 0000000..6f1c504 --- /dev/null +++ b/src/libjin/Common/Data.h @@ -0,0 +1,15 @@ +#ifndef __JIN_COMMON_DATA_H +#define __JIN_COMMON_DATA_H + +namespace jin +{ + + struct Buffer + { + unsigned int len; + char data[0]; + }; + +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Common/Singleton.h b/src/libjin/Common/Singleton.h new file mode 100644 index 0000000..a6c7d6d --- /dev/null +++ b/src/libjin/Common/Singleton.h @@ -0,0 +1,38 @@ +#ifndef __JIN_SINGLETON_H +#define __JIN_SINGLETON_H + +namespace jin +{ + template<class T> + 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<class T> T* Singleton<T>::_instance = nullptr; + +#define SINGLETON(T) \ + friend Singleton<T> + +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Common/Subsystem.h b/src/libjin/Common/Subsystem.h new file mode 100644 index 0000000..35563da --- /dev/null +++ b/src/libjin/Common/Subsystem.h @@ -0,0 +1,42 @@ +#ifndef __JIN_COMMON_SUBSYSTEM_H +#define __JIN_COMMON_SUBSYSTEM_H + +#include "singleton.h" +#include "../utils/macros.h" + +namespace jin +{ + + template<class System> + class Subsystem : public Singleton<System> + { + public: + struct Setting {}; + typedef Setting SettingBase; + + void init(const SettingBase* setting) + { + CALLONCE(initSystem(setting)); + } + + void quit() + { + CALLONCE(quitSystem()); + destroy(); + } + + protected: + + Subsystem() {}; + virtual ~Subsystem() {}; + + SINGLETON(System); + + virtual onlyonce bool initSystem(const Setting* setting) = 0; + virtual onlyonce void quitSystem() = 0; + + }; + +} + +#endif
\ No newline at end of file |