-
Notifications
You must be signed in to change notification settings - Fork 1
/
Config.h
executable file
·41 lines (38 loc) · 1.19 KB
/
Config.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
#pragma once
#include "AntTweakBar.h"
#include <string>
#include <map>
// Simple key-value store for (global) configuration with ATB callbacks.
namespace Config {
template<typename T>
struct TypedStorage {
static std::map<std::string, T> store;
};
template<typename T>
std::map<std::string, T> TypedStorage<T>::store;
template<typename T>
inline const T &Set(const std::string &key, const T &value) {
TypedStorage<T>::store[key] = value;
return value;
}
template<typename T>
inline const T &Get(const std::string &key) {
return TypedStorage<T>::store[key];
}
template<typename T>
void TW_CALL GetCallback(void *value, void *clientData) {
std::string *key = (std::string *)clientData;
*(T *)value = TypedStorage<T>::store[*key];
}
template<typename T>
void TW_CALL SetCallback(const void *value, void *clientData) {
std::string *key = (std::string *)clientData;
TypedStorage<T>::store[*key] = *(T *)value;
}
template<typename T>
const std::string &GetKey(const std::string &key) {
std::map<std::string, T>::const_iterator it =
TypedStorage<T>::store.find(key);
return it->first;
}
};