mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Switched the emitter state's stack of groups to a ptr_stack
This commit is contained in:
@@ -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,10 +45,10 @@ 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));
|
||||||
|
|
||||||
// transfer settings (which last until this group is done)
|
// transfer settings (which last until this group is done)
|
||||||
pGroup->modifiedSettings = m_modifiedSettings;
|
pGroup->modifiedSettings = m_modifiedSettings;
|
||||||
@@ -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()
|
||||||
|
@@ -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>
|
||||||
@@ -155,19 +156,19 @@ namespace YAML
|
|||||||
std::string m_lastError;
|
std::string m_lastError;
|
||||||
|
|
||||||
// other state
|
// other state
|
||||||
std::stack <EMITTER_STATE> m_stateStack;
|
std::stack<EMITTER_STATE> m_stateStack;
|
||||||
|
|
||||||
Setting <EMITTER_MANIP> m_charset;
|
Setting<EMITTER_MANIP> m_charset;
|
||||||
Setting <EMITTER_MANIP> m_strFmt;
|
Setting<EMITTER_MANIP> m_strFmt;
|
||||||
Setting <EMITTER_MANIP> m_boolFmt;
|
Setting<EMITTER_MANIP> m_boolFmt;
|
||||||
Setting <EMITTER_MANIP> m_boolLengthFmt;
|
Setting<EMITTER_MANIP> m_boolLengthFmt;
|
||||||
Setting <EMITTER_MANIP> m_boolCaseFmt;
|
Setting<EMITTER_MANIP> m_boolCaseFmt;
|
||||||
Setting <EMITTER_MANIP> m_intFmt;
|
Setting<EMITTER_MANIP> m_intFmt;
|
||||||
Setting <unsigned> m_indent;
|
Setting<unsigned> m_indent;
|
||||||
Setting <unsigned> m_preCommentIndent, m_postCommentIndent;
|
Setting<unsigned> m_preCommentIndent, m_postCommentIndent;
|
||||||
Setting <EMITTER_MANIP> m_seqFmt;
|
Setting<EMITTER_MANIP> m_seqFmt;
|
||||||
Setting <EMITTER_MANIP> m_mapFmt;
|
Setting<EMITTER_MANIP> m_mapFmt;
|
||||||
Setting <EMITTER_MANIP> m_mapKeyFmt;
|
Setting<EMITTER_MANIP> m_mapKeyFmt;
|
||||||
|
|
||||||
SettingChanges m_modifiedSettings;
|
SettingChanges m_modifiedSettings;
|
||||||
SettingChanges m_globalModifiedSettings;
|
SettingChanges m_globalModifiedSettings;
|
||||||
@@ -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;
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user