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 }
NullEventHandler::OnSequenceEnd
virtual void OnSequenceEnd()
Definition: parse.cpp:31
Params::fileName
std::string fileName
Definition: parse.cpp:9
Params::hasFile
bool hasFile
Definition: parse.cpp:8
YAML_PM::EventHandler
Definition: eventhandler.h:15
NullEventHandler::OnDocumentEnd
virtual void OnDocumentEnd()
Definition: parse.cpp:24
YAML_PM::Emitter::c_str
const char * c_str() const
Definition: emitter.cpp:18
ParseArgs
Params ParseArgs(int argc, char **argv)
Definition: parse.cpp:12
eventhandler.h
testing::internal::string
::std::string string
Definition: gtest.h:1979
Params
Definition: parse.cpp:7
NullEventHandler::OnScalar
virtual void OnScalar(const YAML_PM::Mark &, const std::string &, YAML_PM::anchor_t, const std::string &)
Definition: parse.cpp:28
NullEventHandler::OnMapEnd
virtual void OnMapEnd()
Definition: parse.cpp:34
NullEventHandler
Definition: parse.cpp:20
YAML_PM::Parser::GetNextDocument
bool GetNextDocument(Node &document)
Definition: parser.cpp:61
yaml.h
YAML_PM::Parser
Definition: parser.h:23
NullEventHandler::OnAlias
virtual void OnAlias(const YAML_PM::Mark &, YAML_PM::anchor_t)
Definition: parse.cpp:27
YAML_PM::Node
Definition: node.h:33
YAML_PM::Emitter
Definition: emitter.h:23
YAML_PM::Mark
Definition: mark.h:13
YAML_PM::Exception
Definition: exceptions.h:93
main
int main(int argc, char **argv)
Definition: parse.cpp:52
NullEventHandler::OnDocumentStart
virtual void OnDocumentStart(const YAML_PM::Mark &)
Definition: parse.cpp:23
YAML_PM::anchor_t
std::size_t anchor_t
Definition: anchor.h:12
NullEventHandler::OnNull
virtual void OnNull(const YAML_PM::Mark &, YAML_PM::anchor_t)
Definition: parse.cpp:26
parse
void parse(std::istream &input)
Definition: parse.cpp:37
NullEventHandler::OnMapStart
virtual void OnMapStart(const YAML_PM::Mark &, const std::string &, YAML_PM::anchor_t)
Definition: parse.cpp:33
NullEventHandler::OnSequenceStart
virtual void OnSequenceStart(const YAML_PM::Mark &, const std::string &, YAML_PM::anchor_t)
Definition: parse.cpp:30


mp2p_icp
Author(s):
autogenerated on Thu Dec 26 2024 03:48:12