@@ -29,6 +29,86 @@ or download and include sources to your project:
2929* src/wsjcpp_obj_tree.h
3030* src/wsjcpp_obj_tree.cpp
3131
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+
32112## Examples
33113
34114### Define your tree example
@@ -54,6 +134,9 @@ WsjcppObjTreeChainDeclare chain(&comp);
54134
55135```
56136
137+
138+
139+
57140### Define your node container
58141
591421 way: use a generator of code from wsjcpp
@@ -106,8 +189,8 @@ class WsjcppObjTreeNodeBuilding : public WsjcppObjTreeNode {
106189 int getNumberOfFloors();
107190
108191 // 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;
111194 virtual std::string toString(const std::string &sIntent = "") override;
112195
113196 private:
@@ -201,16 +284,16 @@ int WsjcppObjTreeNodeBuilding::getNumberOfFloors() {
201284
202285// ---------------------------------------------------------------------
203286
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 ;
207290}
208291
209292// ---------------------------------------------------------------------
210293
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 ;
214297}
215298
216299// ---------------------------------------------------------------------
0 commit comments