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

This commit is contained in:
Jesse Beder
2011-03-03 08:11:14 +00:00
parent 27617ec2be
commit a518d87cfc
3 changed files with 26 additions and 38 deletions

View File

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

View File

@@ -6,6 +6,7 @@
#endif #endif
#include "ptr_stack.h"
#include "setting.h" #include "setting.h"
#include "yaml-cpp/emittermanip.h" #include "yaml-cpp/emittermanip.h"
#include <cassert> #include <cassert>
@@ -183,9 +184,7 @@ namespace YAML
SettingChanges modifiedSettings; SettingChanges modifiedSettings;
}; };
std::auto_ptr <Group> _PopGroup(); ptr_stack<Group> m_groups;
std::stack <Group *> m_groups;
unsigned m_curIndent; unsigned m_curIndent;
bool m_requiresSoftSeparation; bool m_requiresSoftSeparation;
bool m_requiresHardSeparation; bool m_requiresHardSeparation;

View File

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