@@ -39,6 +39,7 @@ Official Source Code: https://github.com/wsjcpp/wsjcpp-yaml
3939
4040std::string WSJCPP_INT_TO_STR (int number) {
4141 #if defined(__CODEGEARC__) && !defined(_WIN64)
42+ // TODO
4243 char buffer[] = {
4344 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
4445 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
@@ -57,6 +58,58 @@ std::string WSJCPP_INT_TO_STR(int number) {
5758 #endif
5859}
5960
61+ std::string WSJCPP_FLOAT_TO_STR (float number) {
62+ std::string ret;
63+ #if defined(__CODEGEARC__) && !defined(_WIN64)
64+ // TODO
65+ char buffer[] = {
66+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
67+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
68+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
69+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0
70+ };
71+ #if __CODEGEARC__ == 0x0770
72+ // 12.2
73+ _itoa (number, buffer, 10 );
74+ #else
75+ itoa (number, buffer, 10 );
76+ #endif
77+ ret = std::string (buffer);
78+ #else
79+ ret = std::to_string (number);
80+ #endif
81+ ret.erase (std::find_if (ret.rbegin (), ret.rend (), [](unsigned char ch) {
82+ return ch != ' 0' ;
83+ }).base (), ret.end ());
84+ return ret;
85+ }
86+
87+ std::string WSJCPP_DOUBLE_TO_STR (double number) {
88+ std::string ret;
89+ #if defined(__CODEGEARC__) && !defined(_WIN64)
90+ // TODO
91+ char buffer[] = {
92+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
93+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
94+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0 ,
95+ 0x0 ,0x0 ,0x0 ,0x0 , 0x0 ,0x0 ,0x0 ,0x0
96+ };
97+ #if __CODEGEARC__ == 0x0770
98+ // 12.2
99+ _itoa (number, buffer, 10 );
100+ #else
101+ itoa (number, buffer, 10 );
102+ #endif
103+ ret = std::string (buffer);
104+ #else
105+ ret = std::to_string (number);
106+ #endif
107+ ret.erase (std::find_if (ret.rbegin (), ret.rend (), [](unsigned char ch) {
108+ return ch != ' 0' ;
109+ }).base (), ret.end ());
110+ return ret;
111+ }
112+
60113// ---------------------------------------------------------------------
61114// WsjcppYamlPlaceInFile
62115
@@ -1234,6 +1287,48 @@ int WsjcppYamlCursor::valInt() const {
12341287 return 0 ;
12351288}
12361289
1290+ float WsjcppYamlCursor::valFloat () const {
1291+ if (m_pCurrentNode != WSJCPP_NULL) {
1292+ std::string sValue = m_pCurrentNode->getValue ();
1293+ float nValue = std::stof (sValue );
1294+ std::string sExpectedValue = WSJCPP_FLOAT_TO_STR (nValue);
1295+ if (sExpectedValue != sValue ) {
1296+ std::string error_msg = TAG + " : valInt, Element must be float but have a string" + m_pCurrentNode->getForLogFormat () + " ', but expected value is '" + sExpectedValue + " '" ;
1297+ throw std::runtime_error (error_msg);
1298+ }
1299+ return nValue;
1300+ }
1301+ return 0 .0f ;
1302+ }
1303+
1304+ WsjcppYamlCursor &WsjcppYamlCursor::val (float nValue) {
1305+ if (m_pCurrentNode != WSJCPP_NULL) {
1306+ m_pCurrentNode->setValue (WSJCPP_FLOAT_TO_STR (nValue));
1307+ }
1308+ return *this ;
1309+ }
1310+
1311+ double WsjcppYamlCursor::valDouble () const {
1312+ if (m_pCurrentNode != WSJCPP_NULL) {
1313+ std::string sValue = m_pCurrentNode->getValue ();
1314+ double nValue = std::stod (sValue );
1315+ std::string sExpectedValue = WSJCPP_DOUBLE_TO_STR (nValue);
1316+ if (sExpectedValue != sValue ) {
1317+ std::string error_msg = TAG + " : valInt, Element must be float but have a string '" + m_pCurrentNode->getForLogFormat () + " ', but expected value is '" + sExpectedValue + " '" ;
1318+ throw std::runtime_error (error_msg);
1319+ }
1320+ return nValue;
1321+ }
1322+ return 0 .0f ;
1323+ }
1324+
1325+ WsjcppYamlCursor &WsjcppYamlCursor::val (double nValue) {
1326+ if (m_pCurrentNode != WSJCPP_NULL) {
1327+ m_pCurrentNode->setValue (WSJCPP_DOUBLE_TO_STR (nValue));
1328+ }
1329+ return *this ;
1330+ }
1331+
12371332WsjcppYamlCursor &WsjcppYamlCursor::val (int nValue) {
12381333 if (m_pCurrentNode != WSJCPP_NULL) {
12391334 m_pCurrentNode->setValue (WSJCPP_INT_TO_STR (nValue));
0 commit comments