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
116 o["New String Array"] = sv;
117
118
120 o["String Array 2"][1] = "Second string";
121 o["String Array 2"][2] = "Third string";
122
123
124 o["Bool Array"] = std::array<bool, 3>{true, false, true};
125 o["Bool Array from Vector"] = std::vector<bool>{true, false, true};
126
127
128 int sum = 0;
129 for (
int e : o[
"Int Array"])
131 std::cout << "Sum should be 37: " << sum << std::endl;
132
133
135 oi = 123;
136
137
138 std::cout << oi << std::endl;
139 oi.set_auto_refresh_read(false);
140 std::cout << oi << std::endl;
141 oi.read();
142 std::cout << oi << std::endl;
143
144
145 oi.set_auto_refresh_write(false);
146 oi = 321;
147 oi.write();
148
149
151 ot.
connect(
"/Test/Settings/OTF");
152 ot["Int32 Key"] = 1;
153 ot["Double Key"] = 1.23;
154 ot["String Key"] = "Hello";
155 ot["Int Array"] = std::array<int, 10>{};
156 ot["Subdir"]["Int32 Key"] = 42;
157 ot["String Array"] = std::vector<std::string>{"S1", "S2", "S3"};
158 ot["Other String Array"][0] = "OSA0";
159 ot["Other String Array"][1] = "OSA1";
160
161
162 i = ot[
"Int32 Key"](123);
163 std::cout <<
i << std::endl;
164 i = ot[
"New Int32 Key"](123);
165 std::cout <<
i << std::endl;
166
167
168 std::cout << ot << std::endl;
169
171 std::cout << o.
print() << std::endl;
172
173
176 std::cout << oit.get_name() << ": " << oit << std::endl;
177
178
179 std::cout << o.
print() << std::endl;
180
181
182 std::cout << o.
dump() << std::endl;
183
184
185
187 {"Int32 Key", 456},
188 {"New Bool Key", true},
189 {"String Array", {"Hello1", "Hello2", "Hello3"}},
190 {"Bool Key", true},
191 {"Subdir", {
192 {"Int32 key", 135 },
193 {"New Sub Bool Key", false},
194 {"Double Key", 1.5}
195 }}
196 };
198
199
200 std::cout << "After changing structure with o3:" << std::endl;
201 std::cout << o3.
print() << std::endl;
202
203
205
206
208
209
212 std::cout <<
"Value of key \"" + o.
get_full_path() +
"\" changed to " << o << std::endl;
213 });
214
215 do {
218 break;
220
222 return 1;
223}
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)