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()
{
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,7 +45,7 @@ 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));
@@ -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>
@@ -183,9 +184,7 @@ 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;