Skip to content

Commit 0723ffd

Browse files
committed
Fixed #4 added to support user version of tree
1 parent 961eb96 commit 0723ffd

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ addons:
1818
script:
1919
- ./build_simple.sh
2020
- ./wsjcpp-obj-tree --example -o some.wsjcpp-obj-tree
21+
- ./wsjcpp-obj-tree --random 1000 -o random.wsjcpp-obj-tree
2122
- ./wsjcpp-obj-tree -i some.wsjcpp-obj-tree -o some2.wsjcpp-obj-tree
2223
- rm some.wsjcpp-obj-tree && rm some2.wsjcpp-obj-tree
2324
- cd unit-tests.wsjcpp

src/wsjcpp_obj_tree.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,24 @@ void WsjcppObjTreeNode::setId(uint32_t nId) {
7272

7373
WsjcppObjTree::WsjcppObjTree() {
7474
m_nLastId = 0;
75+
m_nUserVersion = 0;
7576
TAG = "WsjcppObjTree";
7677
}
7778

7879
// ---------------------------------------------------------------------
7980

81+
void WsjcppObjTree::setUserVersionOfTree(uint32_t nUserVersion) {
82+
m_nUserVersion = nUserVersion;
83+
}
84+
85+
// ---------------------------------------------------------------------
86+
87+
uint32_t WsjcppObjTree::getUserVersionOfTree() {
88+
return m_nUserVersion;
89+
}
90+
91+
// ---------------------------------------------------------------------
92+
8093
WsjcppObjTree::~WsjcppObjTree() {
8194
clearNodes();
8295
std::map<uint16_t, IFabricWsjcppObjTreeNode*>::iterator it;
@@ -111,6 +124,11 @@ bool WsjcppObjTree::readTreeFromFile(const std::string &sFilename, std::string &
111124
return false;
112125
}
113126

127+
// just a user version for usebillity
128+
if (!this->readUInt32(f, m_nUserVersion, sError)) {
129+
return false;
130+
}
131+
114132
uint32_t nTreeSize = 0;
115133
if (!this->readUInt32(f, nTreeSize, sError)) {
116134
return false;
@@ -182,7 +200,9 @@ bool WsjcppObjTree::writeTreeToFile(const std::string &sFilename, std::string &s
182200
static const std::string sFileHeader = "WSJCPP-OBJ-TREE-FILE";
183201
f.write(sFileHeader.c_str(), sFileHeader.length());
184202

185-
// m_nLastId
203+
// just a user version for usebillity
204+
this->writeUInt32(f, m_nUserVersion);
205+
186206
int nTreeSize = m_vNodes.size();
187207
this->writeUInt32(f, nTreeSize);
188208
this->writeUInt32(f, m_nLastId);
@@ -292,7 +312,7 @@ int WsjcppObjTree::getRoots(std::vector<WsjcppObjTreeNode *> &vRoots) {
292312

293313
std::string WsjcppObjTree::toString() { // for printing
294314
std::string sIntent = "";
295-
return toStringRecoursiveChilds(nullptr, sIntent);
315+
return "Root (ver: " + std::to_string(m_nUserVersion) + ")\n" + toStringRecoursiveChilds(nullptr, sIntent);
296316
}
297317

298318
// ---------------------------------------------------------------------

src/wsjcpp_obj_tree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class WsjcppObjTree {
7474
public:
7575
WsjcppObjTree();
7676
~WsjcppObjTree();
77+
void setUserVersionOfTree(uint32_t nUserVersion);
78+
uint32_t getUserVersionOfTree();
7779

7880
bool readTreeFromFile(const std::string &sFilename, std::string &sError);
7981
bool writeTreeToFile(const std::string &sFilename, std::string &sError);
@@ -117,6 +119,7 @@ class WsjcppObjTree {
117119

118120
private:
119121
std::string TAG;
122+
uint32_t m_nUserVersion;
120123
std::vector<WsjcppObjTreeNode *> m_vNodes;
121124
uint32_t m_nLastId; // Need for future if will be implemented function of remove nodes
122125
std::map<uint16_t, IFabricWsjcppObjTreeNode*> m_mapFabricTreeNode;
4 Bytes
Binary file not shown.

unit-tests.wsjcpp/src/unit_test_write_tree.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void UnitTestWriteTree::init() {
1818
class CompStruct : public WsjcppObjTree {
1919
public:
2020
CompStruct() {
21+
setUserVersionOfTree(1);
2122
addSupportType<WsjcppObjTreeNodeString>();
2223
addSupportType<WsjcppObjTreeNodeInteger>();
2324
addSupportType<WsjcppObjTreeNodeFloat>();
@@ -73,7 +74,7 @@ bool UnitTestWriteTree::run() {
7374
int nBufferSize = 0;
7475
WsjcppCore::readFileToBuffer(sFilename, &pBuffer, nBufferSize);
7576

76-
compareN(bTestSuccess, "write to file", nBufferSize, 316);
77+
compareN(bTestSuccess, "write to file", nBufferSize, 320);
7778

7879
return bTestSuccess;
7980
}

0 commit comments

Comments
 (0)