-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleManager.h
55 lines (36 loc) · 1.21 KB
/
ModuleManager.h
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
45
46
47
48
49
50
51
52
53
#pragma once
#include <iostream>
#include <vector>
#include "AbstractModule.h"
#define ToBaseModule(_Mod) reinterpret_cast<AbstractModule*>(_Mod)
#define ToDirectModule(_Impl, _Mod) reinterpret_cast<_Impl*>(_Mod)
typedef void* HMOD;
class ModuleManager {
public:
static ModuleManager& getInstance();
template<class MODCLASS>
void addModule(MODCLASS* mod);
template <class MODCLASS>
MODCLASS* getModule(std::string modName);
void getModule(Category c, std::vector<HMOD>* out_modules);
void getModule(bool enabled, std::vector<HMOD>* out_modules);
ModuleManager(ModuleManager&&) = delete;
ModuleManager(const ModuleManager&) = delete;
ModuleManager& operator=(const ModuleManager&) = delete;
private:
std::vector<HMOD> modules;
ModuleManager();
~ModuleManager() = default;
};
template<class MODCLASS>
void ModuleManager::addModule(MODCLASS* mod) {
this->modules.push_back(reinterpret_cast<HMOD>(mod));
}
template<class MODCLASS>
MODCLASS* ModuleManager::getModule(std::string modName) {
for (auto iter = this->modules.cbegin(); iter < this->modules.cend(); iter++) {
if (::compareStringIgnoreCase(ToBaseModule(*iter)->getName(), modName))
return ToDirectModule(MODCLASS, *iter);
}
return nullptr;
}