@@ -29,6 +29,86 @@ or download and include sources to your project:
29
29
* src/wsjcpp_obj_tree.h
30
30
* src/wsjcpp_obj_tree.cpp
31
31
32
+ ### Build test app
33
+
34
+ Please install first: g++ cmake pkg-config
35
+
36
+ Build:
37
+ ``` bash
38
+ $ ./build_simple.sh
39
+ ```
40
+
41
+ Run help:
42
+ ``` bash
43
+ $ ./wsjcpp-obj-tree --help
44
+
45
+ Usage: ./wsjcpp-obj-tree [OPTIONS]
46
+ Options:
47
+ --help | -h help
48
+ Input or source data can be (only one):
49
+ --input < file> | -i < file> input binary file with tree
50
+ --random N | -r N generate random data (more than 0 and less than 1000000)
51
+ --example | -e hardcoded example
52
+ Output data can be (only one):
53
+ --output < file> | -o < file> output binary file for tree
54
+ --print | -p output binary file for tree
55
+
56
+ Command examples:
57
+ Print example of the tree:
58
+ ' ./wsjcpp-obj-tree -e -p'
59
+ Print random tree:
60
+ ' ./wsjcpp-obj-tree -r 20 -p'
61
+ Output example of the tree to file:
62
+ ' ./wsjcpp-obj-tree -e -o some.wsjcpp-obj-tree'
63
+ Input from file and output to file:
64
+ ' ./wsjcpp-obj-tree -i some.wsjcpp-obj-tree -o some2.wsjcpp-obj-tree'
65
+ ```
66
+
67
+ Print example tree
68
+ ``` bash
69
+ % ./wsjcpp-obj-tree -e -p
70
+ Root (ver: 1)
71
+ ├─ Building: st. Morpheus, 1/35a
72
+ │ number-of-floors: 5
73
+ └─ string: Motherboard
74
+ ├─ string: CPU_SOCKET
75
+ │ ├─ string: count
76
+ │ │ └─ int: 1
77
+ │ └─ string: frequency
78
+ │ └─ double: 3.200000
79
+ ├─ string: GPU_SOCKET
80
+ │ └─ int: 1
81
+ ├─ string: USB-A
82
+ │ └─ int: 4
83
+ ├─ string: PCI
84
+ │ └─ int: 3
85
+ └─ string: PCI_EXPRESS
86
+ └─ int: 1
87
+ Printed. Time elapsed 0ms
88
+ ```
89
+
90
+ ### Build and run unit-tests
91
+
92
+ ``` bash
93
+ $ cd unit-tests.wsjcpp
94
+ $ ./build_simple.sh
95
+ $ ./unit-tests
96
+ 2020-09-14 21:39:37.040, 0x0x110c9adc0 [INFO] UnitTests: All tests count 4
97
+ 2020-09-14 21:39:37.041, 0x0x110c9adc0 [INFO] UnitTests: Run test UnitTestAddNode
98
+ 2020-09-14 21:39:37.043, 0x0x110c9adc0 [OK] UnitTestAddNode: Test passed
99
+ 2020-09-14 21:39:37.043, 0x0x110c9adc0 [INFO] UnitTests: Run test UnitTestWriteTree
100
+ 2020-09-14 21:39:37.043, 0x0x110c9adc0 [INFO] UnitTestWriteTree:
101
+ ...
102
+ 2020-09-14 21:39:37.044, 0x0x110c9adc0 [OK] UnitTestWriteTree: Test passed
103
+ 2020-09-14 21:39:37.044, 0x0x110c9adc0 [INFO] UnitTests: Run test UnitTestFindNodes
104
+ 2020-09-14 21:39:37.044, 0x0x110c9adc0 [OK] UnitTestFindNodes: Test passed
105
+ 2020-09-14 21:39:37.045, 0x0x110c9adc0 [INFO] UnitTests: Run test UnitTestReadTree
106
+ 2020-09-14 21:39:37.045, 0x0x110c9adc0 [INFO] UnitTestReadTree:
107
+ ...
108
+ 2020-09-14 21:39:37.045, 0x0x110c9adc0 [OK] UnitTestReadTree: Test passed
109
+ 2020-09-14 21:39:37.045, 0x0x110c9adc0 [INFO] UnitTests: Passed tests 4 / 4
110
+ ```
111
+
32
112
## Examples
33
113
34
114
### Define your tree example
@@ -54,6 +134,9 @@ WsjcppObjTreeChainDeclare chain(&comp);
54
134
55
135
```
56
136
137
+
138
+
139
+
57
140
### Define your node container
58
141
59
142
1 way: use a generator of code from wsjcpp
@@ -106,8 +189,8 @@ class WsjcppObjTreeNodeBuilding : public WsjcppObjTreeNode {
106
189
int getNumberOfFloors();
107
190
108
191
// WsjcppObjTreeNode
109
- virtual int getDataSize( ) override;
110
- virtual const char *getData( ) override;
192
+ virtual bool writeDataPartToFile(std::ofstream &f, std::string &sError ) override;
193
+ virtual bool readDataPartFromFile(std::ifstream &f, std::string &sError ) override;
111
194
virtual std::string toString(const std::string &sIntent = "") override;
112
195
113
196
private:
@@ -201,16 +284,16 @@ int WsjcppObjTreeNodeBuilding::getNumberOfFloors() {
201
284
202
285
// ---------------------------------------------------------------------
203
286
204
- int WsjcppObjTreeNodeBuilding::getDataSize( ) {
205
- WsjcppLog::throw_err( "WsjcppObjTreeNodeBuilding", "::getDataSize() Not implemented") ;
206
- return sizeof(Address) ;
287
+ bool WsjcppObjTreeNodeBuilding::writeDataPartToFile(std::ofstream &f, std::string &sError ) {
288
+ sError = "WsjcppObjTreeNodeBuilding Not implemented";
289
+ return false ;
207
290
}
208
291
209
292
// ---------------------------------------------------------------------
210
293
211
- const char * WsjcppObjTreeNodeBuilding::getData( ) {
212
- WsjcppLog::throw_err( "WsjcppObjTreeNodeBuilding", "::getData() Not implemented") ;
213
- return reinterpret_cast<const char * >(&m_value) ;
294
+ bool WsjcppObjTreeNodeBuilding::readDataPartFromFile(std::ifstream &f, std::string &sError ) {
295
+ sError = "WsjcppObjTreeNodeBuilding Not implemented";
296
+ return false ;
214
297
}
215
298
216
299
// ---------------------------------------------------------------------
0 commit comments