aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Common/Subsystem.hpp
blob: 59013c63e44649481ee965e66b79326d4b3a49f0 (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
44
#ifndef __JIN_COMMON_SUBSYSTEM_H
#define __JIN_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:

        Subsystem() {};
        virtual ~Subsystem() {};

        SINGLETON(System);

		/*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0;
		/*onlyonce*/ virtual void quitSystem() = 0;

    };

} // jin

#endif