blob: 84d160a5afa32982a758ceed8eef2443ace071fe (
plain)
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
|
RYML has decided to stop working and I don't want to spend any more time trying
to figure out why.
Let's make a parser that implements the small subset of YAML that
Config.{h,cpp} rely on.
Config needs to serialize the following types:
* std::string
* bool
* int
Bool will be serialized like ints, with additional requirements on
deserialization.
Serialization looks like this:
```
ConfigMarshall cm(out_);
cm.Append("microphone", microphone_); // string
cm.Append("rows", rows_); // int
cm.Append("use_cpu", use_cpu_); // bool
cm.Write("config.yml");
```
Deserialization looks like this:
```
ConfigMarshall cm(out_);
cm.Load("config.yml");
cm.Get("microphone", microphone_); // string
cm.Get("rows", rows_); // int
cm.Get("use_cpu", use_cpu_); // bool
```
Interface:
```
class ConfigMarshal {
public:
ConfigMarshall(wxTextCtrl *out);
bool Save(const std::filesystem::path& path);
bool Load(const std::filesystem::path& path);
template <typename T>
bool Append(const std::string& key, const T& value);
template <typename T>
bool Get(const std::string& key, T& value);
private:
std::map<std::string, std::string> kv_str_;
std::map<std::string, int> kv_int_;
std::map<std::string, bool> kv_bool_;
}
```
|