Repository navigation
Expand file tree
/
Copy pathargman.cpp
More file actions
63 lines (52 loc) · 1.43 KB
/
Copy pathargman.cpp
File metadata and controls
63 lines (52 loc) · 1.43 KB
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
54
55
56
57
58
59
60
61
62
#include <glog/logging.h>
#include "argman.hpp"
ArgMan g_MainArgs;
void ArgMan::Register(std::string strName, ArgMan::BASE_PARSER parser) {
auto ®Map = GetRegMap();
CHECK_EQ(regMap.count(strName), 0);
regMap[std::move(strName)] = std::move(parser);
}
std::map<std::string, ArgMan::BASE_PARSER>& ArgMan::GetRegMap() {
return m_RegMap;
}
void ParseArgsFromJson(const nlohmann::json &jCfg, ArgMan &argman) {
auto ®Map = argman.GetRegMap();
for (auto &jArg : jCfg.items()) {
std::string strKey = jArg.key();
auto iParser = regMap.find(jArg.key());
if (iParser != regMap.end()) {
iParser->second(jArg.value());
}
}
}
template<>
void Parser(const nlohmann::json &jValue, uint64_t &val) {
CHECK(jValue.is_number_unsigned());
val = jValue.get<uint64_t>();
}
template<>
void Parser(const nlohmann::json &jValue, int32_t &val) {
CHECK(jValue.is_number_integer());
val = jValue.get<int32_t>();
}
template<>
void Parser(const nlohmann::json &jValue, float &val) {
CHECK(jValue.is_number());
val = jValue.get<float>();
}
template<>
void Parser(const nlohmann::json &jValue, bool &val) {
CHECK(jValue.is_boolean());
val = jValue.get<bool>();
}
template<>
void Parser(const nlohmann::json &jValue, std::string &val) {
CHECK(jValue.is_string());
val = jValue.get<std::string>();
}
std::string PathAddSlash(const std::string &strPath) {
if (!strPath.empty() && strPath.back() != '/') {
return strPath + "/";
}
return strPath;
}