aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/common/je_subsystem.hpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-18 23:31:17 +0800
committerchai <chaifix@163.com>2018-11-18 23:31:17 +0800
commitf0f340dec7821cee103ab9267ef941a917ef4dc4 (patch)
tree2f77f6ce6bdc9f63f002c13d4c261e1d6a9c1729 /src/libjin/common/je_subsystem.hpp
parentfc7b4579e49aaeecc81919e247e03f68bd5abfd4 (diff)
*目录改为小写
Diffstat (limited to 'src/libjin/common/je_subsystem.hpp')
-rw-r--r--src/libjin/common/je_subsystem.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/libjin/common/je_subsystem.hpp b/src/libjin/common/je_subsystem.hpp
new file mode 100644
index 0000000..c015bef
--- /dev/null
+++ b/src/libjin/common/je_subsystem.hpp
@@ -0,0 +1,78 @@
+#ifndef __JE_COMMON_SUBSYSTEM_H__
+#define __JE_COMMON_SUBSYSTEM_H__
+
+#include "../utils/je_macros.h"
+
+#include "je_singleton.hpp"
+
+namespace JinEngine
+{
+
+ ///
+ /// Subsystem class.
+ ///
+ template<class System>
+ class Subsystem : public Singleton<System>
+ {
+ public:
+ ///
+ /// Subsystem setting.
+ ///
+ struct Setting
+ {
+ };
+
+ typedef Setting SettingBase;
+
+ ///
+ /// Initialize subsystem.
+ ///
+ /// @param setting Subsystem setting.
+ /// @return True if initialize sucessful, otherwise return false.
+ ///
+ bool init(const SettingBase* setting = nullptr)
+ {
+ static bool success = initSystem(setting);
+ return success;
+ }
+
+ ///
+ /// Quit subsystem.
+ ///
+ void quit()
+ {
+ // Call only once.
+ static char __dummy__ = (quitSystem(), 1);
+ Singleton<System>::destroy();
+ }
+
+ protected:
+ singleton(System);
+
+ ///
+ /// Subsystem constructor.
+ ///
+ Subsystem() {};
+
+ ///
+ /// Subsystem destructor.
+ ///
+ virtual ~Subsystem()
+ {
+ };
+
+ ///
+ /// Initializer callback.
+ ///
+ virtual bool initSystem(const Setting* setting) = 0;
+
+ ///
+ /// Quit subsystem callback.
+ ///
+ virtual void quitSystem() = 0;
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file