Added an iterator class that can iterate through both sequence and map nodes.

This commit is contained in:
Jesse Beder 2008-07-02 01:22:39 +00:00
parent f7358701f2
commit d56b54b34f
16 changed files with 393 additions and 105 deletions

View file

@ -1,18 +1,39 @@
#include "parser.h"
#include "node.h"
#include "exceptions.h"
#include <fstream>
#include <iostream>
int main()
{
std::ifstream fin("test.yaml");
YAML::Parser parser(fin);
YAML::Document doc;
while(parser) {
std::cout << "---\n";
try {
YAML::Parser parser(fin);
if(!parser)
return 0;
YAML::Document doc;
parser.GetNextDocument(doc);
std::cout << doc;
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;
}
} catch(YAML::Exception& e) {
std::cout << "Error parsing the yaml!\n";
}
getchar();
return 0;