Skip to content

Commit 903bab7

Browse files
authored
Merge pull request #26 from wsjcpp/version-0.1.5
Version 0.1.5
2 parents db997f3 + 31730f3 commit 903bab7

17 files changed

+226
-46
lines changed

src.wsjcpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Automaticly generated by wsjcpp@v0.2.0
22
cmake_minimum_required(VERSION 3.0)
33

4-
add_definitions(-DWSJCPP_APP_VERSION="v0.1.3")
4+
add_definitions(-DWSJCPP_APP_VERSION="v0.1.5")
55
add_definitions(-DWSJCPP_APP_NAME="wsjcpp-yaml")
66

77
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ int main(int argc, char* argv[]) {
2222
return -1;
2323
}
2424

25-
if (!yaml.saveToFile(sFilePath)) {
26-
WsjcppLog::err(TAG, "Could not save data to file");
25+
if (!yaml.saveToFile(sFilePath, sError)) {
26+
WsjcppLog::err(TAG, "Could not save data to file: " + sError);
2727
return -1;
2828
}
2929

src/wsjcpp_yaml.cpp

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void WsjcppYamlNode::doEmpty() {
161161
if (m_nItemType == WSJCPP_YAML_NODE_UNDEFINED) {
162162
m_nItemType = WSJCPP_YAML_NODE_EMPTY;
163163
} else {
164-
throw std::runtime_error(TAG + ": Element already defined as '" + this->getItemTypeAsString() + "'");
164+
throw std::runtime_error(TAG + ": Element already defined as '" + this->getNodeTypeAsString() + "'");
165165
}
166166
}
167167

@@ -177,7 +177,7 @@ void WsjcppYamlNode::doArray() {
177177
if (m_nItemType == WSJCPP_YAML_NODE_UNDEFINED) {
178178
m_nItemType = WSJCPP_YAML_NODE_ARRAY;
179179
} else {
180-
throw std::runtime_error(TAG + ": Element already defined as '" + this->getItemTypeAsString() + "'");
180+
throw std::runtime_error(TAG + ": Element already defined as '" + this->getNodeTypeAsString() + "'");
181181
}
182182
}
183183

@@ -187,7 +187,7 @@ void WsjcppYamlNode::doMap() {
187187
if (m_nItemType == WSJCPP_YAML_NODE_UNDEFINED) {
188188
m_nItemType = WSJCPP_YAML_NODE_MAP;
189189
} else {
190-
throw std::runtime_error(TAG + ": Element already defined as '" + this->getItemTypeAsString() + "'");
190+
throw std::runtime_error(TAG + ": Element already defined as '" + this->getNodeTypeAsString() + "'");
191191
}
192192
}
193193

@@ -197,7 +197,7 @@ void WsjcppYamlNode::doValue() {
197197
if (m_nItemType == WSJCPP_YAML_NODE_UNDEFINED) {
198198
m_nItemType = WSJCPP_YAML_NODE_VALUE;
199199
} else {
200-
throw std::runtime_error(TAG + ": Element already defined as '" + this->getItemTypeAsString() + "'");
200+
throw std::runtime_error(TAG + ": Element already defined as '" + this->getNodeTypeAsString() + "'");
201201
}
202202
}
203203

@@ -413,15 +413,20 @@ WsjcppYamlNode *WsjcppYamlNode::getElement(int i) {
413413

414414
// ---------------------------------------------------------------------
415415

416-
bool WsjcppYamlNode::appendElement(WsjcppYamlNode *pItem) {
417-
if (pItem->isEmpty()) {
418-
m_vObjects.push_back(pItem); // TODO clone object
416+
bool WsjcppYamlNode::appendElement(WsjcppYamlNode *pNode) {
417+
if (pNode->isEmpty()) {
418+
m_vObjects.push_back(pNode); // TODO clone object
419419
return true;
420420
}
421421
if (m_nItemType != WSJCPP_YAML_NODE_ARRAY) {
422-
throw std::runtime_error(TAG + ": appendElement, Element must be array for " + this->getForLogFormat());
423-
}
424-
m_vObjects.push_back(pItem); // TODO clone object
422+
throw std::runtime_error(TAG + ": appendElement, "
423+
"tring add node \n"
424+
" name='" + pNode->getName() + "'\n"
425+
" type=" + pNode->getNodeTypeAsString() + "\n"
426+
" line=" + std::to_string(pNode->getNumberOfLine()) + ")\n"
427+
" To element (must be array) \n" + this->getForLogFormat());
428+
}
429+
m_vObjects.push_back(pNode); // TODO clone object
425430
return true;
426431
}
427432

@@ -613,7 +618,7 @@ std::string WsjcppYamlNode::toString(std::string sIntent) {
613618

614619
// ---------------------------------------------------------------------
615620

616-
std::string WsjcppYamlNode::getItemTypeAsString() {
621+
std::string WsjcppYamlNode::getNodeTypeAsString() {
617622
if (m_nItemType == WSJCPP_YAML_NODE_UNDEFINED) {
618623
return "undefined";
619624
} else if (m_nItemType == WSJCPP_YAML_NODE_ARRAY) {
@@ -666,6 +671,18 @@ int WsjcppYamlNode::getNodeIntent() {
666671

667672
// ---------------------------------------------------------------------
668673

674+
int WsjcppYamlNode::getNumberOfLine() const {
675+
return m_placeInFile.getNumberOfLine();
676+
}
677+
678+
// ---------------------------------------------------------------------
679+
680+
void WsjcppYamlNode::setNumberOfLine(int nNumberOfLine) {
681+
m_placeInFile.setNumberOfLine(nNumberOfLine);
682+
}
683+
684+
// ---------------------------------------------------------------------
685+
669686
void WsjcppYamlNode::throw_error(const std::string &sError) {
670687
throw std::runtime_error(sError.c_str());
671688
}
@@ -1191,6 +1208,12 @@ WsjcppYamlCursor &WsjcppYamlCursor::val(bool bValue) {
11911208

11921209
// ---------------------------------------------------------------------
11931210

1211+
WsjcppYamlNode *WsjcppYamlCursor::node() {
1212+
return m_pCurrentNode;
1213+
}
1214+
1215+
// ---------------------------------------------------------------------
1216+
11941217
WsjcppYamlCursor WsjcppYamlCursor::operator[](int idx) const {
11951218
if (m_pCurrentNode != nullptr && m_pCurrentNode->isArray() && idx < m_pCurrentNode->getLength() && idx >= 0) {
11961219
return WsjcppYamlCursor(m_pCurrentNode->getElement(idx));
@@ -1240,9 +1263,10 @@ bool WsjcppYaml::loadFromFile(const std::string &sFileName, std::string &sError)
12401263

12411264
// ---------------------------------------------------------------------
12421265

1243-
bool WsjcppYaml::saveToFile(const std::string &sFileName) {
1266+
bool WsjcppYaml::saveToFile(const std::string &sFileName, std::string &sError) {
12441267
std::string sBuffer = m_pRoot->toString();
12451268
if (!WsjcppCore::writeFile(sFileName, sBuffer)) {
1269+
sError = "Could not save to file";
12461270
return false;
12471271
}
12481272
return true;
@@ -1256,7 +1280,7 @@ bool WsjcppYaml::loadFromString(const std::string &sBufferName, const std::strin
12561280

12571281
// ---------------------------------------------------------------------
12581282

1259-
bool WsjcppYaml::saveToString(std::string &sBuffer) {
1283+
bool WsjcppYaml::saveToString(std::string &sBuffer, std::string &sError) {
12601284
sBuffer = m_pRoot->toString();
12611285
return true;
12621286
}
@@ -1440,38 +1464,30 @@ void WsjcppYaml::process_hasName_emptyValue_arrayItem() {
14401464
// ---------------------------------------------------------------------
14411465

14421466
void WsjcppYaml::process_hasName_emptyValue_noArrayItem() {
1467+
// std::cout << "process_hasName_emptyValue_noArrayItem" << std::endl;
14431468
if (m_parseLine.getIntent() == m_pParseCurrentParentNode->getNodeIntent()) {
14441469
if (m_pParseCurrentParentNode->getParent() != nullptr) {
14451470
m_pParseCurrentParentNode = m_pParseCurrentParentNode->getParent();
14461471
}
14471472
}
1448-
// std::cout << "process_hasName_emptyValue_noArrayItem " << std::endl;
14491473
WsjcppYamlNode *pNode = new WsjcppYamlNode(
14501474
m_pParseCurrentParentNode, m_parsePlaceInFile,
14511475
WSJCPP_YAML_NODE_UNDEFINED
14521476
);
14531477
if (m_parseLine.getValueQuotes() != WSJCPP_YAML_QUOTES_NONE) {
1478+
// std::cout << "pNode->doValue() for '" << m_parseLine.getName() << "' value: '" << m_parseLine.getValue() << "' " << std::endl;
14541479
pNode->doValue();
14551480
pNode->setValue(m_parseLine.getValue(), m_parseLine.getValueQuotes());
14561481
}
1457-
int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
1482+
// int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
14581483
pNode->setName(m_parseLine.getName(), m_parseLine.getNameQuotes());
14591484
pNode->setComment(m_parseLine.getComment());
14601485
pNode->setNodeIntents(m_vStackDiffNodeIntents);
1461-
// std::cout << "current node [" << m_vStackDiffNodeIntents.back() << "]" << std::endl;
1462-
1463-
/* if (nDiffIntent == 0 && m_pParseCurrentParentNode->isUndefined()) {
1464-
std::cout << "shit nDiffIntent = " << nDiffIntent << std::endl;
1465-
std::cout << "shit m_pParseCurrentParentNode->getName() = " << m_pParseCurrentParentNode->getName() << std::endl;
1466-
if (m_pParseCurrentParentNode->getParent() != nullptr) {
1467-
std::cout << "shit "
1468-
<< " {" << m_pParseCurrentParentNode->getPlaceInFile().getLine() << "} "
1469-
<< " {" << m_parsePlaceInFile.getLine() << "} " << std::endl;
1470-
}
1471-
}
1472-
*/
1486+
14731487
m_pParseCurrentParentNode->setElement(m_parseLine.getName(), pNode);
1474-
m_pParseCurrentParentNode = pNode;
1488+
if (pNode->isUndefined()) {
1489+
m_pParseCurrentParentNode = pNode;
1490+
}
14751491
}
14761492

14771493
// ---------------------------------------------------------------------
@@ -1481,11 +1497,18 @@ void WsjcppYaml::process_hasName_hasValue_arrayItem() {
14811497
if (m_pParseCurrentParentNode->isUndefined()) {
14821498
m_pParseCurrentParentNode->doArray();
14831499
}
1500+
// if (!m_pParseCurrentParentNode->isArray()) {
1501+
// std::cout << "m_pParseCurrentParentNode->getName(): " << m_pParseCurrentParentNode->getName() << std::endl;
1502+
// }
1503+
14841504
WsjcppYamlNode *pMapItem = new WsjcppYamlNode(
14851505
m_pParseCurrentParentNode, m_parsePlaceInFile,
14861506
WSJCPP_YAML_NODE_MAP
14871507
);
1508+
// std::cout << "m_parseLine.getName(): " << m_parseLine.getName() << std::endl;
1509+
14881510
m_pParseCurrentParentNode->appendElement(pMapItem);
1511+
// std::cout << "appended " << std::endl;
14891512
m_pParseCurrentParentNode = pMapItem;
14901513
pMapItem->setNodeIntents(m_vStackDiffNodeIntents);
14911514

@@ -1506,6 +1529,7 @@ void WsjcppYaml::process_hasName_hasValue_arrayItem() {
15061529
// ---------------------------------------------------------------------
15071530

15081531
void WsjcppYaml::process_hasName_hasValue_noArrayItem() {
1532+
// std::cout << "process_hasName_hasValue_noArrayItem" << std::endl;
15091533
WsjcppYamlNode *pNode = new WsjcppYamlNode(
15101534
m_pParseCurrentParentNode, m_parsePlaceInFile,
15111535
WSJCPP_YAML_NODE_VALUE
@@ -1550,6 +1574,7 @@ void WsjcppYaml::process_emptyName_hasValue_noArrayItem() {
15501574
// ---------------------------------------------------------------------
15511575

15521576
void WsjcppYaml::process_emptyName_emptyValue_arrayItem() {
1577+
// std::cout << "process_emptyName_emptyValue_arrayItem" << std::endl;
15531578
if (m_pParseCurrentParentNode->isUndefined()) {
15541579
m_pParseCurrentParentNode->doArray();
15551580
}

src/wsjcpp_yaml.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class WsjcppYamlNode {
6565
const WsjcppYamlPlaceInFile &placeInFile,
6666
WsjcppYamlNodeType nItemType
6767
);
68+
// WsjcppYamlNode(
69+
// WsjcppYamlNode *pParent,
70+
// WsjcppYamlNodeType nItemType
71+
// const WsjcppYamlPlaceInFile &placeInFile,
72+
// );
6873
~WsjcppYamlNode();
6974
WsjcppYamlNode *getParent();
7075

@@ -119,14 +124,17 @@ class WsjcppYamlNode {
119124

120125
std::string getSerializedName();
121126
std::string toString(std::string sIntent = "");
122-
std::string getItemTypeAsString();
127+
std::string getNodeTypeAsString();
123128

124129
std::string getForLogFormat();
125130
int getNodeLastIntent();
126131
std::string getStringNodeLastIntent();
127132
void setNodeIntents(const std::vector<int> & vNodeIntents);
128133
int getNodeIntent();
129134

135+
int getNumberOfLine() const;
136+
void setNumberOfLine(int nNumberOfLine);
137+
130138
private:
131139
void throw_error(const std::string &sError);
132140

@@ -235,6 +243,8 @@ class WsjcppYamlCursor {
235243
bool valBool();
236244
WsjcppYamlCursor &val(bool bValue);
237245

246+
// node
247+
WsjcppYamlNode *node();
238248

239249
WsjcppYamlCursor operator[](int idx) const;
240250
WsjcppYamlCursor operator[](const std::string &sName) const;
@@ -253,9 +263,9 @@ class WsjcppYaml {
253263
~WsjcppYaml();
254264
void clear();
255265
bool loadFromFile(const std::string &sFileName, std::string &sError);
256-
bool saveToFile(const std::string &sFileName);
266+
bool saveToFile(const std::string &sFileName, std::string &sError);
257267
bool loadFromString(const std::string &sBufferName, const std::string &sBuffer, std::string &sError);
258-
bool saveToString(std::string &sBuffer);
268+
bool saveToString(std::string &sBuffer, std::string &sError);
259269
WsjcppYamlNode *getRoot();
260270

261271
WsjcppYamlCursor getCursor() const;

unit-tests.wsjcpp/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cmake_minimum_required(VERSION 3.0)
33

44
project(unit-tests C CXX)
5-
add_definitions(-DWSJCPP_APP_VERSION="ut-v0.1.3")
5+
add_definitions(-DWSJCPP_APP_VERSION="ut-v0.1.5")
66
add_definitions(-DWSJCPP_APP_NAME="unit-tests-wsjcpp-yaml")
77

88
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -51,6 +51,8 @@ list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_cursor.cpp")
5151
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_tag_names.cpp")
5252
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_cleanup.cpp")
5353
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_append_elements.cpp")
54+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_read_wsjcpp_hold_yaml.cpp")
55+
5456

5557
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.user-custom.txt)
5658

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
wsjcpp_version: v0.0.1
2+
cmake_cxx_standard: 11
3+
cmake_minimum_required: 3.0
4+
5+
name: wsjcpp-core
6+
version: v0.2.1
7+
description: Basic Utils for wsjcpp
8+
issues: https://github.com/wsjcpp/wsjcpp-core/issues
9+
repositories:
10+
- type: main
11+
url: "https://github.com/wsjcpp/wsjcpp-core"
12+
keywords:
13+
- c++
14+
- wsjcpp
15+
16+
authors:
17+
- name: Evgenii Sopov
18+
email: mrseakg@gmail.com
19+
20+
distribution:
21+
- source-file: src/wsjcpp_core.cpp
22+
target-file: wsjcpp_core.cpp
23+
type: "source-code"
24+
sha1: "09ef821bbc090fc1cd8a15bc4a57a9a2ce8ae00d"
25+
- source-file: src/wsjcpp_core.h
26+
target-file: wsjcpp_core.h
27+
type: "source-code" # todo must be header-file
28+
sha1: "e6e4ab2067d3c942db08e3b79862486eaf851e4b"
29+
- source-file: "src/wsjcpp_unit_tests.cpp"
30+
target-file: "wsjcpp_unit_tests.cpp"
31+
type: "unit-tests"
32+
sha1: "fd5989d1a83c8b90bdc4d5e9bc9c3051eaa1e6d2"
33+
- source-file: "src/wsjcpp_unit_tests.h"
34+
target-file: "wsjcpp_unit_tests.h"
35+
type: "unit-tests"
36+
sha1: "83d4b6e046b6b58c42882ccae4be413e03c401c1"
37+
- source-file: "src/wsjcpp_unit_tests_main.cpp"
38+
target-file: "wsjcpp_unit_tests_main.cpp"
39+
type: "unit-tests"
40+
sha1: "388ae269b325c5e161f6c3a5c598575714a4bffc"
41+
- source-file: "scripts.wsjcpp/generate.WsjcppUnitTest.wsjcpp-script"
42+
target-file: "generate.WsjcppUnitTest.wsjcpp-script"
43+
type: "safe-scripting-generate"
44+
sha1: "a7c9c2d19bf81c5b00e659384b0b92a99319a4c1"
45+
- source-file: "scripts.wsjcpp/generate.Class.wsjcpp-script"
46+
target-file: "generate.Class.wsjcpp-script"
47+
type: "safe-scripting-generate"
48+
sha1: "de1799907c685d606b93e08b821b540c2faa2db1"
49+
50+
unit-tests:
51+
cases:
52+
- name: CoreNormalizePath
53+
description: Check function normalizePath
54+
- name: CoreExtractFilename
55+
description: Check function extract filenane from path
56+
- name: "ToUpper"
57+
description: "String to upper"
58+
- name: "CreateUuid"
59+
description: "Test generation uuids"
60+
- name: "GetEnv"
61+
description: "Test getEnv function"
62+
- name: "ToLower"
63+
description: "Test toLower"
64+
- name: "ReplaceAll"
65+
description: "Test replace all"
66+
- name: "DecodeUriComponent"
67+
description: "Check decoding"
68+
- name: "EncodeUriComponent"
69+
description: "Check encoding"
70+
- name: "Uint2HexString"
71+
description: "Test convert unsigned int to hex string"
72+
- name: "Split"
73+
description: "Test split function"
74+
- name: "CreateEmptyFile"
75+
description: "Test create empty file"
76+
- name: "ReadFileToBuffer"
77+
description: "test for readFileToBuffer"
78+
- name: "Join"
79+
description: "Test join function"
80+
- name: "getHumanSizeBytes"
81+
description: "Test function get human size in bytes"
82+
- name: "TestResources"
83+
description: "Test basic resources"
84+
- name: "ListOfDirs"
85+
description: "Check list of directories"
86+
- name: "FilePermissions"
87+
description: ""
88+
- name: "StringPadding"
89+
description: ""
90+
- name: "DateTimeFormat"
91+
description: ""

0 commit comments

Comments
 (0)