blob: 78f4e01e67bf37c4182ce32877993135357761f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#ifndef __LIBJIN_COMMON_SUBSYSTEM_H
#define __LIBJIN_COMMON_SUBSYSTEM_H
#include "singleton.hpp"
#include "../utils/macros.h"
namespace jin
{
template<class System>
class Subsystem : public Singleton<System>
{
public:
struct Setting {};
typedef Setting SettingBase;
bool init(const SettingBase* setting = nullptr)
{
static bool success = initSystem(setting);
return success;
}
void quit()
{
/*call only once*/
static char __dummy__ = (quitSystem(), 1);
Singleton<System>::destroy();
}
protected:
SINGLETON(System);
Subsystem() {};
virtual ~Subsystem() {};
/*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0;
/*onlyonce*/ virtual void quitSystem() = 0;
};
} // jin
#endif
|