@@ -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+
669686void WsjcppYamlNode::throw_error (const std::string &sError ) {
670687 throw std::runtime_error (sError .c_str ());
671688}
@@ -1447,38 +1464,30 @@ void WsjcppYaml::process_hasName_emptyValue_arrayItem() {
14471464// ---------------------------------------------------------------------
14481465
14491466void WsjcppYaml::process_hasName_emptyValue_noArrayItem () {
1467+ // std::cout << "process_hasName_emptyValue_noArrayItem" << std::endl;
14501468 if (m_parseLine.getIntent () == m_pParseCurrentParentNode->getNodeIntent ()) {
14511469 if (m_pParseCurrentParentNode->getParent () != nullptr ) {
14521470 m_pParseCurrentParentNode = m_pParseCurrentParentNode->getParent ();
14531471 }
14541472 }
1455- // std::cout << "process_hasName_emptyValue_noArrayItem " << std::endl;
14561473 WsjcppYamlNode *pNode = new WsjcppYamlNode (
14571474 m_pParseCurrentParentNode, m_parsePlaceInFile,
14581475 WSJCPP_YAML_NODE_UNDEFINED
14591476 );
14601477 if (m_parseLine.getValueQuotes () != WSJCPP_YAML_QUOTES_NONE) {
1478+ // std::cout << "pNode->doValue() for '" << m_parseLine.getName() << "' value: '" << m_parseLine.getValue() << "' " << std::endl;
14611479 pNode->doValue ();
14621480 pNode->setValue (m_parseLine.getValue (), m_parseLine.getValueQuotes ());
14631481 }
1464- int nDiffIntent = m_parseLine.getIntent () - m_nParseCurrentIntent;
1482+ // int nDiffIntent = m_parseLine.getIntent() - m_nParseCurrentIntent;
14651483 pNode->setName (m_parseLine.getName (), m_parseLine.getNameQuotes ());
14661484 pNode->setComment (m_parseLine.getComment ());
14671485 pNode->setNodeIntents (m_vStackDiffNodeIntents);
1468- // std::cout << "current node [" << m_vStackDiffNodeIntents.back() << "]" << std::endl;
1469-
1470- /* if (nDiffIntent == 0 && m_pParseCurrentParentNode->isUndefined()) {
1471- std::cout << "shit nDiffIntent = " << nDiffIntent << std::endl;
1472- std::cout << "shit m_pParseCurrentParentNode->getName() = " << m_pParseCurrentParentNode->getName() << std::endl;
1473- if (m_pParseCurrentParentNode->getParent() != nullptr) {
1474- std::cout << "shit "
1475- << " {" << m_pParseCurrentParentNode->getPlaceInFile().getLine() << "} "
1476- << " {" << m_parsePlaceInFile.getLine() << "} " << std::endl;
1477- }
1478- }
1479- */
1486+
14801487 m_pParseCurrentParentNode->setElement (m_parseLine.getName (), pNode);
1481- m_pParseCurrentParentNode = pNode;
1488+ if (pNode->isUndefined ()) {
1489+ m_pParseCurrentParentNode = pNode;
1490+ }
14821491}
14831492
14841493// ---------------------------------------------------------------------
@@ -1488,11 +1497,18 @@ void WsjcppYaml::process_hasName_hasValue_arrayItem() {
14881497 if (m_pParseCurrentParentNode->isUndefined ()) {
14891498 m_pParseCurrentParentNode->doArray ();
14901499 }
1500+ // if (!m_pParseCurrentParentNode->isArray()) {
1501+ // std::cout << "m_pParseCurrentParentNode->getName(): " << m_pParseCurrentParentNode->getName() << std::endl;
1502+ // }
1503+
14911504 WsjcppYamlNode *pMapItem = new WsjcppYamlNode (
14921505 m_pParseCurrentParentNode, m_parsePlaceInFile,
14931506 WSJCPP_YAML_NODE_MAP
14941507 );
1508+ // std::cout << "m_parseLine.getName(): " << m_parseLine.getName() << std::endl;
1509+
14951510 m_pParseCurrentParentNode->appendElement (pMapItem);
1511+ // std::cout << "appended " << std::endl;
14961512 m_pParseCurrentParentNode = pMapItem;
14971513 pMapItem->setNodeIntents (m_vStackDiffNodeIntents);
14981514
@@ -1513,6 +1529,7 @@ void WsjcppYaml::process_hasName_hasValue_arrayItem() {
15131529// ---------------------------------------------------------------------
15141530
15151531void WsjcppYaml::process_hasName_hasValue_noArrayItem () {
1532+ // std::cout << "process_hasName_hasValue_noArrayItem" << std::endl;
15161533 WsjcppYamlNode *pNode = new WsjcppYamlNode (
15171534 m_pParseCurrentParentNode, m_parsePlaceInFile,
15181535 WSJCPP_YAML_NODE_VALUE
@@ -1557,6 +1574,7 @@ void WsjcppYaml::process_emptyName_hasValue_noArrayItem() {
15571574// ---------------------------------------------------------------------
15581575
15591576void WsjcppYaml::process_emptyName_emptyValue_arrayItem () {
1577+ // std::cout << "process_emptyName_emptyValue_arrayItem" << std::endl;
15601578 if (m_pParseCurrentParentNode->isUndefined ()) {
15611579 m_pParseCurrentParentNode->doArray ();
15621580 }
0 commit comments