mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Overloaded the iterator's -> operator.
This commit is contained in:
@@ -37,6 +37,14 @@ namespace YAML
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
const Node *Node::Iterator::operator -> ()
|
||||
{
|
||||
if(type == IT_SEQ)
|
||||
return &**seqIter;
|
||||
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
const Node& Node::Iterator::first()
|
||||
{
|
||||
if(type == IT_MAP)
|
||||
|
18
main.cpp
18
main.cpp
@@ -18,17 +18,13 @@ int main()
|
||||
|
||||
const YAML::Node& root = doc.GetRoot();
|
||||
for(YAML::Node::Iterator it=root.begin();it!=root.end();++it) {
|
||||
std::string name;
|
||||
(*it)["name"] >> name;
|
||||
std::cout << "Name: " << name << std::endl;
|
||||
|
||||
int age;
|
||||
(*it)["age"] >> age;
|
||||
std::cout << "Age: " << age << std::endl;
|
||||
|
||||
std::string school;
|
||||
(*it)["school"] >> school;
|
||||
std::cout << "School: " << school << std::endl;
|
||||
std::cout << "Sequence:";
|
||||
for(YAML::Node::Iterator jt=it->begin();jt!=it->end();++jt) {
|
||||
int value;
|
||||
*jt >> value;
|
||||
std::cout << " " << value;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
} catch(YAML::Exception& e) {
|
||||
std::cout << "Error parsing the yaml!\n";
|
||||
|
1
node.h
1
node.h
@@ -27,6 +27,7 @@ namespace YAML
|
||||
friend bool operator != (const Iterator& it, const Iterator& jt);
|
||||
Iterator& operator ++ ();
|
||||
const Node& operator * ();
|
||||
const Node *operator -> ();
|
||||
const Node& first();
|
||||
const Node& second();
|
||||
|
||||
|
Reference in New Issue
Block a user