From 65d80ebc116db557c83dd5428cbb546dd8a08be1 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Mon, 21 May 2012 17:06:12 -0500 Subject: [PATCH] Started prepare node --- include/yaml-cpp/emitter.h | 7 +++++ src/emitter.cpp | 61 ++++++++++++++++++++++++++++++++++++++ util/sandbox.cpp | 4 --- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/include/yaml-cpp/emitter.h b/include/yaml-cpp/emitter.h index ae88751..4e329cc 100644 --- a/include/yaml-cpp/emitter.h +++ b/include/yaml-cpp/emitter.h @@ -85,6 +85,13 @@ namespace YAML void EmitKindTag(); void EmitTag(bool verbatim, const _Tag& tag); + void PrepareNode(); + void PrepareTopNode(); + void FlowSeqPrepareNode(); + void BlockSeqPrepareNode(); + void FlowMapPrepareNode(); + void BlockMapPrepareNode(); + const char *ComputeFullBoolName(bool b) const; bool CanEmitNewline() const; diff --git a/src/emitter.cpp b/src/emitter.cpp index d3cc8f0..6ef9d2a 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -210,6 +210,8 @@ namespace YAML if(!good()) return; + PrepareNode(); + m_pState->BeginGroup(GroupType::Seq); } @@ -228,6 +230,8 @@ namespace YAML if(!good()) return; + PrepareNode(); + m_pState->BeginGroup(GroupType::Map); } @@ -252,6 +256,61 @@ namespace YAML return false; } + // Put the stream in a state so we can simply write the next node + // E.g., if we're in a sequence, write the "- " + void Emitter::PrepareNode() + { + switch(m_pState->CurGroupType()) { + case GroupType::None: + PrepareTopNode(); + break; + case GroupType::Seq: + switch(m_pState->CurGroupFlowType()) { + case FlowType::Flow: + FlowSeqPrepareNode(); + break; + case FlowType::Block: + BlockSeqPrepareNode(); + break; + case FlowType::None: + assert(false); + } + break; + case GroupType::Map: + switch(m_pState->CurGroupFlowType()) { + case FlowType::Flow: + FlowMapPrepareNode(); + break; + case FlowType::Block: + BlockMapPrepareNode(); + break; + case FlowType::None: + assert(false); + } + break; + } + } + + void Emitter::PrepareTopNode() + { + } + + void Emitter::FlowSeqPrepareNode() + { + } + + void Emitter::BlockSeqPrepareNode() + { + } + + void Emitter::FlowMapPrepareNode() + { + } + + void Emitter::BlockMapPrepareNode() + { + } + // ******************************************************************************************* // overloads of Write @@ -260,6 +319,8 @@ namespace YAML if(!good()) return *this; + PrepareNode(); + m_pState->BeginScalar(); return *this; diff --git a/util/sandbox.cpp b/util/sandbox.cpp index 3f1fa3e..24504d1 100644 --- a/util/sandbox.cpp +++ b/util/sandbox.cpp @@ -4,11 +4,7 @@ int main() { YAML::Emitter out; - out << YAML::BeginDoc; - out << YAML::BeginSeq; out << "foo"; - out << YAML::EndSeq; - out << YAML::EndDoc; std::cout << out.c_str() << "\n"; return 0;