mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Switched the emitter state enums to scoped enums
This commit is contained in:
@@ -39,69 +39,69 @@ namespace YAML
|
|||||||
// global setters
|
// global setters
|
||||||
bool Emitter::SetOutputCharset(EMITTER_MANIP value)
|
bool Emitter::SetOutputCharset(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
return m_pState->SetOutputCharset(value, GLOBAL);
|
return m_pState->SetOutputCharset(value, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetStringFormat(EMITTER_MANIP value)
|
bool Emitter::SetStringFormat(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
return m_pState->SetStringFormat(value, GLOBAL);
|
return m_pState->SetStringFormat(value, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetBoolFormat(EMITTER_MANIP value)
|
bool Emitter::SetBoolFormat(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if(m_pState->SetBoolFormat(value, GLOBAL))
|
if(m_pState->SetBoolFormat(value, FmtScope::Global))
|
||||||
ok = true;
|
ok = true;
|
||||||
if(m_pState->SetBoolCaseFormat(value, GLOBAL))
|
if(m_pState->SetBoolCaseFormat(value, FmtScope::Global))
|
||||||
ok = true;
|
ok = true;
|
||||||
if(m_pState->SetBoolLengthFormat(value, GLOBAL))
|
if(m_pState->SetBoolLengthFormat(value, FmtScope::Global))
|
||||||
ok = true;
|
ok = true;
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetIntBase(EMITTER_MANIP value)
|
bool Emitter::SetIntBase(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
return m_pState->SetIntFormat(value, GLOBAL);
|
return m_pState->SetIntFormat(value, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetSeqFormat(EMITTER_MANIP value)
|
bool Emitter::SetSeqFormat(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
return m_pState->SetFlowType(GT_SEQ, value, GLOBAL);
|
return m_pState->SetFlowType(GroupType::Seq, value, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetMapFormat(EMITTER_MANIP value)
|
bool Emitter::SetMapFormat(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if(m_pState->SetFlowType(GT_MAP, value, GLOBAL))
|
if(m_pState->SetFlowType(GroupType::Map, value, FmtScope::Global))
|
||||||
ok = true;
|
ok = true;
|
||||||
if(m_pState->SetMapKeyFormat(value, GLOBAL))
|
if(m_pState->SetMapKeyFormat(value, FmtScope::Global))
|
||||||
ok = true;
|
ok = true;
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetIndent(unsigned n)
|
bool Emitter::SetIndent(unsigned n)
|
||||||
{
|
{
|
||||||
return m_pState->SetIndent(n, GLOBAL);
|
return m_pState->SetIndent(n, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetPreCommentIndent(unsigned n)
|
bool Emitter::SetPreCommentIndent(unsigned n)
|
||||||
{
|
{
|
||||||
return m_pState->SetPreCommentIndent(n, GLOBAL);
|
return m_pState->SetPreCommentIndent(n, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetPostCommentIndent(unsigned n)
|
bool Emitter::SetPostCommentIndent(unsigned n)
|
||||||
{
|
{
|
||||||
return m_pState->SetPostCommentIndent(n, GLOBAL);
|
return m_pState->SetPostCommentIndent(n, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetFloatPrecision(unsigned n)
|
bool Emitter::SetFloatPrecision(unsigned n)
|
||||||
{
|
{
|
||||||
return m_pState->SetFloatPrecision(n, GLOBAL);
|
return m_pState->SetFloatPrecision(n, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emitter::SetDoublePrecision(unsigned n)
|
bool Emitter::SetDoublePrecision(unsigned n)
|
||||||
{
|
{
|
||||||
return m_pState->SetDoublePrecision(n, GLOBAL);
|
return m_pState->SetDoublePrecision(n, FmtScope::Global);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLocalValue
|
// SetLocalValue
|
||||||
@@ -151,16 +151,16 @@ namespace YAML
|
|||||||
|
|
||||||
Emitter& Emitter::SetLocalIndent(const _Indent& indent)
|
Emitter& Emitter::SetLocalIndent(const _Indent& indent)
|
||||||
{
|
{
|
||||||
m_pState->SetIndent(indent.value, LOCAL);
|
m_pState->SetIndent(indent.value, FmtScope::Local);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Emitter& Emitter::SetLocalPrecision(const _Precision& precision)
|
Emitter& Emitter::SetLocalPrecision(const _Precision& precision)
|
||||||
{
|
{
|
||||||
if(precision.floatPrecision >= 0)
|
if(precision.floatPrecision >= 0)
|
||||||
m_pState->SetFloatPrecision(precision.floatPrecision, LOCAL);
|
m_pState->SetFloatPrecision(precision.floatPrecision, FmtScope::Local);
|
||||||
if(precision.doublePrecision >= 0)
|
if(precision.doublePrecision >= 0)
|
||||||
m_pState->SetDoublePrecision(precision.doublePrecision, LOCAL);
|
m_pState->SetDoublePrecision(precision.doublePrecision, FmtScope::Local);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +400,7 @@ namespace YAML
|
|||||||
PreAtomicWrite();
|
PreAtomicWrite();
|
||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
EMITTER_MANIP flowType = m_pState->GetFlowType(GT_SEQ);
|
EMITTER_MANIP flowType = m_pState->GetFlowType(GroupType::Seq);
|
||||||
if(flowType == Block) {
|
if(flowType == Block) {
|
||||||
if(curState == ES_WRITING_BLOCK_SEQ_ENTRY ||
|
if(curState == ES_WRITING_BLOCK_SEQ_ENTRY ||
|
||||||
curState == ES_WRITING_BLOCK_MAP_KEY || curState == ES_WRITING_BLOCK_MAP_VALUE ||
|
curState == ES_WRITING_BLOCK_MAP_KEY || curState == ES_WRITING_BLOCK_MAP_VALUE ||
|
||||||
@@ -419,7 +419,7 @@ namespace YAML
|
|||||||
} else
|
} else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
m_pState->BeginGroup(GT_SEQ);
|
m_pState->BeginGroup(GroupType::Seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmitEndSeq
|
// EmitEndSeq
|
||||||
@@ -428,12 +428,12 @@ namespace YAML
|
|||||||
if(!good())
|
if(!good())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(m_pState->GetCurGroupType() != GT_SEQ)
|
if(m_pState->GetCurGroupType() != GroupType::Seq)
|
||||||
return m_pState->SetError(ErrorMsg::UNEXPECTED_END_SEQ);
|
return m_pState->SetError(ErrorMsg::UNEXPECTED_END_SEQ);
|
||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FlowType::value flowType = m_pState->GetCurGroupFlowType();
|
||||||
if(flowType == FT_BLOCK) {
|
if(flowType == FlowType::Block) {
|
||||||
// Note: block sequences are *not* allowed to be empty, but we convert it
|
// Note: block sequences are *not* allowed to be empty, but we convert it
|
||||||
// to a flow sequence if it is
|
// to a flow sequence if it is
|
||||||
assert(curState == ES_DONE_WITH_BLOCK_SEQ_ENTRY || curState == ES_WAITING_FOR_BLOCK_SEQ_ENTRY);
|
assert(curState == ES_DONE_WITH_BLOCK_SEQ_ENTRY || curState == ES_WAITING_FOR_BLOCK_SEQ_ENTRY);
|
||||||
@@ -445,7 +445,7 @@ namespace YAML
|
|||||||
|
|
||||||
m_stream << "[]";
|
m_stream << "[]";
|
||||||
}
|
}
|
||||||
} else if(flowType == FT_FLOW) {
|
} else if(flowType == FlowType::Flow) {
|
||||||
// Note: flow sequences are allowed to be empty
|
// Note: flow sequences are allowed to be empty
|
||||||
assert(curState == ES_DONE_WITH_FLOW_SEQ_ENTRY || curState == ES_WAITING_FOR_FLOW_SEQ_ENTRY);
|
assert(curState == ES_DONE_WITH_FLOW_SEQ_ENTRY || curState == ES_WAITING_FOR_FLOW_SEQ_ENTRY);
|
||||||
m_stream << "]";
|
m_stream << "]";
|
||||||
@@ -453,7 +453,7 @@ namespace YAML
|
|||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
m_pState->PopState();
|
m_pState->PopState();
|
||||||
m_pState->EndGroup(GT_SEQ);
|
m_pState->EndGroup(GroupType::Seq);
|
||||||
|
|
||||||
PostAtomicWrite();
|
PostAtomicWrite();
|
||||||
}
|
}
|
||||||
@@ -470,7 +470,7 @@ namespace YAML
|
|||||||
PreAtomicWrite();
|
PreAtomicWrite();
|
||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
EMITTER_MANIP flowType = m_pState->GetFlowType(GT_MAP);
|
EMITTER_MANIP flowType = m_pState->GetFlowType(GroupType::Map);
|
||||||
if(flowType == Block) {
|
if(flowType == Block) {
|
||||||
if(curState == ES_WRITING_BLOCK_SEQ_ENTRY ||
|
if(curState == ES_WRITING_BLOCK_SEQ_ENTRY ||
|
||||||
curState == ES_WRITING_BLOCK_MAP_KEY || curState == ES_WRITING_BLOCK_MAP_VALUE ||
|
curState == ES_WRITING_BLOCK_MAP_KEY || curState == ES_WRITING_BLOCK_MAP_VALUE ||
|
||||||
@@ -489,7 +489,7 @@ namespace YAML
|
|||||||
} else
|
} else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
m_pState->BeginGroup(GT_MAP);
|
m_pState->BeginGroup(GroupType::Map);
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmitEndMap
|
// EmitEndMap
|
||||||
@@ -498,12 +498,12 @@ namespace YAML
|
|||||||
if(!good())
|
if(!good())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(m_pState->GetCurGroupType() != GT_MAP)
|
if(m_pState->GetCurGroupType() != GroupType::Map)
|
||||||
return m_pState->SetError(ErrorMsg::UNEXPECTED_END_MAP);
|
return m_pState->SetError(ErrorMsg::UNEXPECTED_END_MAP);
|
||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FlowType::value flowType = m_pState->GetCurGroupFlowType();
|
||||||
if(flowType == FT_BLOCK) {
|
if(flowType == FlowType::Block) {
|
||||||
// Note: block sequences are *not* allowed to be empty, but we convert it
|
// Note: block sequences are *not* allowed to be empty, but we convert it
|
||||||
// to a flow sequence if it is
|
// to a flow sequence if it is
|
||||||
assert(curState == ES_DONE_WITH_BLOCK_MAP_VALUE || curState == ES_WAITING_FOR_BLOCK_MAP_ENTRY);
|
assert(curState == ES_DONE_WITH_BLOCK_MAP_VALUE || curState == ES_WAITING_FOR_BLOCK_MAP_ENTRY);
|
||||||
@@ -514,7 +514,7 @@ namespace YAML
|
|||||||
m_stream << IndentTo(curIndent);
|
m_stream << IndentTo(curIndent);
|
||||||
m_stream << "{}";
|
m_stream << "{}";
|
||||||
}
|
}
|
||||||
} else if(flowType == FT_FLOW) {
|
} else if(flowType == FlowType::Flow) {
|
||||||
// Note: flow maps are allowed to be empty
|
// Note: flow maps are allowed to be empty
|
||||||
assert(curState == ES_DONE_WITH_FLOW_MAP_VALUE || curState == ES_WAITING_FOR_FLOW_MAP_ENTRY);
|
assert(curState == ES_DONE_WITH_FLOW_MAP_VALUE || curState == ES_WAITING_FOR_FLOW_MAP_ENTRY);
|
||||||
EmitSeparationIfNecessary();
|
EmitSeparationIfNecessary();
|
||||||
@@ -523,7 +523,7 @@ namespace YAML
|
|||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
m_pState->PopState();
|
m_pState->PopState();
|
||||||
m_pState->EndGroup(GT_MAP);
|
m_pState->EndGroup(GroupType::Map);
|
||||||
|
|
||||||
PostAtomicWrite();
|
PostAtomicWrite();
|
||||||
}
|
}
|
||||||
@@ -535,19 +535,19 @@ namespace YAML
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FlowType::value flowType = m_pState->GetCurGroupFlowType();
|
||||||
if(curState != ES_WAITING_FOR_BLOCK_MAP_ENTRY && curState != ES_DONE_WITH_BLOCK_MAP_VALUE
|
if(curState != ES_WAITING_FOR_BLOCK_MAP_ENTRY && curState != ES_DONE_WITH_BLOCK_MAP_VALUE
|
||||||
&& curState != ES_WAITING_FOR_FLOW_MAP_ENTRY && curState != ES_DONE_WITH_FLOW_MAP_VALUE)
|
&& curState != ES_WAITING_FOR_FLOW_MAP_ENTRY && curState != ES_DONE_WITH_FLOW_MAP_VALUE)
|
||||||
return m_pState->SetError(ErrorMsg::UNEXPECTED_KEY_TOKEN);
|
return m_pState->SetError(ErrorMsg::UNEXPECTED_KEY_TOKEN);
|
||||||
|
|
||||||
if(flowType == FT_BLOCK) {
|
if(flowType == FlowType::Block) {
|
||||||
if(curState == ES_DONE_WITH_BLOCK_MAP_VALUE)
|
if(curState == ES_DONE_WITH_BLOCK_MAP_VALUE)
|
||||||
m_stream << '\n';
|
m_stream << '\n';
|
||||||
unsigned curIndent = m_pState->GetCurIndent();
|
unsigned curIndent = m_pState->GetCurIndent();
|
||||||
m_stream << IndentTo(curIndent);
|
m_stream << IndentTo(curIndent);
|
||||||
m_pState->UnsetSeparation();
|
m_pState->UnsetSeparation();
|
||||||
m_pState->SwitchState(ES_WAITING_FOR_BLOCK_MAP_KEY);
|
m_pState->SwitchState(ES_WAITING_FOR_BLOCK_MAP_KEY);
|
||||||
} else if(flowType == FT_FLOW) {
|
} else if(flowType == FlowType::Flow) {
|
||||||
EmitSeparationIfNecessary();
|
EmitSeparationIfNecessary();
|
||||||
if(curState == ES_DONE_WITH_FLOW_MAP_VALUE) {
|
if(curState == ES_DONE_WITH_FLOW_MAP_VALUE) {
|
||||||
m_stream << ',';
|
m_stream << ',';
|
||||||
@@ -572,11 +572,11 @@ namespace YAML
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FlowType::value flowType = m_pState->GetCurGroupFlowType();
|
||||||
if(curState != ES_DONE_WITH_BLOCK_MAP_KEY && curState != ES_DONE_WITH_FLOW_MAP_KEY)
|
if(curState != ES_DONE_WITH_BLOCK_MAP_KEY && curState != ES_DONE_WITH_FLOW_MAP_KEY)
|
||||||
return m_pState->SetError(ErrorMsg::UNEXPECTED_VALUE_TOKEN);
|
return m_pState->SetError(ErrorMsg::UNEXPECTED_VALUE_TOKEN);
|
||||||
|
|
||||||
if(flowType == FT_BLOCK) {
|
if(flowType == FlowType::Block) {
|
||||||
if(m_pState->CurrentlyInLongKey()) {
|
if(m_pState->CurrentlyInLongKey()) {
|
||||||
m_stream << '\n';
|
m_stream << '\n';
|
||||||
m_stream << IndentTo(m_pState->GetCurIndent());
|
m_stream << IndentTo(m_pState->GetCurIndent());
|
||||||
@@ -584,7 +584,7 @@ namespace YAML
|
|||||||
m_pState->RequireSoftSeparation();
|
m_pState->RequireSoftSeparation();
|
||||||
}
|
}
|
||||||
m_pState->SwitchState(ES_WAITING_FOR_BLOCK_MAP_VALUE);
|
m_pState->SwitchState(ES_WAITING_FOR_BLOCK_MAP_VALUE);
|
||||||
} else if(flowType == FT_FLOW) {
|
} else if(flowType == FlowType::Flow) {
|
||||||
m_pState->SwitchState(ES_WAITING_FOR_FLOW_MAP_VALUE);
|
m_pState->SwitchState(ES_WAITING_FOR_FLOW_MAP_VALUE);
|
||||||
} else
|
} else
|
||||||
assert(false);
|
assert(false);
|
||||||
@@ -604,8 +604,8 @@ namespace YAML
|
|||||||
|
|
||||||
bool Emitter::CanEmitNewline() const
|
bool Emitter::CanEmitNewline() const
|
||||||
{
|
{
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FlowType::value flowType = m_pState->GetCurGroupFlowType();
|
||||||
if(flowType == FT_BLOCK && m_pState->CurrentlyInLongKey())
|
if(flowType == FlowType::Block && m_pState->CurrentlyInLongKey())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
EMITTER_STATE curState = m_pState->GetCurState();
|
EMITTER_STATE curState = m_pState->GetCurState();
|
||||||
@@ -621,7 +621,7 @@ namespace YAML
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
// literal scalars must use long keys
|
// literal scalars must use long keys
|
||||||
if(m_pState->GetStringFormat() == Literal && m_pState->GetCurGroupFlowType() != FT_FLOW)
|
if(m_pState->GetStringFormat() == Literal && m_pState->GetCurGroupFlowType() != FlowType::Flow)
|
||||||
m_pState->StartLongKey();
|
m_pState->StartLongKey();
|
||||||
|
|
||||||
PreAtomicWrite();
|
PreAtomicWrite();
|
||||||
@@ -629,12 +629,12 @@ namespace YAML
|
|||||||
|
|
||||||
bool escapeNonAscii = m_pState->GetOutputCharset() == EscapeNonAscii;
|
bool escapeNonAscii = m_pState->GetOutputCharset() == EscapeNonAscii;
|
||||||
EMITTER_MANIP strFmt = m_pState->GetStringFormat();
|
EMITTER_MANIP strFmt = m_pState->GetStringFormat();
|
||||||
FLOW_TYPE flowType = m_pState->GetCurGroupFlowType();
|
FlowType::value flowType = m_pState->GetCurGroupFlowType();
|
||||||
unsigned curIndent = m_pState->GetCurIndent();
|
unsigned curIndent = m_pState->GetCurIndent();
|
||||||
|
|
||||||
switch(strFmt) {
|
switch(strFmt) {
|
||||||
case Auto:
|
case Auto:
|
||||||
Utils::WriteString(m_stream, str, flowType == FT_FLOW, escapeNonAscii);
|
Utils::WriteString(m_stream, str, flowType == FlowType::Flow, escapeNonAscii);
|
||||||
break;
|
break;
|
||||||
case SingleQuoted:
|
case SingleQuoted:
|
||||||
if(!Utils::WriteSingleQuotedString(m_stream, str)) {
|
if(!Utils::WriteSingleQuotedString(m_stream, str)) {
|
||||||
@@ -646,8 +646,8 @@ namespace YAML
|
|||||||
Utils::WriteDoubleQuotedString(m_stream, str, escapeNonAscii);
|
Utils::WriteDoubleQuotedString(m_stream, str, escapeNonAscii);
|
||||||
break;
|
break;
|
||||||
case Literal:
|
case Literal:
|
||||||
if(flowType == FT_FLOW)
|
if(flowType == FlowType::Flow)
|
||||||
Utils::WriteString(m_stream, str, flowType == FT_FLOW, escapeNonAscii);
|
Utils::WriteString(m_stream, str, flowType == FlowType::Flow, escapeNonAscii);
|
||||||
else
|
else
|
||||||
Utils::WriteLiteralString(m_stream, str, curIndent + m_pState->GetIndent());
|
Utils::WriteLiteralString(m_stream, str, curIndent + m_pState->GetIndent());
|
||||||
break;
|
break;
|
||||||
|
@@ -35,18 +35,18 @@ namespace YAML
|
|||||||
// . Only the ones that make sense will be accepted
|
// . Only the ones that make sense will be accepted
|
||||||
void EmitterState::SetLocalValue(EMITTER_MANIP value)
|
void EmitterState::SetLocalValue(EMITTER_MANIP value)
|
||||||
{
|
{
|
||||||
SetOutputCharset(value, LOCAL);
|
SetOutputCharset(value, FmtScope::Local);
|
||||||
SetStringFormat(value, LOCAL);
|
SetStringFormat(value, FmtScope::Local);
|
||||||
SetBoolFormat(value, LOCAL);
|
SetBoolFormat(value, FmtScope::Local);
|
||||||
SetBoolCaseFormat(value, LOCAL);
|
SetBoolCaseFormat(value, FmtScope::Local);
|
||||||
SetBoolLengthFormat(value, LOCAL);
|
SetBoolLengthFormat(value, FmtScope::Local);
|
||||||
SetIntFormat(value, LOCAL);
|
SetIntFormat(value, FmtScope::Local);
|
||||||
SetFlowType(GT_SEQ, value, LOCAL);
|
SetFlowType(GroupType::Seq, value, FmtScope::Local);
|
||||||
SetFlowType(GT_MAP, value, LOCAL);
|
SetFlowType(GroupType::Map, value, FmtScope::Local);
|
||||||
SetMapKeyFormat(value, LOCAL);
|
SetMapKeyFormat(value, FmtScope::Local);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitterState::BeginGroup(GROUP_TYPE type)
|
void EmitterState::BeginGroup(GroupType::value type)
|
||||||
{
|
{
|
||||||
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
|
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
|
||||||
m_curIndent += lastIndent;
|
m_curIndent += lastIndent;
|
||||||
@@ -64,7 +64,7 @@ namespace YAML
|
|||||||
m_groups.push(pGroup);
|
m_groups.push(pGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitterState::EndGroup(GROUP_TYPE type)
|
void EmitterState::EndGroup(GroupType::value type)
|
||||||
{
|
{
|
||||||
if(m_groups.empty())
|
if(m_groups.empty())
|
||||||
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
|
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
|
||||||
@@ -86,20 +86,20 @@ namespace YAML
|
|||||||
m_globalModifiedSettings.restore();
|
m_globalModifiedSettings.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
GROUP_TYPE EmitterState::GetCurGroupType() const
|
GroupType::value EmitterState::GetCurGroupType() const
|
||||||
{
|
{
|
||||||
if(m_groups.empty())
|
if(m_groups.empty())
|
||||||
return GT_NONE;
|
return GroupType::None;
|
||||||
|
|
||||||
return m_groups.top().type;
|
return m_groups.top().type;
|
||||||
}
|
}
|
||||||
|
|
||||||
FLOW_TYPE EmitterState::GetCurGroupFlowType() const
|
FlowType::value EmitterState::GetCurGroupFlowType() const
|
||||||
{
|
{
|
||||||
if(m_groups.empty())
|
if(m_groups.empty())
|
||||||
return FT_NONE;
|
return FlowType::None;
|
||||||
|
|
||||||
return (m_groups.top().flow == Flow ? FT_FLOW : FT_BLOCK);
|
return (m_groups.top().flow == Flow ? FlowType::Flow : FlowType::Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::CurrentlyInLongKey()
|
bool EmitterState::CurrentlyInLongKey()
|
||||||
@@ -126,7 +126,7 @@ namespace YAML
|
|||||||
m_modifiedSettings.clear();
|
m_modifiedSettings.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case EmitNonAscii:
|
case EmitNonAscii:
|
||||||
@@ -138,7 +138,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case Auto:
|
case Auto:
|
||||||
@@ -152,7 +152,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case OnOffBool:
|
case OnOffBool:
|
||||||
@@ -165,7 +165,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case LongBool:
|
case LongBool:
|
||||||
@@ -177,7 +177,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case UpperCase:
|
case UpperCase:
|
||||||
@@ -190,7 +190,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case Dec:
|
case Dec:
|
||||||
@@ -203,7 +203,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetIndent(unsigned value, FMT_SCOPE scope)
|
bool EmitterState::SetIndent(unsigned value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
if(value == 0)
|
if(value == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -212,7 +212,7 @@ namespace YAML
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetPreCommentIndent(unsigned value, FMT_SCOPE scope)
|
bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
if(value == 0)
|
if(value == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -221,7 +221,7 @@ namespace YAML
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetPostCommentIndent(unsigned value, FMT_SCOPE scope)
|
bool EmitterState::SetPostCommentIndent(unsigned value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
if(value == 0)
|
if(value == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -230,30 +230,30 @@ namespace YAML
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case Block:
|
case Block:
|
||||||
case Flow:
|
case Flow:
|
||||||
_Set(groupType == GT_SEQ ? m_seqFmt : m_mapFmt, value, scope);
|
_Set(groupType == GroupType::Seq ? m_seqFmt : m_mapFmt, value, scope);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EMITTER_MANIP EmitterState::GetFlowType(GROUP_TYPE groupType) const
|
EMITTER_MANIP EmitterState::GetFlowType(GroupType::value groupType) const
|
||||||
{
|
{
|
||||||
// force flow style if we're currently in a flow
|
// force flow style if we're currently in a flow
|
||||||
FLOW_TYPE flowType = GetCurGroupFlowType();
|
FlowType::value flowType = GetCurGroupFlowType();
|
||||||
if(flowType == FT_FLOW)
|
if(flowType == FlowType::Flow)
|
||||||
return Flow;
|
return Flow;
|
||||||
|
|
||||||
// otherwise, go with what's asked of use
|
// otherwise, go with what's asked of us
|
||||||
return (groupType == GT_SEQ ? m_seqFmt.get() : m_mapFmt.get());
|
return (groupType == GroupType::Seq ? m_seqFmt.get() : m_mapFmt.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope)
|
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case Auto:
|
case Auto:
|
||||||
@@ -265,7 +265,7 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetFloatPrecision(int value, FMT_SCOPE scope)
|
bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
if(value < 0 || value > std::numeric_limits<float>::digits10)
|
if(value < 0 || value > std::numeric_limits<float>::digits10)
|
||||||
return false;
|
return false;
|
||||||
@@ -273,7 +273,7 @@ namespace YAML
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::SetDoublePrecision(int value, FMT_SCOPE scope)
|
bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope)
|
||||||
{
|
{
|
||||||
if(value < 0 || value > std::numeric_limits<double>::digits10)
|
if(value < 0 || value > std::numeric_limits<double>::digits10)
|
||||||
return false;
|
return false;
|
||||||
|
@@ -16,23 +16,10 @@
|
|||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
enum FMT_SCOPE {
|
struct FmtScope { enum value { Local, Global }; };
|
||||||
LOCAL,
|
struct GroupType { enum value { None, Seq, Map }; };
|
||||||
GLOBAL
|
struct FlowType { enum value { None, Flow, Block }; };
|
||||||
};
|
|
||||||
|
|
||||||
enum GROUP_TYPE {
|
|
||||||
GT_NONE,
|
|
||||||
GT_SEQ,
|
|
||||||
GT_MAP
|
|
||||||
};
|
|
||||||
|
|
||||||
enum FLOW_TYPE {
|
|
||||||
FT_NONE,
|
|
||||||
FT_FLOW,
|
|
||||||
FT_BLOCK
|
|
||||||
};
|
|
||||||
|
|
||||||
enum NODE_STATE {
|
enum NODE_STATE {
|
||||||
NS_START,
|
NS_START,
|
||||||
NS_READY_FOR_ATOM,
|
NS_READY_FOR_ATOM,
|
||||||
@@ -93,11 +80,11 @@ namespace YAML
|
|||||||
void SetLocalValue(EMITTER_MANIP value);
|
void SetLocalValue(EMITTER_MANIP value);
|
||||||
|
|
||||||
// group handling
|
// group handling
|
||||||
void BeginGroup(GROUP_TYPE type);
|
void BeginGroup(GroupType::value type);
|
||||||
void EndGroup(GROUP_TYPE type);
|
void EndGroup(GroupType::value type);
|
||||||
|
|
||||||
GROUP_TYPE GetCurGroupType() const;
|
GroupType::value GetCurGroupType() const;
|
||||||
FLOW_TYPE GetCurGroupFlowType() const;
|
FlowType::value GetCurGroupFlowType() const;
|
||||||
int GetCurIndent() const { return m_curIndent; }
|
int GetCurIndent() const { return m_curIndent; }
|
||||||
|
|
||||||
bool CurrentlyInLongKey();
|
bool CurrentlyInLongKey();
|
||||||
@@ -114,46 +101,46 @@ namespace YAML
|
|||||||
void ClearModifiedSettings();
|
void ClearModifiedSettings();
|
||||||
|
|
||||||
// formatters
|
// formatters
|
||||||
bool SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); }
|
EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); }
|
||||||
|
|
||||||
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetStringFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
|
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
|
||||||
|
|
||||||
bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); }
|
EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); }
|
||||||
|
|
||||||
bool SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetBoolLengthFormat() const { return m_boolLengthFmt.get(); }
|
EMITTER_MANIP GetBoolLengthFormat() const { return m_boolLengthFmt.get(); }
|
||||||
|
|
||||||
bool SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetBoolCaseFormat() const { return m_boolCaseFmt.get(); }
|
EMITTER_MANIP GetBoolCaseFormat() const { return m_boolCaseFmt.get(); }
|
||||||
|
|
||||||
bool SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
|
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
|
||||||
|
|
||||||
bool SetIndent(unsigned value, FMT_SCOPE scope);
|
bool SetIndent(unsigned value, FmtScope::value scope);
|
||||||
int GetIndent() const { return m_indent.get(); }
|
int GetIndent() const { return m_indent.get(); }
|
||||||
|
|
||||||
bool SetPreCommentIndent(unsigned value, FMT_SCOPE scope);
|
bool SetPreCommentIndent(unsigned value, FmtScope::value scope);
|
||||||
int GetPreCommentIndent() const { return m_preCommentIndent.get(); }
|
int GetPreCommentIndent() const { return m_preCommentIndent.get(); }
|
||||||
bool SetPostCommentIndent(unsigned value, FMT_SCOPE scope);
|
bool SetPostCommentIndent(unsigned value, FmtScope::value scope);
|
||||||
int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
|
int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
|
||||||
|
|
||||||
bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetFlowType(GROUP_TYPE groupType) const;
|
EMITTER_MANIP GetFlowType(GroupType::value groupType) const;
|
||||||
|
|
||||||
bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope);
|
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
|
||||||
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
|
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
|
||||||
|
|
||||||
bool SetFloatPrecision(int value, FMT_SCOPE scope);
|
bool SetFloatPrecision(int value, FmtScope::value scope);
|
||||||
unsigned GetFloatPrecision() const { return m_floatPrecision.get(); }
|
unsigned GetFloatPrecision() const { return m_floatPrecision.get(); }
|
||||||
bool SetDoublePrecision(int value, FMT_SCOPE scope);
|
bool SetDoublePrecision(int value, FmtScope::value scope);
|
||||||
unsigned GetDoublePrecision() const { return m_doublePrecision.get(); }
|
unsigned GetDoublePrecision() const { return m_doublePrecision.get(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void _Set(Setting<T>& fmt, T value, FMT_SCOPE scope);
|
void _Set(Setting<T>& fmt, T value, FmtScope::value scope);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// basic state ok?
|
// basic state ok?
|
||||||
@@ -181,9 +168,9 @@ namespace YAML
|
|||||||
SettingChanges m_globalModifiedSettings;
|
SettingChanges m_globalModifiedSettings;
|
||||||
|
|
||||||
struct Group {
|
struct Group {
|
||||||
Group(GROUP_TYPE type_): type(type_), usingLongKey(false), indent(0) {}
|
Group(GroupType::value type_): type(type_), usingLongKey(false), indent(0) {}
|
||||||
|
|
||||||
GROUP_TYPE type;
|
GroupType::value type;
|
||||||
EMITTER_MANIP flow;
|
EMITTER_MANIP flow;
|
||||||
bool usingLongKey;
|
bool usingLongKey;
|
||||||
int indent;
|
int indent;
|
||||||
@@ -198,12 +185,12 @@ namespace YAML
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void EmitterState::_Set(Setting<T>& fmt, T value, FMT_SCOPE scope) {
|
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
|
||||||
switch(scope) {
|
switch(scope) {
|
||||||
case LOCAL:
|
case FmtScope::Local:
|
||||||
m_modifiedSettings.push(fmt.set(value));
|
m_modifiedSettings.push(fmt.set(value));
|
||||||
break;
|
break;
|
||||||
case GLOBAL:
|
case FmtScope::Global:
|
||||||
fmt.set(value);
|
fmt.set(value);
|
||||||
m_globalModifiedSettings.push(fmt.set(value)); // this pushes an identity set, so when we restore,
|
m_globalModifiedSettings.push(fmt.set(value)); // this pushes an identity set, so when we restore,
|
||||||
// it restores to the value here, and not the previous one
|
// it restores to the value here, and not the previous one
|
||||||
|
Reference in New Issue
Block a user