scide: implement selectionLength for openDocument
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / src / emitfromevents.cpp
blob49fc10b29e304653c79b834905c4e28291c6171a
1 #include "yaml-cpp/emitfromevents.h"
2 #include "yaml-cpp/emitter.h"
3 #include "yaml-cpp/null.h"
4 #include <cassert>
5 #include <sstream>
7 namespace {
8 std::string ToString(YAML::anchor_t anchor) {
9 std::stringstream stream;
10 stream << anchor;
11 return stream.str();
15 namespace YAML
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)
31 BeginNode();
32 EmitProps("", anchor);
33 m_emitter << Null;
36 void EmitFromEvents::OnAlias(const Mark&, anchor_t anchor)
38 BeginNode();
39 m_emitter << Alias(ToString(anchor));
42 void EmitFromEvents::OnScalar(const Mark&, const std::string& tag, anchor_t anchor, const std::string& value)
44 BeginNode();
45 EmitProps(tag, anchor);
46 m_emitter << value;
49 void EmitFromEvents::OnSequenceStart(const Mark&, const std::string& tag, anchor_t anchor)
51 BeginNode();
52 EmitProps(tag, anchor);
53 m_emitter << BeginSeq;
54 m_stateStack.push(State::WaitingForSequenceEntry);
57 void EmitFromEvents::OnSequenceEnd()
59 m_emitter << EndSeq;
60 assert(m_stateStack.top() == State::WaitingForSequenceEntry);
61 m_stateStack.pop();
64 void EmitFromEvents::OnMapStart(const Mark&, const std::string& tag, anchor_t anchor)
66 BeginNode();
67 EmitProps(tag, anchor);
68 m_emitter << BeginMap;
69 m_stateStack.push(State::WaitingForKey);
72 void EmitFromEvents::OnMapEnd()
74 m_emitter << EndMap;
75 assert(m_stateStack.top() == State::WaitingForKey);
76 m_stateStack.pop();
79 void EmitFromEvents::BeginNode()
81 if(m_stateStack.empty())
82 return;
84 switch(m_stateStack.top()) {
85 case State::WaitingForKey:
86 m_emitter << Key;
87 m_stateStack.top() = State::WaitingForValue;
88 break;
89 case State::WaitingForValue:
90 m_emitter << Value;
91 m_stateStack.top() = State::WaitingForKey;
92 break;
93 default:
94 break;
98 void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor)
100 if(!tag.empty() && tag != "?")
101 m_emitter << VerbatimTag(tag);
102 if(anchor)
103 m_emitter << Anchor(ToString(anchor));