parse.cpp
Go to the documentation of this file.
1 #include "yaml-cpp-pm/yaml.h"
3 #include <fstream>
4 #include <iostream>
5 #include <vector>
6 
7 struct Params {
8  bool hasFile;
10 };
11 
12 Params ParseArgs(int argc, char **argv) {
13  Params p;
14 
15  std::vector<std::string> args(argv + 1, argv + argc);
16 
17  return p;
18 }
19 
21 {
22 public:
23  virtual void OnDocumentStart(const YAML_PM::Mark&) {}
24  virtual void OnDocumentEnd() {}
25 
26  virtual void OnNull(const YAML_PM::Mark&, YAML_PM::anchor_t) {}
27  virtual void OnAlias(const YAML_PM::Mark&, YAML_PM::anchor_t) {}
28  virtual void OnScalar(const YAML_PM::Mark&, const std::string&, YAML_PM::anchor_t, const std::string&) {}
29 
31  virtual void OnSequenceEnd() {}
32 
33  virtual void OnMapStart(const YAML_PM::Mark&, const std::string&, YAML_PM::anchor_t) {}
34  virtual void OnMapEnd() {}
35 };
36 
37 void parse(std::istream& input)
38 {
39  try {
40  YAML_PM::Parser parser(input);
41  YAML_PM::Node doc;
42  while(parser.GetNextDocument(doc)) {
43  YAML_PM::Emitter emitter;
44  emitter << doc;
45  std::cout << emitter.c_str() << "\n";
46  }
47  } catch(const YAML_PM::Exception& e) {
48  std::cerr << e.what() << "\n";
49  }
50 }
51 
52 int main(int argc, char **argv)
53 {
54  Params p = ParseArgs(argc, argv);
55 
56  if(argc > 1) {
57  std::ifstream fin;
58  fin.open(argv[1]);
59  parse(fin);
60  } else {
61  parse(std::cin);
62  }
63 
64  return 0;
65 }
std::size_t anchor_t
Definition: anchor.h:12
Params ParseArgs(int argc, char **argv)
Definition: parse.cpp:12
virtual void OnDocumentStart(const YAML_PM::Mark &)
Definition: parse.cpp:23
::std::string string
Definition: gtest.h:1979
virtual void OnNull(const YAML_PM::Mark &, YAML_PM::anchor_t)
Definition: parse.cpp:26
Definition: parse.cpp:7
bool hasFile
Definition: parse.cpp:8
bool GetNextDocument(Node &document)
Definition: parser.cpp:61
virtual void OnMapStart(const YAML_PM::Mark &, const std::string &, YAML_PM::anchor_t)
Definition: parse.cpp:33
virtual void OnSequenceStart(const YAML_PM::Mark &, const std::string &, YAML_PM::anchor_t)
Definition: parse.cpp:30
std::string fileName
Definition: parse.cpp:9
const char * c_str() const
Definition: emitter.cpp:18
virtual void OnDocumentEnd()
Definition: parse.cpp:24
virtual void OnSequenceEnd()
Definition: parse.cpp:31
virtual void OnScalar(const YAML_PM::Mark &, const std::string &, YAML_PM::anchor_t, const std::string &)
Definition: parse.cpp:28
int main(int argc, char **argv)
Definition: parse.cpp:52
virtual void OnMapEnd()
Definition: parse.cpp:34
virtual void OnAlias(const YAML_PM::Mark &, YAML_PM::anchor_t)
Definition: parse.cpp:27
void parse(std::istream &input)
Definition: parse.cpp:37


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:03