parse.cpp
Go to the documentation of this file.
00001 #include "yaml-cpp-pm/yaml.h"
00002 #include "yaml-cpp-pm/eventhandler.h"
00003 #include <fstream>
00004 #include <iostream>
00005 #include <vector>
00006 
00007 struct Params {
00008         bool hasFile;
00009         std::string fileName;
00010 };
00011 
00012 Params ParseArgs(int argc, char **argv) {
00013         Params p;
00014 
00015         std::vector<std::string> args(argv + 1, argv + argc);
00016         
00017         return p;
00018 }
00019 
00020 class NullEventHandler: public YAML_PM::EventHandler
00021 {
00022 public:
00023         virtual void OnDocumentStart(const YAML_PM::Mark&) {}
00024         virtual void OnDocumentEnd() {}
00025         
00026         virtual void OnNull(const YAML_PM::Mark&, YAML_PM::anchor_t) {}
00027         virtual void OnAlias(const YAML_PM::Mark&, YAML_PM::anchor_t) {}
00028         virtual void OnScalar(const YAML_PM::Mark&, const std::string&, YAML_PM::anchor_t, const std::string&) {}
00029         
00030         virtual void OnSequenceStart(const YAML_PM::Mark&, const std::string&, YAML_PM::anchor_t) {}
00031         virtual void OnSequenceEnd() {}
00032         
00033         virtual void OnMapStart(const YAML_PM::Mark&, const std::string&, YAML_PM::anchor_t) {}
00034         virtual void OnMapEnd() {}
00035 };
00036 
00037 void parse(std::istream& input)
00038 {
00039         try {
00040                 YAML_PM::Parser parser(input);
00041                 YAML_PM::Node doc;
00042                 while(parser.GetNextDocument(doc)) {
00043                         YAML_PM::Emitter emitter;
00044                         emitter << doc;
00045                         std::cout << emitter.c_str() << "\n";
00046                 }
00047         } catch(const YAML_PM::Exception& e) {
00048                 std::cerr << e.what() << "\n";
00049         }
00050 }
00051 
00052 int main(int argc, char **argv)
00053 {
00054         Params p = ParseArgs(argc, argv);
00055 
00056         if(argc > 1) {
00057                 std::ifstream fin;
00058                 fin.open(argv[1]);
00059                 parse(fin);
00060         } else {
00061                 parse(std::cin);
00062         }
00063 
00064         return 0;
00065 }


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:42