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 }
YAML_PM::EmitFromEvents::OnScalar
virtual void OnScalar(const Mark &mark, const std::string &tag, anchor_t anchor, const std::string &value)
Definition: emitfromevents.cpp:42
YAML_PM::VerbatimTag
_Tag VerbatimTag(const std::string content)
Definition: emittermanip.h:104
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::Null
YAML_CPP_API _Null Null
Definition: null.cpp:6
YAML_PM::EmitFromEvents::OnSequenceEnd
virtual void OnSequenceEnd()
Definition: emitfromevents.cpp:57
YAML_PM::EmitFromEvents::OnDocumentEnd
virtual void OnDocumentEnd()
Definition: emitfromevents.cpp:25
testing::internal::string
::std::string string
Definition: gtest.h:1979
YAML_PM::BeginMap
@ BeginMap
Definition: emittermanip.h:55
YAML_PM::EndSeq
@ EndSeq
Definition: emittermanip.h:50
null.h
YAML_PM::EmitFromEvents::State::WaitingForKey
@ WaitingForKey
Definition: emitfromevents.h:40
YAML_PM::EmitFromEvents::OnDocumentStart
virtual void OnDocumentStart(const Mark &mark)
Definition: emitfromevents.cpp:21
YAML_PM::EmitFromEvents::State::WaitingForValue
@ WaitingForValue
Definition: emitfromevents.h:40
YAML_PM::EmitFromEvents::m_emitter
Emitter & m_emitter
Definition: emitfromevents.h:38
YAML_PM::Alias
_Alias Alias(const std::string content)
Definition: emittermanip.h:79
YAML_PM::Value
@ Value
Definition: emittermanip.h:58
YAML_PM::EmitFromEvents::OnMapEnd
virtual void OnMapEnd()
Definition: emitfromevents.cpp:72
YAML_PM::EmitFromEvents::OnMapStart
virtual void OnMapStart(const Mark &mark, const std::string &tag, anchor_t anchor)
Definition: emitfromevents.cpp:64
YAML_PM::EmitFromEvents::State::WaitingForSequenceEntry
@ WaitingForSequenceEntry
Definition: emitfromevents.h:40
YAML_PM::EmitFromEvents::OnSequenceStart
virtual void OnSequenceStart(const Mark &mark, const std::string &tag, anchor_t anchor)
Definition: emitfromevents.cpp:49
YAML_PM::EmitFromEvents::EmitFromEvents
EmitFromEvents(Emitter &emitter)
Definition: emitfromevents.cpp:17
emitfromevents.h
YAML_PM::Emitter
Definition: emitter.h:23
YAML_PM::Anchor
_Anchor Anchor(const std::string content)
Definition: emittermanip.h:88
YAML_PM::Mark
Definition: mark.h:13
YAML_PM::EmitFromEvents::EmitProps
void EmitProps(const std::string &tag, anchor_t anchor)
Definition: emitfromevents.cpp:98
YAML_PM::BeginSeq
@ BeginSeq
Definition: emittermanip.h:49
YAML_PM::EmitFromEvents::OnNull
virtual void OnNull(const Mark &mark, anchor_t anchor)
Definition: emitfromevents.cpp:29
YAML_PM::EmitFromEvents::OnAlias
virtual void OnAlias(const Mark &mark, anchor_t anchor)
Definition: emitfromevents.cpp:36
YAML_PM::EmitFromEvents::m_stateStack
std::stack< State::value > m_stateStack
Definition: emitfromevents.h:41
YAML_PM::anchor_t
std::size_t anchor_t
Definition: anchor.h:12
YAML_PM::EmitFromEvents::BeginNode
void BeginNode()
Definition: emitfromevents.cpp:79
emitter.h
YAML_PM::EndMap
@ EndMap
Definition: emittermanip.h:56
YAML_PM::Key
@ Key
Definition: emittermanip.h:57


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:57