Commit 41c2ddc0 by Jesse Beder

Switched the emitter state enums to scoped enums

parent 39165338
...@@ -35,18 +35,18 @@ namespace YAML ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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,22 +16,9 @@ ...@@ -16,22 +16,9 @@
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,
...@@ -93,11 +80,11 @@ namespace YAML ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment