@@ -313,39 +313,6 @@ bool WsjcppYamlItem::setElementValue(
313313
314314// ---------------------------------------------------------------------
315315
316- bool WsjcppYamlItem::setElementValue (
317- const std::string &sName ,
318- long nValue,
319- WsjcppYamlQuotes nNameQuotes,
320- WsjcppYamlQuotes nValueQuotes
321- ) {
322- return setElementValue (sName , std::to_string (nValue), nNameQuotes, nValueQuotes);
323- }
324-
325- // ---------------------------------------------------------------------
326-
327- bool WsjcppYamlItem::setElementValue (
328- const std::string &sName ,
329- int nValue,
330- WsjcppYamlQuotes nNameQuotes,
331- WsjcppYamlQuotes nValueQuotes
332- ) {
333- return setElementValue (sName , std::to_string (nValue), nNameQuotes, nValueQuotes);
334- }
335-
336- // ---------------------------------------------------------------------
337-
338- bool WsjcppYamlItem::setElementValue (
339- const std::string &sName ,
340- bool bValue,
341- WsjcppYamlQuotes nNameQuotes,
342- WsjcppYamlQuotes nValueQuotes
343- ) {
344- return setElementValue (sName , (bValue ? " yes" : " no" ), nNameQuotes, nValueQuotes);
345- }
346-
347- // ---------------------------------------------------------------------
348-
349316bool WsjcppYamlItem::createElementMap (const std::string &sName , WsjcppYamlQuotes nNameQuotes) {
350317 if (m_nItemType != WSJCPP_YAML_ITEM_MAP ) {
351318 WsjcppLog::throw_err (TAG, " createElementMap, Element must be 'map' for " + this ->getPlaceInFile ().getForLogFormat ());
@@ -498,7 +465,6 @@ bool WsjcppYamlItem::isValue() {
498465// ---------------------------------------------------------------------
499466
500467std::string WsjcppYamlItem::getValue () {
501- WsjcppLog::warn (TAG, " getValue is deprecated try getStringValue, getBoolValue, getLongValue, getIntValue..." );
502468 if (m_nItemType != WSJCPP_YAML_ITEM_VALUE) {
503469 WsjcppLog::throw_err (TAG, " getValue, Element must be value for " + this ->getForLogFormat ());
504470 }
@@ -507,55 +473,6 @@ std::string WsjcppYamlItem::getValue() {
507473
508474// ---------------------------------------------------------------------
509475
510- std::string WsjcppYamlItem::getStringValue () {
511- if (m_nItemType != WSJCPP_YAML_ITEM_VALUE) {
512- WsjcppLog::throw_err (TAG, " getStringValue, Element must be value for " + this ->getForLogFormat ());
513- }
514- return m_sValue;
515- }
516-
517- // ---------------------------------------------------------------------
518-
519- bool WsjcppYamlItem::getBoolValue () {
520- std::string sValue = getStringValue ();
521- sValue = WsjcppCore::toLower (sValue );
522- if (sValue == " yes" || sValue == " true" ) {
523- return true ;
524- } else if (sValue == " no" || sValue == " false" ) {
525- return false ;
526- } else {
527- WsjcppLog::throw_err (TAG, " getBoolValue, Element must be bool expected with ignore case like"
528- " ['yes','no','true','false'] for " + this ->getForLogFormat ());
529- }
530- return false ;
531- }
532-
533- // ---------------------------------------------------------------------
534-
535- long WsjcppYamlItem::getLongValue () {
536- std::string sValue = getStringValue ();
537- sValue = WsjcppCore::toLower (sValue );
538- long nValue = std::atol (sValue .c_str ());
539- if (std::to_string (nValue) != sValue ) {
540- WsjcppLog::throw_err (TAG, " getLongValue, Element must be long or int but have a string" + this ->getForLogFormat ());
541- }
542- return nValue;
543- }
544-
545- // ---------------------------------------------------------------------
546-
547- int WsjcppYamlItem::getIntValue () {
548- std::string sValue = getStringValue ();
549- sValue = WsjcppCore::toLower (sValue );
550- int nValue = std::atoi (sValue .c_str ());
551- if (std::to_string (nValue) != sValue ) {
552- WsjcppLog::throw_err (TAG, " getLongValue, Element must be int but have a string" + this ->getForLogFormat ());
553- }
554- return nValue;
555- }
556-
557- // ---------------------------------------------------------------------
558-
559476void WsjcppYamlItem::setValue (const std::string &sValue , WsjcppYamlQuotes nQuotes) {
560477 if (m_nItemType != WSJCPP_YAML_ITEM_VALUE) {
561478 WsjcppLog::throw_err (TAG, " setValue, Element must be value for " + this ->getForLogFormat ());
@@ -987,12 +904,14 @@ void WsjcppYamlParserStatus::logUnknownLine(const std::string &sPrefix) {
987904
988905WsjcppYamlCursor::WsjcppYamlCursor (WsjcppYamlItem *pCurrentNode) {
989906 m_pCurrentNode = pCurrentNode;
907+ TAG = " WsjcppYamlCursor" ;
990908}
991909
992910// ---------------------------------------------------------------------
993911
994- WsjcppYamlCursor::WsjcppYamlCursor () {
995- m_pCurrentNode = nullptr ;
912+ WsjcppYamlCursor::WsjcppYamlCursor ()
913+ : WsjcppYamlCursor(nullptr ) {
914+ // nothing
996915}
997916
998917// ---------------------------------------------------------------------
@@ -1009,6 +928,18 @@ bool WsjcppYamlCursor::isNull() const {
1009928
1010929// ---------------------------------------------------------------------
1011930
931+ bool WsjcppYamlCursor::isUndefined () const {
932+ return m_pCurrentNode != nullptr && m_pCurrentNode->isUndefined ();
933+ }
934+
935+ // ---------------------------------------------------------------------
936+
937+ bool WsjcppYamlCursor::isValue () const {
938+ return m_pCurrentNode != nullptr && m_pCurrentNode->isValue ();
939+ }
940+
941+ // ---------------------------------------------------------------------
942+
1012943bool WsjcppYamlCursor::isArray () const {
1013944 return m_pCurrentNode != nullptr && m_pCurrentNode->isArray ();
1014945}
@@ -1027,6 +958,130 @@ bool WsjcppYamlCursor::isMap() const {
1027958
1028959// ---------------------------------------------------------------------
1029960
961+ std::vector<std::string> WsjcppYamlCursor::keys () const {
962+ return m_pCurrentNode != nullptr && m_pCurrentNode->isMap () ? m_pCurrentNode->getKeys () : std::vector<std::string>();
963+ }
964+
965+ // ---------------------------------------------------------------------
966+
967+ bool WsjcppYamlCursor::hasKey (const std::string &sKey ) const {
968+ return m_pCurrentNode != nullptr && m_pCurrentNode->isMap () && m_pCurrentNode->hasElement (sKey );
969+ }
970+
971+ // ---------------------------------------------------------------------
972+
973+ // WsjcppYamlCursor &WsjcppYamlCursor::set(const std::string &sName, const std::string &sValue) {
974+ // return *this;
975+ // }
976+ //
977+ // // ---------------------------------------------------------------------
978+ //
979+ // WsjcppYamlCursor &WsjcppYamlCursor::set(const std::string &sName, int nValue) {
980+ // return *this;
981+ // }
982+ //
983+ // // ---------------------------------------------------------------------
984+ //
985+ // WsjcppYamlCursor &WsjcppYamlCursor::set(const std::string &sName, bool bValue) {
986+ // return *this;
987+ // }
988+ //
989+ // // ---------------------------------------------------------------------
990+ //
991+ // WsjcppYamlCursor &WsjcppYamlCursor::remove(const std::string &sKey) {
992+ // return *this;
993+ // }
994+
995+ // ---------------------------------------------------------------------
996+
997+ std::string WsjcppYamlCursor::comment () {
998+ return m_pCurrentNode != nullptr ? m_pCurrentNode->getComment () : " " ;
999+ }
1000+
1001+ // ---------------------------------------------------------------------
1002+
1003+ WsjcppYamlCursor &WsjcppYamlCursor::comment (const std::string& sComment ) {
1004+ if (m_pCurrentNode != nullptr ) {
1005+ m_pCurrentNode->setComment (sComment );
1006+ }
1007+ return *this ;
1008+ }
1009+
1010+ // ---------------------------------------------------------------------
1011+
1012+ std::string WsjcppYamlCursor::valStr () {
1013+ return m_pCurrentNode != nullptr ? m_pCurrentNode->getValue () : " " ;
1014+ }
1015+
1016+ // ---------------------------------------------------------------------
1017+
1018+ WsjcppYamlCursor &WsjcppYamlCursor::val (const std::string &sValue ) {
1019+ if (m_pCurrentNode != nullptr ) {
1020+ m_pCurrentNode->setValue (sValue ); // TODO reserch need or not add quotes
1021+ }
1022+ return *this ;
1023+ }
1024+
1025+ // ---------------------------------------------------------------------
1026+
1027+ WsjcppYamlCursor &WsjcppYamlCursor::val (const char *sValue ) {
1028+ this ->val (std::string (sValue ));
1029+ return *this ;
1030+ }
1031+
1032+ // ---------------------------------------------------------------------
1033+
1034+ int WsjcppYamlCursor::valInt () {
1035+ if (m_pCurrentNode != nullptr ) {
1036+ std::string sValue = m_pCurrentNode->getValue ();
1037+ sValue = WsjcppCore::toLower (sValue );
1038+ int nValue = std::atoi (sValue .c_str ());
1039+ if (std::to_string (nValue) != sValue ) {
1040+ WsjcppLog::throw_err (TAG, " valInt, Element must be int but have a string" + m_pCurrentNode->getForLogFormat ());
1041+ }
1042+ return nValue;
1043+ }
1044+ return 0 ;
1045+ }
1046+
1047+ // ---------------------------------------------------------------------
1048+
1049+ WsjcppYamlCursor &WsjcppYamlCursor::val (int nValue) {
1050+ if (m_pCurrentNode != nullptr ) {
1051+ m_pCurrentNode->setValue (std::to_string (nValue));
1052+ }
1053+ return *this ;
1054+ }
1055+
1056+ // ---------------------------------------------------------------------
1057+
1058+ bool WsjcppYamlCursor::valBool () {
1059+ if (m_pCurrentNode != nullptr ) {
1060+ std::string sValue = m_pCurrentNode->getValue ();
1061+ sValue = WsjcppCore::toLower (sValue );
1062+ if (sValue == " yes" || sValue == " true" ) {
1063+ return true ;
1064+ } else if (sValue == " no" || sValue == " false" ) {
1065+ return false ;
1066+ } else {
1067+ WsjcppLog::throw_err (TAG, " valBool, Element must be bool expected with ignore case like"
1068+ " ['yes','no','true','false'] for " + m_pCurrentNode->getForLogFormat ());
1069+ }
1070+ }
1071+ return false ;
1072+ }
1073+
1074+ // ---------------------------------------------------------------------
1075+
1076+ WsjcppYamlCursor &WsjcppYamlCursor::val (bool bValue) {
1077+ if (m_pCurrentNode != nullptr ) {
1078+ m_pCurrentNode->setValue ((bValue ? " yes" : " no" ));
1079+ }
1080+ return *this ;
1081+ }
1082+
1083+ // ---------------------------------------------------------------------
1084+
10301085WsjcppYamlCursor WsjcppYamlCursor::operator [](int idx) const {
10311086 if (m_pCurrentNode != nullptr && m_pCurrentNode->isArray () && idx < m_pCurrentNode->getLength () && idx >= 0 ) {
10321087 return WsjcppYamlCursor (m_pCurrentNode->getElement (idx));
0 commit comments