]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoardTest/main.cpp
Document server should use variable value request with binding
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoardTest / main.cpp
1 #ifdef _WIN32\r
2 #include <Windows.h>\r
3 #include "StackWalker.h"\r
4 #endif\r
5 \r
6 #include "TypeParser.h"\r
7 #include "ValueParser.h"\r
8 \r
9 #include "DataBoardRepository.h"\r
10 #include "DataValueRepository.h"\r
11 \r
12 #include "RecordType.h"\r
13 #include "Component.h"\r
14 \r
15 #include "RecordValue.h"\r
16 #include "StringValue.h"\r
17 #include "IntegerValue.h"\r
18 #include "DoubleValue.h"\r
19 #include "ArrayValue.h"\r
20 \r
21 #include "MapValue.h"\r
22 #include "IntegerType.h"\r
23 #include "StringType.h"\r
24 #include "DataType.h"\r
25 \r
26 \r
27 #include "NumberType.h"\r
28 \r
29 #include <iostream>\r
30 \r
31 \r
32 \r
33 void testParser()\r
34 {\r
35         std::cout << "Output of dbt & dbv files:" << std::endl;\r
36 \r
37         Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input11.dbt");\r
38 \r
39         if(typeRepo == NULL)\r
40         {\r
41                 std::cerr << "type repository not found" << std::endl;\r
42 \r
43                 return;\r
44         }\r
45 \r
46         Databoard::Type::DataType* type = typeRepo->getDataBoard("PBEparticle");\r
47 \r
48         if(type == NULL)\r
49         {\r
50                 std::cerr << "type not found" << std::endl;\r
51 \r
52                 return;\r
53         }\r
54 \r
55         Databoard::Value::Value* value = Databoard::Value::parse("input12.dbv", type);\r
56 \r
57         if(value == NULL)\r
58         {\r
59                 std::cerr << "value not found" << std::endl;\r
60 \r
61                 return;\r
62         }\r
63 \r
64         //Databoard::Type::RecordType* r = ((Databoard::Type::RecordType*)type);\r
65 \r
66         //std::cout << r->getComponentIndex("FractalIndex") << std::endl;\r
67         //std::cout << r->getComponentIndex("Bondforce") << std::endl;\r
68         //std::cout << r->getComponentIndex("Density") << std::endl;\r
69         //std::cout << r->getComponentIndex("RefractiveIndex") << std::endl;\r
70         //std::cout << r->getComponentIndex("UVabsorption") << std::endl;\r
71         //std::cout << r->getComponentIndex("SurfacePotential") << std::endl;\r
72         //std::cout << r->getComponentIndex("SurfaceCharge") << std::endl;\r
73         //std::cout << r->getComponentIndex("RPermittivity") << std::endl;\r
74         //std::cout << r->getComponentIndex("AvgRadius") << std::endl;\r
75 \r
76         //Databoard::Value::RecordValue* t = ((Databoard::Value::RecordValue*)value);\r
77 \r
78         //Databoard::Value::DoubleValue* f0 = (Databoard::Value::DoubleValue*)t->getField(0);\r
79         //Databoard::Value::DoubleValue* f1 = (Databoard::Value::DoubleValue*)t->getField(1);\r
80         //Databoard::Value::DoubleValue* f2 = (Databoard::Value::DoubleValue*)t->getField(2);\r
81         //Databoard::Value::DoubleValue* f3 = (Databoard::Value::DoubleValue*)t->getField(3);\r
82         //Databoard::Value::RecordValue* f4 = (Databoard::Value::RecordValue*)t->getField(4);\r
83         //Databoard::Value::DoubleValue* f5 = (Databoard::Value::DoubleValue*)t->getField(5);\r
84         //Databoard::Value::DoubleValue* f6 = (Databoard::Value::DoubleValue*)t->getField(6);\r
85         //Databoard::Value::DoubleValue* f7 = (Databoard::Value::DoubleValue*)t->getField(7);\r
86         //Databoard::Value::DoubleValue* f8 = (Databoard::Value::DoubleValue*)t->getField(8);\r
87 \r
88         //std::cout << f0->getValue() << std::endl;\r
89         //std::cout << f1->getValue() << std::endl;\r
90         //std::cout << f2->getValue() << std::endl;\r
91         //std::cout << f3->getValue() << std::endl;\r
92 \r
93         //std::cout << ((Databoard::Value::DoubleValue*)f4->getField(0))->getValue() << std::endl;\r
94         //std::cout << ((Databoard::Value::DoubleValue*)f4->getField(1))->getValue() << std::endl;\r
95 \r
96         //std::cout << f5->getValue() << std::endl;\r
97         //std::cout << f6->getValue() << std::endl;\r
98         //std::cout << f7->getValue() << std::endl;\r
99         //std::cout << f8->getValue() << std::endl;\r
100 \r
101         std::cout << type->writeOut() << std::endl;\r
102         std::cout << value->writeOut() << std::endl;\r
103 \r
104         delete value;\r
105         delete typeRepo;\r
106 \r
107         std::cout << "..." << std::endl;\r
108 }\r
109 \r
110 void testParser2()\r
111 {\r
112         std::cout << "Output of dbt & dbd(s) files:" << std::endl;\r
113 \r
114         Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input23.dbt");\r
115 \r
116         if(typeRepo == NULL)\r
117         {\r
118                 std::cerr << "type repository not found" << std::endl;\r
119 \r
120                 return;\r
121         }\r
122 \r
123         Databoard::Value::DataValueRepository* valueRepo = NULL;\r
124         Databoard::Value::parse("input24_1.dbd", valueRepo, typeRepo);\r
125         Databoard::Value::parse("input24_2.dbd", valueRepo, typeRepo);\r
126 \r
127         const Databoard::Value::strDataValueDefinition* v1 = valueRepo->getDataValue("a");\r
128         const Databoard::Value::strDataValueDefinition* v2 = valueRepo->getDataValue("b");\r
129 \r
130         std::cout << "... printing types:" << std::endl;\r
131 \r
132         for(int i = 0; i < typeRepo->count(); ++i)\r
133         {\r
134                 std::cout << "#" << i << ":" << std::endl;\r
135 \r
136                 std::cout << typeRepo->getDataBoard(i).writeOut() << std::endl << std::endl;\r
137         }\r
138 \r
139         if(v1 != NULL)\r
140         {\r
141                 std::cout << "... printing value definition:" << std::endl;\r
142 \r
143                 std::cout << v1->writeOut() << std::endl;\r
144 \r
145                 std::string v = v1->value->isValid();\r
146 \r
147                 if(v.length() > 0)\r
148                 {\r
149                         std::cout << "type is invalid: " << v << std::endl;\r
150                 }\r
151                 else\r
152                 {\r
153                         std::cout << "type is valid" << std::endl;\r
154                 }\r
155         }\r
156 \r
157         if(v2 != NULL)\r
158         {\r
159                 std::cout << "... printing value definition:" << std::endl;\r
160 \r
161                 std::cout << v2->writeOut() << std::endl;\r
162 \r
163                 std::string v = v2->value->isValid();\r
164 \r
165                 if(v.length() > 0)\r
166                 {\r
167                         std::cout << "type is invalid: " << v << std::endl;\r
168                 }\r
169                 else\r
170                 {\r
171                         std::cout << "type is valid" << std::endl;\r
172                 }\r
173         }\r
174 \r
175 \r
176         Databoard::Value::free(valueRepo);\r
177         Databoard::Type::free(typeRepo);\r
178 \r
179         std::cout << "..." << std::endl;\r
180 \r
181 }\r
182 \r
183 void testParser3()\r
184 {\r
185         std::cout << "Output of dbt file:" << std::endl;\r
186 \r
187         Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input17.dbt");\r
188 \r
189         Databoard::Type::DataType* type = typeRepo->getDataBoard("Complex");\r
190 \r
191         if(type == NULL)\r
192         {\r
193                 std::cerr << "type not found" << std::endl;\r
194 \r
195                 return;\r
196         }\r
197 \r
198         std::cout << type->writeOut() << std::endl;\r
199 \r
200         Databoard::Value::MapValue* mapValue = new Databoard::Value::MapValue(type);\r
201 \r
202         Databoard::Type::IntegerType* integerType = new Databoard::Type::IntegerType();\r
203         Databoard::Type::StringType* stringType = new Databoard::Type::StringType();\r
204 \r
205         Databoard::Value::IntegerValue* k0 = new Databoard::Value::IntegerValue(integerType);\r
206         Databoard::Value::IntegerValue* k1 = new Databoard::Value::IntegerValue(integerType);\r
207         Databoard::Value::IntegerValue* k2 = new Databoard::Value::IntegerValue(integerType);\r
208         Databoard::Value::IntegerValue* k3 = new Databoard::Value::IntegerValue(integerType);\r
209 \r
210         Databoard::Value::StringValue* v0 = new Databoard::Value::StringValue(stringType);\r
211         Databoard::Value::StringValue* v1 = new Databoard::Value::StringValue(stringType);\r
212         Databoard::Value::StringValue* v2 = new Databoard::Value::StringValue(stringType);\r
213         Databoard::Value::StringValue* v3 = new Databoard::Value::StringValue(stringType);\r
214 \r
215         k0->setValue(2);\r
216         k1->setValue(4);\r
217         k2->setValue(8);\r
218         k3->setValue(5);\r
219 \r
220         v0->setValue("asd0");\r
221         v1->setValue("asd1");\r
222         v2->setValue("asd2");\r
223         v3->setValue("asd3");\r
224 \r
225         std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl;\r
226         mapValue->put(k0, v0);\r
227 \r
228         std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl;\r
229         mapValue->put(k1, v1);\r
230 \r
231         std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl;\r
232         mapValue->put(k2, v2);\r
233 \r
234         std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl;\r
235         mapValue->put(k3, v3);\r
236 \r
237         mapValue->removeRange(k0, k1);\r
238 \r
239         //Databoard::Value::Value* old = mapValue->remove(k0);\r
240 \r
241         //delete k0;\r
242         //delete old;\r
243 \r
244         delete mapValue;\r
245         delete integerType;\r
246         delete stringType;\r
247 \r
248         Databoard::Type::free(typeRepo);\r
249 }\r
250 \r
251 void testParser4()\r
252 {\r
253         std::cout << "Output of dbt & dbv files:" << std::endl;\r
254 \r
255         Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input25.dbt");\r
256 \r
257         if(typeRepo == NULL)\r
258         {\r
259                 std::cerr << "type repository not found" << std::endl;\r
260 \r
261                 return;\r
262         }\r
263 \r
264         Databoard::Type::DataType* type = typeRepo->getDataBoard("AggreDist");\r
265 \r
266         if(type == NULL)\r
267         {\r
268                 std::cerr << "type not found" << std::endl;\r
269 \r
270                 return;\r
271         }\r
272 \r
273         Databoard::Value::DataValueRepository* valueRepo = NULL;\r
274         Databoard::Value::parse("input26_3.dbd", valueRepo, typeRepo);\r
275 \r
276         Databoard::Value::Value* value1 = Databoard::Value::parse("input26_1.dbv", type);\r
277 \r
278         if(value1 == NULL)\r
279         {\r
280                 std::cerr << "value not found" << std::endl;\r
281 \r
282                 return;\r
283         }\r
284 \r
285         Databoard::Value::Value* value2 = Databoard::Value::parse("input26_2.dbv", type);\r
286 \r
287         if(value2 == NULL)\r
288         {\r
289                 std::cerr << "value not found" << std::endl;\r
290 \r
291                 return;\r
292         }\r
293 \r
294         if(value1 != NULL)\r
295         {\r
296                 std::cout << "... printing value definition:" << std::endl;\r
297 \r
298                 std::cout << value1->writeOut() << std::endl;\r
299 \r
300                 std::string v = value1->isValid();\r
301 \r
302                 if(v.length() > 0)\r
303                 {\r
304                         std::cout << "type is invalid: " << v << std::endl;\r
305                 }\r
306                 else\r
307                 {\r
308                         std::cout << "type is valid" << std::endl;\r
309                 }\r
310 \r
311                 delete value1;\r
312         }\r
313 \r
314         if(value2 != NULL)\r
315         {\r
316                 std::cout << "... printing value definition:" << std::endl;\r
317 \r
318                 std::cout << value2->writeOut() << std::endl;\r
319 \r
320                 std::string v = value2->isValid();\r
321 \r
322                 if(v.length() > 0)\r
323                 {\r
324                         std::cout << "type is invalid: " << v << std::endl;\r
325                 }\r
326                 else\r
327                 {\r
328                         std::cout << "type is valid" << std::endl;\r
329                 }\r
330 \r
331                 delete value2;\r
332         }\r
333 \r
334         delete valueRepo;\r
335         delete typeRepo;\r
336 \r
337         std::cout << "..." << std::endl;\r
338 }\r
339 \r
340 void testParser5()\r
341 {\r
342         std::cout << "Output of dbt & dbv files:" << std::endl;\r
343 \r
344         Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input27.dbt");\r
345 \r
346         if(typeRepo == NULL)\r
347         {\r
348                 std::cerr << "type repository not found" << std::endl;\r
349 \r
350                 return;\r
351         }\r
352 \r
353         Databoard::Type::DataType* type = typeRepo->getDataBoard("Complex");\r
354 \r
355         if(type == NULL)\r
356         {\r
357                 std::cerr << "type not found" << std::endl;\r
358 \r
359                 return;\r
360         }\r
361 \r
362         Databoard::Value::Value* value = Databoard::Value::parse("input28.dbv", type);\r
363 \r
364         if(value == NULL)\r
365         {\r
366                 std::cerr << "value not found" << std::endl;\r
367 \r
368                 return;\r
369         }\r
370 \r
371         std::cout << type->writeOut() << std::endl;\r
372         std::cout << value->writeOut() << std::endl;\r
373 \r
374         delete value;\r
375         delete typeRepo;\r
376 \r
377         std::cout << "..." << std::endl;\r
378 }\r
379 \r
380 void testParser6()\r
381 {\r
382         std::cout << "Output of dbt & dbv files:" << std::endl;\r
383 \r
384         Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input29.dbt");\r
385 \r
386         if(typeRepo == NULL)\r
387         {\r
388                 std::cerr << "type repository not found" << std::endl;\r
389 \r
390                 return;\r
391         }\r
392 \r
393         Databoard::Type::DataType* type = typeRepo->getDataBoard("T");\r
394 \r
395         if(type == NULL)\r
396         {\r
397                 std::cerr << "type not found" << std::endl;\r
398 \r
399                 return;\r
400         }\r
401 \r
402         Databoard::Value::Value* value1 = Databoard::Value::parse("input30.dbv", type);\r
403 \r
404         if(value1 == NULL)\r
405         {\r
406                 std::cerr << "value not found" << std::endl;\r
407 \r
408                 return;\r
409         }\r
410 \r
411         Databoard::Value::RecordValue* recordValue = dynamic_cast<Databoard::Value::RecordValue*>(value1);\r
412 \r
413         if(recordValue != NULL)\r
414         {\r
415                 for(int i = 0; i < recordValue->count(); ++i)\r
416                 {\r
417                         Databoard::Value::Value* value = recordValue->getField(i);\r
418 \r
419                         Databoard::Value::ArrayValue* arrayValue = dynamic_cast<Databoard::Value::ArrayValue*>(value);\r
420 \r
421                         if(arrayValue != NULL)\r
422                         {\r
423                                 //// one by one:\r
424                                 //for(int j = 0; j < arrayValue->count(); ++j)\r
425                                 //{\r
426                                 //      Databoard::Value::Value* value = arrayValue->get(j);\r
427 \r
428                                 //      std::cout << value->writeOut() << std::endl;\r
429                                 //}\r
430 \r
431                                 // or to vector:\r
432                                 std::vector<Databoard::Value::Value*> valueVector = arrayValue->getAll();\r
433 \r
434                                 std::cout << "Row count: " << (int)valueVector.size() << std::endl;\r
435 \r
436                                 for(int j = 0; j < (int)valueVector.size(); ++j)\r
437                                 {\r
438                                         Databoard::Value::RecordValue* recordValue = (Databoard::Value::RecordValue*)valueVector.at(j);\r
439 \r
440                                         std::cout << "Element count: " << recordValue->count() << std::endl;\r
441 \r
442                                         for(int k = 0; k < recordValue->count(); ++k)\r
443                                         {\r
444                                                 Databoard::Value::DoubleValue* doubleValue = (Databoard::Value::DoubleValue*)recordValue->getField(k);\r
445 \r
446                                                 std::cout << doubleValue->getValue() << std::endl;\r
447                                                 \r
448                                         }\r
449                                 }\r
450                         }\r
451                 }\r
452 \r
453                 delete value1;\r
454         }\r
455 \r
456         delete typeRepo;\r
457 \r
458         std::cout << "..." << std::endl;\r
459 }\r
460 \r
461 \r
462 int main()\r
463 {\r
464 #ifdef _WIN32\r
465         InitAllocCheck();\r
466 #endif\r
467 \r
468         //testParser();\r
469         //testParser2();\r
470         //testParser3();\r
471         //testParser4();\r
472         //testParser5();\r
473         testParser6();\r
474 \r
475 #ifdef _WIN32\r
476         DeInitAllocCheck();\r
477 #endif\r
478 }\r