19 {
20
23
24
26
27
29 {"Int32 Key", 42},
30 {"Bool Key", true},
31 {"Subdir", {
32 {"Int32 key", 123 },
33 {"Double Key", 1.2},
34 {"Subsub", {
35 {"Float key", 1.2f},
36 {"String Key", "Hello"},
37 }}
38 }},
39 {"Int Array", {1, 2, 3}},
40 {"Double Array", {1.2, 2.3, 3.4}},
41 {"String Array", {"Hello1", "Hello2", "Hello3"}},
42 {"Large Array", std::array<int, 10>{} },
43 {"Large String", std::string(63, '\0') },
44 {"String Array 10", std::array<std::string, 10>{}},
45
46 {"Large String Array 10", std::array<std::string, 10>{std::string(63, '\0')}}
47 };
48
49
50
51
53
54
56 std::cout << o2 << std::endl;
57
58
59 o["Int32 Key"] = 42;
60 int i = o[
"Int32 Key"];
62 o["Int32 Key"]++;
63 o["Int32 Key"] *= 1.3;
64 std::cout << "Should be 57: " << o["Int32 Key"] << std::endl;
65
66
67 o["Int64 Key"] = -1LL;
68 int64_t i64 = o["Int64 Key"];
69 std::cout << std::hex << "0x" << i64 << std::dec << std::endl;
70
71 o["UInt64 Key"] = 0x1234567812345678u;
72 uint64_t ui64 = o["UInt64 Key"];
73 std::cout << std::hex << "0x" << ui64 << std::dec << std::endl;
74
75
76 o["Bool Key"] = false;
77 o["Bool Key"] = !o["Bool Key"];
78
79
80 o["Subdir"]["Subsub"]["String Key"] = "Hello";
81 std::string s = o["Subdir"]["Subsub"]["String Key"];
82 s += " world!";
83 o["Subdir"]["Subsub"]["String Key"] = s;
84 s = s + o[
"Subdir"][
"Subsub"][
"String Key"].
s();
85 std::cout << s << std::endl;
86
87
88 std::string substr("Int32 Key");
89 o[substr] = 43;
90
91
92 std::vector<int> v = o["Int Array"];
93 std::fill(v.begin(), v.end(), 10);
94 o["Int Array"] = v;
95 o["Int Array"][1] = 2;
96 i = o[
"Int Array"][1];
97 std::cout <<
i <<std::endl;
99 o["Int Array"]++;
100 std::cout <<
"Arrays size is " << o[
"Int Array"].
size() << std::endl;
101
102
103 o["Int Array"][10] = 10;
104
105
106 std::vector<std::string> sv;
107 sv = o["String Array"];
108 sv[1] = "New String";
109 o["String Array"] = sv;
110 o["String Array"][2] = "Another String";
111 o["String Array"][3] = std::string("One more");
112 s = o[
"String Array"][1].
s();
113 std::cout << s << std::endl;
114
115
117 o["String Array 2"][1] = "Second string";
118 o["String Array 2"][2] = "Third string";
119
120
121 o["Bool Array"] = std::array<bool, 3>{true, false, true};
122 o["Bool Array from Vector"] = std::vector<bool>{true, false, true};
123
124
125 int sum = 0;
126 for (
int e : o[
"Int Array"])
128 std::cout << "Sum should be 37: " << sum << std::endl;
129
130
132 oi = 123;
133
134
135 std::cout << oi << std::endl;
136 oi.set_auto_refresh_read(false);
137 std::cout << oi << std::endl;
138 oi.read();
139 std::cout << oi << std::endl;
140
141
142 oi.set_auto_refresh_write(false);
143 oi = 321;
144 oi.write();
145
146
148 ot.
connect(
"/Test/Settings/OTF");
149 ot["Int32 Key"] = 1;
150 ot["Double Key"] = 1.23;
151 ot["String Key"] = "Hello";
152 ot["Int Array"] = std::array<int, 10>{};
153 ot["Subdir"]["Int32 Key"] = 42;
154 ot["String Array"] = std::vector<std::string>{"S1", "S2", "S3"};
155 ot["Other String Array"][0] = "OSA0";
156 ot["Other String Array"][1] = "OSA1";
157
158
159 i = ot[
"Int32 Key"](123);
160 std::cout <<
i << std::endl;
161 i = ot[
"New Int32 Key"](123);
162 std::cout <<
i << std::endl;
163
164
165 std::cout << ot << std::endl;
166
168 std::cout << o.
print() << std::endl;
169
170
173 std::cout << oit.get_name() << ": " << oit << std::endl;
174
175
176 std::cout << o.
print() << std::endl;
177
178
179 std::cout << o.
dump() << std::endl;
180
181
182
184 {"Int32 Key", 456},
185 {"New Bool Key", true},
186 {"String Array", {"Hello1", "Hello2", "Hello3"}},
187 {"Bool Key", true},
188 {"Subdir", {
189 {"Int32 key", 135 },
190 {"New Sub Bool Key", false},
191 {"Double Key", 1.5}
192 }}
193 };
195
196
197 std::cout << "After changing structure with o3:" << std::endl;
198 std::cout << o3.
print() << std::endl;
199
200
202
203
205
206
209 std::cout <<
"Value of key \"" + o.
get_full_path() +
"\" changed to " << o << std::endl;
210 });
211
212 do {
215 break;
217
219 return 1;
220}
void set_string_size(std::string s, int size)
std::string get_full_path()
static void set_debug(bool flag)
static int delete_key(const std::string &name)
void connect_and_fix_structure(std::string path)
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
INT cm_yield(INT millisec)
INT cm_connect_experiment(const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *))
INT cm_disconnect_experiment(void)