Switched the emitter state's stack of groups to a ptr_stack

This commit is contained in:
jbeder
2011-03-03 08:11:14 +00:00
parent bbb19cf5c0
commit 06eae35c31
3 changed files with 26 additions and 38 deletions

View File

@@ -25,18 +25,6 @@ namespace YAML
EmitterState::~EmitterState()
{
while(!m_groups.empty())
_PopGroup();
}
std::auto_ptr <EmitterState::Group> EmitterState::_PopGroup()
{
if(m_groups.empty())
return std::auto_ptr <Group> (0);
std::auto_ptr <Group> pGroup(m_groups.top());
m_groups.pop();
return pGroup;
}
// SetLocalValue
@@ -57,10 +45,10 @@ namespace YAML
void EmitterState::BeginGroup(GROUP_TYPE type)
{
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top()->indent);
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
m_curIndent += lastIndent;
std::auto_ptr <Group> pGroup(new Group(type));
std::auto_ptr<Group> pGroup(new Group(type));
// transfer settings (which last until this group is done)
pGroup->modifiedSettings = m_modifiedSettings;
@@ -70,7 +58,7 @@ namespace YAML
pGroup->indent = GetIndent();
pGroup->usingLongKey = (GetMapKeyFormat() == LongKey ? true : false);
m_groups.push(pGroup.release());
m_groups.push(pGroup);
}
void EmitterState::EndGroup(GROUP_TYPE type)
@@ -80,13 +68,13 @@ namespace YAML
// get rid of the current group
{
std::auto_ptr <Group> pFinishedGroup = _PopGroup();
std::auto_ptr<Group> pFinishedGroup = m_groups.pop();
if(pFinishedGroup->type != type)
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
}
// reset old settings
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top()->indent);
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
assert(m_curIndent >= lastIndent);
m_curIndent -= lastIndent;
@@ -100,7 +88,7 @@ namespace YAML
if(m_groups.empty())
return GT_NONE;
return m_groups.top()->type;
return m_groups.top().type;
}
FLOW_TYPE EmitterState::GetCurGroupFlowType() const
@@ -108,26 +96,26 @@ namespace YAML
if(m_groups.empty())
return FT_NONE;
return (m_groups.top()->flow == Flow ? FT_FLOW : FT_BLOCK);
return (m_groups.top().flow == Flow ? FT_FLOW : FT_BLOCK);
}
bool EmitterState::CurrentlyInLongKey()
{
if(m_groups.empty())
return false;
return m_groups.top()->usingLongKey;
return m_groups.top().usingLongKey;
}
void EmitterState::StartLongKey()
{
if(!m_groups.empty())
m_groups.top()->usingLongKey = true;
m_groups.top().usingLongKey = true;
}
void EmitterState::StartSimpleKey()
{
if(!m_groups.empty())
m_groups.top()->usingLongKey = false;
m_groups.top().usingLongKey = false;
}
void EmitterState::ClearModifiedSettings()

View File

@@ -6,6 +6,7 @@
#endif
#include "ptr_stack.h"
#include "setting.h"
#include "yaml-cpp/emittermanip.h"
#include <cassert>
@@ -155,19 +156,19 @@ namespace YAML
std::string m_lastError;
// other state
std::stack <EMITTER_STATE> m_stateStack;
std::stack<EMITTER_STATE> m_stateStack;
Setting <EMITTER_MANIP> m_charset;
Setting <EMITTER_MANIP> m_strFmt;
Setting <EMITTER_MANIP> m_boolFmt;
Setting <EMITTER_MANIP> m_boolLengthFmt;
Setting <EMITTER_MANIP> m_boolCaseFmt;
Setting <EMITTER_MANIP> m_intFmt;
Setting <unsigned> m_indent;
Setting <unsigned> m_preCommentIndent, m_postCommentIndent;
Setting <EMITTER_MANIP> m_seqFmt;
Setting <EMITTER_MANIP> m_mapFmt;
Setting <EMITTER_MANIP> m_mapKeyFmt;
Setting<EMITTER_MANIP> m_charset;
Setting<EMITTER_MANIP> m_strFmt;
Setting<EMITTER_MANIP> m_boolFmt;
Setting<EMITTER_MANIP> m_boolLengthFmt;
Setting<EMITTER_MANIP> m_boolCaseFmt;
Setting<EMITTER_MANIP> m_intFmt;
Setting<unsigned> m_indent;
Setting<unsigned> m_preCommentIndent, m_postCommentIndent;
Setting<EMITTER_MANIP> m_seqFmt;
Setting<EMITTER_MANIP> m_mapFmt;
Setting<EMITTER_MANIP> m_mapKeyFmt;
SettingChanges m_modifiedSettings;
SettingChanges m_globalModifiedSettings;
@@ -182,10 +183,8 @@ namespace YAML
SettingChanges modifiedSettings;
};
std::auto_ptr <Group> _PopGroup();
std::stack <Group *> m_groups;
ptr_stack<Group> m_groups;
unsigned m_curIndent;
bool m_requiresSoftSeparation;
bool m_requiresHardSeparation;

View File

@@ -35,6 +35,7 @@ public:
return t;
}
T& top() { return *m_data.back(); }
const T& top() const { return *m_data.back(); }
private:
std::vector<T*> m_data;