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