-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.cpp
51 lines (42 loc) · 2.21 KB
/
test.cpp
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
#include "Parser.h"
#include <sstream>
// syntax sugar
#define $ .Get()
int main() {
std::stringstream ss;
ss <<
"# defining a configuration file \n"
"a-b*2=1 # an original named key! \n"
"b=1 \n\n"
"# section 'e' \n"
"[e] \n"
"ea=1 ; middle line comment \n"
"eb=1 \n\n"
"# section 'c' \n"
"[c] \n"
"ca=2 \n"
"cb=2 # another middle line comment \n\n"
"# nested section in 'e' called 'd' \n"
"[[d]] \n"
"da=3.0 \n"
"db={3, 4, 5} ; <- look an integer vector... \n\n"
"# section 'e' \n"
"[A] \n"
"Aa=true \n"
"A-b=foo-bar # a key with an unusual character inside it \n";
// construct a config file structure
Configuration::Parser config(ss);
// print config file
std::ostringstream out;
config.ExportSection(out);
std::cout << out.str();
// extract scalars and vectors from config file
int a = Configuration::GetAs<int> (config $["a-b*2"]);
float da = Configuration::GetAs<float> (config $("c")("d")["da"]);
std::vector<int> db = Configuration::GetAs<std::vector<int>>(config $("c")("d")["db"]);
bool aa = Configuration::GetAs<bool> (config $("A")["Aa"]);
std::string ab = config $("A")["A-b"];
// clear config file structure
config.Clear();
return 1;
}