emitfromevents.cpp
Go to the documentation of this file.
2 #include "yaml-cpp-pm/emitter.h"
3 #include "yaml-cpp-pm/null.h"
4 #include <cassert>
5 #include <sstream>
6 
7 namespace {
8  std::string ToString(YAML_PM::anchor_t anchor) {
9  std::stringstream stream;
10  stream << anchor;
11  return stream.str();
12  }
13 }
14 
15 namespace YAML_PM
16 {
17  EmitFromEvents::EmitFromEvents(Emitter& emitter): m_emitter(emitter)
18  {
19  }
20 
22  {
23  }
24 
26  {
27  }
28 
29  void EmitFromEvents::OnNull(const Mark&, anchor_t anchor)
30  {
31  BeginNode();
32  EmitProps("", anchor);
33  m_emitter << Null;
34  }
35 
36  void EmitFromEvents::OnAlias(const Mark&, anchor_t anchor)
37  {
38  BeginNode();
39  m_emitter << Alias(ToString(anchor));
40  }
41 
42  void EmitFromEvents::OnScalar(const Mark&, const std::string& tag, anchor_t anchor, const std::string& value)
43  {
44  BeginNode();
45  EmitProps(tag, anchor);
46  m_emitter << value;
47  }
48 
49  void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag, anchor_t anchor)
50  {
51  BeginNode();
52  EmitProps(tag, anchor);
55  }
56 
58  {
59  m_emitter << EndSeq;
61  m_stateStack.pop();
62  }
63 
64  void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag, anchor_t anchor)
65  {
66  BeginNode();
67  EmitProps(tag, anchor);
70  }
71 
73  {
74  m_emitter << EndMap;
75  assert(m_stateStack.top() == State::WaitingForKey);
76  m_stateStack.pop();
77  }
78 
80  {
81  if(m_stateStack.empty())
82  return;
83 
84  switch(m_stateStack.top()) {
86  m_emitter << Key;
88  break;
90  m_emitter << Value;
92  break;
93  default:
94  break;
95  }
96  }
97 
99  {
100  if(!tag.empty() && tag != "?")
101  m_emitter << VerbatimTag(tag);
102  if(anchor)
103  m_emitter << Anchor(ToString(anchor));
104  }
105 }
std::size_t anchor_t
Definition: anchor.h:12
virtual void OnDocumentEnd()
virtual void OnMapStart(const Mark &mark, const std::string &tag, anchor_t anchor)
::std::string string
Definition: gtest.h:1979
EmitFromEvents(Emitter &emitter)
_Alias Alias(const std::string content)
Definition: emittermanip.h:79
void EmitProps(const std::string &tag, anchor_t anchor)
virtual void OnScalar(const Mark &mark, const std::string &tag, anchor_t anchor, const std::string &value)
_Anchor Anchor(const std::string content)
Definition: emittermanip.h:88
YAML_CPP_API _Null Null
Definition: null.cpp:6
std::stack< State::value > m_stateStack
virtual void OnSequenceEnd()
virtual void OnDocumentStart(const Mark &mark)
virtual void OnAlias(const Mark &mark, anchor_t anchor)
_Tag VerbatimTag(const std::string content)
Definition: emittermanip.h:104
virtual void OnNull(const Mark &mark, anchor_t anchor)
virtual void OnSequenceStart(const Mark &mark, const std::string &tag, anchor_t anchor)


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:36:30