Skip to content

Commit 1df461b

Browse files
committed
More operators for casts
1 parent 91e5022 commit 1df461b

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ int main(int argc, char* argv[]) {
5555
return -1;
5656
}
5757
std::cout << "Done." << std::endl;
58-
std::string s = yaml["version"];
59-
// int nVer = yaml["version"];
60-
// bool bVer = yaml["version"];
61-
std::cout << s << std::endl;
58+
std::string sVer = yaml["version"];
59+
int nVer = yaml["version"];
60+
bool bVer = yaml["version"];
61+
std::cout << sVer << std::endl;
62+
std::cout << nVer << std::endl;
63+
std::cout << bVer << std::endl;
6264

6365
example_operator_1();
6466
return 0;

src/wsjcpp_yaml.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,14 @@ WsjcppYamlCursor WsjcppYamlCursor::operator[](const std::string &sName) const {
12371237
return WsjcppYamlCursor();
12381238
}
12391239

1240+
WsjcppYamlCursor WsjcppYamlCursor::operator[](const char *pName) const {
1241+
std::string sName(pName);
1242+
if (m_pCurrentNode != nullptr && m_pCurrentNode->isMap() && m_pCurrentNode->hasElement(sName)) {
1243+
return WsjcppYamlCursor(m_pCurrentNode->getElement(sName));
1244+
}
1245+
return WsjcppYamlCursor();
1246+
}
1247+
12401248
WsjcppYamlCursor& WsjcppYamlCursor::operator=(const char *sVal) {
12411249
return this->val(std::string(sVal));
12421250
}

src/wsjcpp_yaml.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,13 @@ class WsjcppYamlCursor {
260260

261261
std::string getCurrentNodePath();
262262

263-
explicit operator int() const { return valInt(); };
264-
explicit operator bool() const { return valBool(); }
263+
operator int() const { return int(valInt()); };
264+
// explicit operator bool() const { return valBool(); }
265265
operator std::string() const { return valStr(); };
266266

267267
WsjcppYamlCursor operator[](int idx) const;
268268
WsjcppYamlCursor operator[](const std::string &sName) const;
269+
WsjcppYamlCursor operator[](const char *sName) const;
269270

270271
WsjcppYamlCursor& operator=(const char *sVal);
271272
WsjcppYamlCursor& operator=(const std::string &sVal);

0 commit comments

Comments
 (0)