/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-source/src/controllers/controllermanager.h
Line | Count | Source |
1 | | #pragma once |
2 | | #include <functional> |
3 | | #include <map> |
4 | | #include <memory> |
5 | | #include <string> |
6 | | #include <vector> |
7 | | |
8 | | #include "controllers/playercontroller.h" |
9 | | |
10 | | namespace mahjong { |
11 | | using newControllerInst = std::function<std::unique_ptr<PlayerController>()>; |
12 | | |
13 | | class ControllerManager { |
14 | | public: |
15 | 1.15k | static ControllerManager& Instance() { |
16 | 1.15k | static ControllerManager controller_manager; |
17 | 1.15k | return controller_manager; |
18 | 1.15k | } |
19 | | |
20 | 34 | std::map<std::string, newControllerInst> GetAvailableControllersMap() { |
21 | 34 | return available_controllers_; |
22 | 34 | } |
23 | | std::vector<std::string> GetAvailableControllers(); |
24 | | std::unique_ptr<mahjong::PlayerController> NewController( |
25 | | const std::string& controller); |
26 | | bool RegisterController(newControllerInst newFunc, const std::string& Name); |
27 | | |
28 | | private: |
29 | | std::map<std::string, newControllerInst> available_controllers_; |
30 | | }; |
31 | | |
32 | | #define REGISTER_PLAYER_CONTROLLER(controller) \ |
33 | | namespace { \ |
34 | | bool __registered = ControllerManager::Instance().RegisterController( \ |
35 | | &controller::New, #controller); \ |
36 | | } |
37 | | |
38 | | } // namespace mahjong |