1 #include "yaml-cpp/emitfromevents.h"
2 #include "yaml-cpp/emitter.h"
3 #include "yaml-cpp/null.h"
8 std::string
ToString(YAML::anchor_t anchor
) {
9 std::stringstream stream
;
17 EmitFromEvents::EmitFromEvents(Emitter
& emitter
): m_emitter(emitter
)
21 void EmitFromEvents::OnDocumentStart(const Mark
&)
25 void EmitFromEvents::OnDocumentEnd()
29 void EmitFromEvents::OnNull(const Mark
&, anchor_t anchor
)
32 EmitProps("", anchor
);
36 void EmitFromEvents::OnAlias(const Mark
&, anchor_t anchor
)
39 m_emitter
<< Alias(ToString(anchor
));
42 void EmitFromEvents::OnScalar(const Mark
&, const std::string
& tag
, anchor_t anchor
, const std::string
& value
)
45 EmitProps(tag
, anchor
);
49 void EmitFromEvents::OnSequenceStart(const Mark
&, const std::string
& tag
, anchor_t anchor
)
52 EmitProps(tag
, anchor
);
53 m_emitter
<< BeginSeq
;
54 m_stateStack
.push(State::WaitingForSequenceEntry
);
57 void EmitFromEvents::OnSequenceEnd()
60 assert(m_stateStack
.top() == State::WaitingForSequenceEntry
);
64 void EmitFromEvents::OnMapStart(const Mark
&, const std::string
& tag
, anchor_t anchor
)
67 EmitProps(tag
, anchor
);
68 m_emitter
<< BeginMap
;
69 m_stateStack
.push(State::WaitingForKey
);
72 void EmitFromEvents::OnMapEnd()
75 assert(m_stateStack
.top() == State::WaitingForKey
);
79 void EmitFromEvents::BeginNode()
81 if(m_stateStack
.empty())
84 switch(m_stateStack
.top()) {
85 case State::WaitingForKey
:
87 m_stateStack
.top() = State::WaitingForValue
;
89 case State::WaitingForValue
:
91 m_stateStack
.top() = State::WaitingForKey
;
98 void EmitFromEvents::EmitProps(const std::string
& tag
, anchor_t anchor
)
100 if(!tag
.empty() && tag
!= "?")
101 m_emitter
<< VerbatimTag(tag
);
103 m_emitter
<< Anchor(ToString(anchor
));