-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtypes.h
40 lines (31 loc) · 1 KB
/
types.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
#pragma once
#include <json.hpp>
#include <fifo_map.hpp>
template<class K, class V, class dummy_compare, class A>
using unordered_fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<K>, A>;
using json = nlohmann::basic_json<unordered_fifo_map>;
template <typename value_t>
value_t json_get(const json& jobject, const std::string& name, const value_t def)
{
return jobject.contains(name) ? jobject[name].get<value_t>() : def;
}
template <typename value_t>
value_t json_get_option(json& jobject, const std::string& name, const value_t def)
{
if (not jobject.contains("options"))
{
jobject["options"] = json::object();
}
auto& joptions = jobject["options"];
return joptions.contains(name) ? joptions[name].get<value_t>() : def;
}
template <typename value_t>
void json_set_option(json& jobject, const std::string& name, const value_t def)
{
if (not jobject.contains("options"))
{
jobject["options"] = json::object();
}
auto& joptions = jobject["options"];
joptions[name] = def;
}