diff --git a/iterator.cpp b/iterator.cpp index 074e5eed95..a9161cd892 100644 --- a/iterator.cpp +++ b/iterator.cpp @@ -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) diff --git a/main.cpp b/main.cpp index 12de0fbd10..3639503c5a 100644 --- a/main.cpp +++ b/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"; diff --git a/node.h b/node.h index bbfcfe9f67..dc2d60306f 100644 --- a/node.h +++ b/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(); diff --git a/test.yaml b/test.yaml index 340878ef1e..f18974185d 100644 --- a/test.yaml +++ b/test.yaml @@ -1,8 +1,4 @@ --- -- name: Jesse - age: 23 - school: University of Illinois -- name: Naftali - age: 21 - school: Rhode Island School of Design +- [1, 2, 3] +- [2, 4, 6] ... \ No newline at end of file