YamlDocWriter simplification

This commit is contained in:
Jack Andersen 2016-02-29 16:57:53 -10:00
parent ca0ff04340
commit b317ac9d9f
1 changed files with 21 additions and 38 deletions

View File

@ -815,26 +815,33 @@ public:
yaml_emitter_t* getEmitter() {return &m_emitter;}
bool open()
bool finish()
{
if (!yaml_emitter_open(&m_emitter))
{
HandleYAMLEmitterError(&m_emitter);
return false;
}
return true;
}
yaml_event_t event;
if (!yaml_emitter_open(&m_emitter))
goto err;
event.type = YAML_DOCUMENT_START_EVENT;
event.data.document_start.implicit = true;
if (!yaml_emitter_emit(&m_emitter, &event))
goto err;
if (!RecursiveFinish(&m_emitter, m_rootNode))
return false;
event.type = YAML_DOCUMENT_END_EVENT;
event.data.document_end.implicit = true;
if (!yaml_emitter_emit(&m_emitter, &event))
goto err;
bool close()
{
if (!yaml_emitter_close(&m_emitter) ||
!yaml_emitter_flush(&m_emitter))
{
goto err;
return true;
err:
HandleYAMLEmitterError(&m_emitter);
return false;
}
return true;
}
inline YAMLNode* getCurNode() const {return m_subStack.empty() ? nullptr : m_subStack.back();}
@ -960,24 +967,6 @@ public:
leaveSubVector();
}
bool finish()
{
yaml_event_t event = {YAML_DOCUMENT_START_EVENT};
event.data.document_start.implicit = true;
if (!yaml_emitter_emit(&m_emitter, &event))
goto err;
if (!RecursiveFinish(&m_emitter, m_rootNode))
return false;
event.type = YAML_DOCUMENT_END_EVENT;
event.data.document_end.implicit = true;
if (!yaml_emitter_emit(&m_emitter, &event))
goto err;
return true;
err:
HandleYAMLEmitterError(&m_emitter);
return false;
}
template <typename INTYPE>
void writeVal(const char* name, const INTYPE& val)
{
@ -1156,12 +1145,9 @@ struct DNAYaml : DNA<DNAE>
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
if (!docWriter.open())
return std::string();
write(docWriter);
if (!docWriter.finish())
return std::string();
docWriter.close();
return res;
}
@ -1201,12 +1187,9 @@ struct DNAYaml : DNA<DNAE>
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
yaml_emitter_set_width(docWriter.getEmitter(), -1);
if (!docWriter.open())
return false;
write(docWriter);
if (!docWriter.finish())
return false;
docWriter.close();
return true;
}