Skip to content

Commit 5f1252c

Browse files
committed
Updated wsjcpp-core
1 parent dadacec commit 5f1252c

File tree

6 files changed

+62
-52
lines changed

6 files changed

+62
-52
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# wsjcpp-print-tree
22

3-
[![Build Status](https://api.travis-ci.org/wsjcpp/wsjcpp-print-tree.svg?branch=master)](https://travis-ci.org/wsjcpp/wsjcpp-print-tree) [![Github Stars](https://img.shields.io/github/stars/wsjcpp/wsjcpp-print-tree.svg?label=github%20%E2%98%85)](https://github.com/wsjcpp/wsjcpp-print-tree) [![Github Stars](https://img.shields.io/github/contributors/wsjcpp/wsjcpp-print-tree.svg)](https://github.com/wsjcpp/wsjcpp-print-tree) [![Github Forks](https://img.shields.io/github/forks/wsjcpp/wsjcpp-print-tree.svg?label=github%20forks)](https://github.com/wsjcpp/wsjcpp-print-tree/network/members)
3+
[![Build Status](https://api.travis-ci.com/wsjcpp/wsjcpp-print-tree.svg?branch=master)](https://travis-ci.com/wsjcpp/wsjcpp-print-tree) [![Github Stars](https://img.shields.io/github/stars/wsjcpp/wsjcpp-print-tree.svg?label=github%20%E2%98%85)](https://github.com/wsjcpp/wsjcpp-print-tree) [![Github Stars](https://img.shields.io/github/contributors/wsjcpp/wsjcpp-print-tree.svg)](https://github.com/wsjcpp/wsjcpp-print-tree) [![Github Forks](https://img.shields.io/github/forks/wsjcpp/wsjcpp-print-tree.svg?label=github%20forks)](https://github.com/wsjcpp/wsjcpp-print-tree/network/members)
44

55
Helper class for print tree like a for filesystems
66

@@ -22,7 +22,7 @@ Second way integrate files:
2222
## Example of usage
2323

2424
```
25-
WSJCppPrintTree tree("Example Of Tree");
25+
WsjcppPrintTree tree("Example Of Tree");
2626
tree
2727
.addChild("Hello1")
2828
.switchToLatestChild()

src/main.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@
77

88
int main(int argc, const char* argv[]) {
99
std::string TAG = "MAIN";
10-
WSJCppCore::init(argc, argv, true);
10+
std::string appName = std::string(WSJCPP_NAME);
11+
std::string appVersion = std::string(WSJCPP_VERSION);
12+
13+
std::string appLogPath = ".logs";
14+
if (!WsjcppCore::dirExists(appLogPath)) {
15+
WsjcppCore::makeDir(appLogPath);
16+
}
17+
WsjcppLog::setPrefixLogFile("wsjcpp-print-tree");
18+
WsjcppLog::setLogDirectory(appLogPath);
19+
20+
// WsjcppCore::init(argc, argv, sAppName, sAppVersion, "Evgenii Sopov", "WsjcppPrintTree");
1121

1222
// may be better read from file struct for example json or any some
13-
WSJCppPrintTree tree("Example Of Tree");
23+
WsjcppPrintTree tree("Example Of Tree");
1424
tree
1525
.addChild("Hello1")
1626
.switchToLatestChild()

src/wsjcpp_print_tree.cpp

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#include "wsjcpp_print_tree.h"
22
#include <wsjcpp_core.h>
33

4-
WSJCppPrintNode::WSJCppPrintNode(WSJCppPrintNode *pParent, const std::string &sTitle) {
5-
TAG = "WSJCppPrintNode";
4+
WsjcppPrintNode::WsjcppPrintNode(WsjcppPrintNode *pParent, const std::string &sTitle) {
5+
TAG = "WsjcppPrintNode";
66
m_pParent = pParent;
77
m_sTitle = sTitle;
88
}
99

1010
// ----------------------------------------------------------------------
1111

12-
std::string WSJCppPrintNode::getTitle() {
12+
std::string WsjcppPrintNode::getTitle() {
1313
return m_sTitle;
1414
}
1515

1616
// ----------------------------------------------------------------------
1717

18-
WSJCppPrintNode *WSJCppPrintNode::getParent() {
18+
WsjcppPrintNode *WsjcppPrintNode::getParent() {
1919
return m_pParent;
2020
}
2121

2222
// ----------------------------------------------------------------------
2323

24-
std::vector<WSJCppPrintNode *> WSJCppPrintNode::getChildsList() {
24+
std::vector<WsjcppPrintNode *> WsjcppPrintNode::getChildsList() {
2525
return m_vChilds;
2626
}
2727

2828
// ----------------------------------------------------------------------
2929

30-
WSJCppPrintNode *WSJCppPrintNode::getLastChild() {
30+
WsjcppPrintNode *WsjcppPrintNode::getLastChild() {
3131
if (m_vChilds.size() == 0) {
3232
return nullptr;
3333
}
@@ -36,85 +36,85 @@ WSJCppPrintNode *WSJCppPrintNode::getLastChild() {
3636

3737
// ----------------------------------------------------------------------
3838

39-
WSJCppPrintNode *WSJCppPrintNode::addChild(const std::string &sTitle) {
40-
WSJCppPrintNode *pNode = new WSJCppPrintNode(this, sTitle);
39+
WsjcppPrintNode *WsjcppPrintNode::addChild(const std::string &sTitle) {
40+
WsjcppPrintNode *pNode = new WsjcppPrintNode(this, sTitle);
4141
m_vChilds.push_back(pNode);
4242
return pNode;
4343
}
4444

4545
// ----------------------------------------------------------------------
4646

47-
bool WSJCppPrintNode::hasChilds() {
47+
bool WsjcppPrintNode::hasChilds() {
4848
return m_vChilds.size() > 0;
4949
}
5050

5151
// ----------------------------------------------------------------------
52-
// WSJCppPrintTree
52+
// WsjcppPrintTree
5353

54-
WSJCppPrintTree::WSJCppPrintTree(const std::string &sTitle) {
55-
TAG = "WSJCppPrintTree";
56-
m_pRootNode = new WSJCppPrintNode(nullptr, sTitle);
54+
WsjcppPrintTree::WsjcppPrintTree(const std::string &sTitle) {
55+
TAG = "WsjcppPrintTree";
56+
m_pRootNode = new WsjcppPrintNode(nullptr, sTitle);
5757
m_pCurrentNode = m_pRootNode;
5858
}
5959

6060
// ----------------------------------------------------------------------
6161

62-
WSJCppPrintNode *WSJCppPrintTree::getRootNode() {
62+
WsjcppPrintNode *WsjcppPrintTree::getRootNode() {
6363
return m_pRootNode;
6464
}
6565

6666
// ----------------------------------------------------------------------
6767

68-
WSJCppPrintNode *WSJCppPrintTree::getCurrentNode() {
68+
WsjcppPrintNode *WsjcppPrintTree::getCurrentNode() {
6969
return m_pCurrentNode;
7070
}
7171

7272
// ----------------------------------------------------------------------
7373

74-
WSJCppPrintTree &WSJCppPrintTree::switchToLatestChild() {
75-
WSJCppPrintNode *pChild = m_pCurrentNode->getLastChild();
74+
WsjcppPrintTree &WsjcppPrintTree::switchToLatestChild() {
75+
WsjcppPrintNode *pChild = m_pCurrentNode->getLastChild();
7676
if (pChild == nullptr) {
77-
WSJCppLog::throw_err(TAG, "Could not found last child");
77+
WsjcppLog::throw_err(TAG, "Could not found last child");
7878
}
7979
m_pCurrentNode = pChild;
8080
return *this;
8181
}
8282

8383
// ----------------------------------------------------------------------
8484

85-
WSJCppPrintTree &WSJCppPrintTree::addChild(const std::string &sTitle) {
85+
WsjcppPrintTree &WsjcppPrintTree::addChild(const std::string &sTitle) {
8686
m_pCurrentNode->addChild(sTitle);
8787
return *this;
8888
}
8989

9090
// ----------------------------------------------------------------------
9191

92-
WSJCppPrintTree &WSJCppPrintTree::switchToParent() {
93-
WSJCppPrintNode *pParent = m_pCurrentNode->getParent();
92+
WsjcppPrintTree &WsjcppPrintTree::switchToParent() {
93+
WsjcppPrintNode *pParent = m_pCurrentNode->getParent();
9494
if (pParent == nullptr) {
95-
WSJCppLog::throw_err(TAG, "Parent is null");
95+
WsjcppLog::throw_err(TAG, "Parent is null");
9696
}
9797
m_pCurrentNode = pParent;
9898
return *this;
9999
}
100100

101101
// ----------------------------------------------------------------------
102102

103-
std::string WSJCppPrintTree::printTree() {
103+
std::string WsjcppPrintTree::printTree() {
104104
return
105105
m_pRootNode->getTitle() + "\n"
106106
+ printRecoursive("", m_pRootNode);
107107
}
108108

109109
// ----------------------------------------------------------------------
110110

111-
std::string WSJCppPrintTree::printRecoursive(const std::string &sPrefix, WSJCppPrintNode *pParentNode) {
111+
std::string WsjcppPrintTree::printRecoursive(const std::string &sPrefix, WsjcppPrintNode *pParentNode) {
112112
std::string sRet = "";
113-
std::vector<WSJCppPrintNode *> v = pParentNode->getChildsList();
113+
std::vector<WsjcppPrintNode *> v = pParentNode->getChildsList();
114114
int nLen = v.size();
115115
for (int i = 0; i < nLen; i++) {
116116
bool bLatestChild = (i == nLen-1);
117-
WSJCppPrintNode *pNode = v[i];
117+
WsjcppPrintNode *pNode = v[i];
118118
sRet += sPrefix;
119119
sRet += bLatestChild ? "└─ " : "├─ ";
120120
sRet += pNode->getTitle() + "\n";

src/wsjcpp_print_tree.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@
44
#include <string>
55
#include <vector>
66

7-
class WSJCppPrintNode {
7+
class WsjcppPrintNode {
88
public:
9-
WSJCppPrintNode(WSJCppPrintNode *pParent, const std::string &sTitle);
9+
WsjcppPrintNode(WsjcppPrintNode *pParent, const std::string &sTitle);
1010
std::string getTitle();
11-
WSJCppPrintNode *getParent();
12-
std::vector<WSJCppPrintNode *> getChildsList();
13-
WSJCppPrintNode *getLastChild();
14-
WSJCppPrintNode *addChild(const std::string &sTitle);
11+
WsjcppPrintNode *getParent();
12+
std::vector<WsjcppPrintNode *> getChildsList();
13+
WsjcppPrintNode *getLastChild();
14+
WsjcppPrintNode *addChild(const std::string &sTitle);
1515
bool hasChilds();
1616
private:
1717
std::string TAG;
18-
WSJCppPrintNode *m_pParent;
18+
WsjcppPrintNode *m_pParent;
1919
std::string m_sTitle;
20-
std::vector<WSJCppPrintNode *> m_vChilds;
20+
std::vector<WsjcppPrintNode *> m_vChilds;
2121
};
2222

2323
// ----------------------------------------------------------------------
2424

25-
class WSJCppPrintTree {
25+
class WsjcppPrintTree {
2626
public:
27-
WSJCppPrintTree(const std::string &sTitle);
28-
WSJCppPrintNode *getRootNode();
29-
WSJCppPrintNode *getCurrentNode();
30-
WSJCppPrintTree &switchToLatestChild();
31-
WSJCppPrintTree &addChild(const std::string &sTitle);
32-
WSJCppPrintTree &switchToParent();
27+
WsjcppPrintTree(const std::string &sTitle);
28+
WsjcppPrintNode *getRootNode();
29+
WsjcppPrintNode *getCurrentNode();
30+
WsjcppPrintTree &switchToLatestChild();
31+
WsjcppPrintTree &addChild(const std::string &sTitle);
32+
WsjcppPrintTree &switchToParent();
3333
std::string printTree();
3434

3535
private:
3636
std::string TAG;
37-
WSJCppPrintNode *m_pRootNode;
38-
WSJCppPrintNode *m_pCurrentNode;
37+
WsjcppPrintNode *m_pRootNode;
38+
WsjcppPrintNode *m_pCurrentNode;
3939

40-
std::string printRecoursive(const std::string &sPrefix, WSJCppPrintNode *pParentNode);
40+
std::string printRecoursive(const std::string &sPrefix, WsjcppPrintNode *pParentNode);
4141
};
4242

4343
#endif // WSJCPP_PRINT_TREE_H

unit-tests.wsjcpp/src/unit_test_tree_simple.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#include <wsjcpp_core.h>
44
#include <wsjcpp_print_tree.h>
55

6-
REGISTRY_UNIT_TEST(UnitTestTreeSimple)
6+
REGISTRY_WSJCPP_UNIT_TEST(UnitTestTreeSimple)
77

88
UnitTestTreeSimple::UnitTestTreeSimple()
9-
: WSJCppUnitTestBase("UnitTestTreeSimple") {
9+
: WsjcppUnitTestBase("UnitTestTreeSimple") {
1010
}
1111

1212
// ---------------------------------------------------------------------
@@ -20,7 +20,7 @@ void UnitTestTreeSimple::init() {
2020
bool UnitTestTreeSimple::run() {
2121
bool bTestSuccess = true;
2222

23-
WSJCppPrintTree tree("Example Of Tree");
23+
WsjcppPrintTree tree("Example Of Tree");
2424
tree
2525
.addChild("Hello1")
2626
.switchToLatestChild()

unit-tests.wsjcpp/src/unit_test_tree_simple.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <wsjcpp_unit_tests.h>
55

66
// Description: TODO
7-
class UnitTestTreeSimple : public WSJCppUnitTestBase {
7+
class UnitTestTreeSimple : public WsjcppUnitTestBase {
88
public:
99
UnitTestTreeSimple();
1010
virtual void init();

0 commit comments

Comments
 (0)