mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Remove ptr_stack<T>, in favor of vector<unique_ptr<T>>.
(Not stack<unique_ptr<T>> because it wasn't quite a stack; we needed to get the second-to-last element sometimes.)
This commit is contained in:
@@ -53,28 +53,31 @@ void EmitterState::SetNonContent() { m_hasNonContent = true; }
|
|||||||
|
|
||||||
void EmitterState::SetLongKey() {
|
void EmitterState::SetLongKey() {
|
||||||
assert(!m_groups.empty());
|
assert(!m_groups.empty());
|
||||||
if (m_groups.empty())
|
if (m_groups.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(m_groups.top().type == GroupType::Map);
|
assert(m_groups.back()->type == GroupType::Map);
|
||||||
m_groups.top().longKey = true;
|
m_groups.back()->longKey = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitterState::ForceFlow() {
|
void EmitterState::ForceFlow() {
|
||||||
assert(!m_groups.empty());
|
assert(!m_groups.empty());
|
||||||
if (m_groups.empty())
|
if (m_groups.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_groups.top().flowType = FlowType::Flow;
|
m_groups.back()->flowType = FlowType::Flow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitterState::StartedNode() {
|
void EmitterState::StartedNode() {
|
||||||
if (m_groups.empty()) {
|
if (m_groups.empty()) {
|
||||||
m_docCount++;
|
m_docCount++;
|
||||||
} else {
|
} else {
|
||||||
m_groups.top().childCount++;
|
m_groups.back()->childCount++;
|
||||||
if (m_groups.top().childCount % 2 == 0)
|
if (m_groups.back()->childCount % 2 == 0) {
|
||||||
m_groups.top().longKey = false;
|
m_groups.back()->longKey = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hasAnchor = false;
|
m_hasAnchor = false;
|
||||||
@@ -121,7 +124,7 @@ void EmitterState::StartedScalar() {
|
|||||||
void EmitterState::StartedGroup(GroupType::value type) {
|
void EmitterState::StartedGroup(GroupType::value type) {
|
||||||
StartedNode();
|
StartedNode();
|
||||||
|
|
||||||
const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
|
const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.back()->indent);
|
||||||
m_curIndent += lastGroupIndent;
|
m_curIndent += lastGroupIndent;
|
||||||
|
|
||||||
// TODO: Create move constructors for settings types to simplify transfer
|
// TODO: Create move constructors for settings types to simplify transfer
|
||||||
@@ -134,32 +137,36 @@ void EmitterState::StartedGroup(GroupType::value type) {
|
|||||||
pGroup->modifiedSettings = std::move(m_modifiedSettings);
|
pGroup->modifiedSettings = std::move(m_modifiedSettings);
|
||||||
|
|
||||||
// set up group
|
// set up group
|
||||||
if (GetFlowType(type) == Block)
|
if (GetFlowType(type) == Block) {
|
||||||
pGroup->flowType = FlowType::Block;
|
pGroup->flowType = FlowType::Block;
|
||||||
else
|
} else {
|
||||||
pGroup->flowType = FlowType::Flow;
|
pGroup->flowType = FlowType::Flow;
|
||||||
|
}
|
||||||
pGroup->indent = GetIndent();
|
pGroup->indent = GetIndent();
|
||||||
|
|
||||||
m_groups.push(std::move(pGroup));
|
m_groups.push_back(std::move(pGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitterState::EndedGroup(GroupType::value type) {
|
void EmitterState::EndedGroup(GroupType::value type) {
|
||||||
if (m_groups.empty()) {
|
if (m_groups.empty()) {
|
||||||
if (type == GroupType::Seq)
|
if (type == GroupType::Seq) {
|
||||||
return SetError(ErrorMsg::UNEXPECTED_END_SEQ);
|
return SetError(ErrorMsg::UNEXPECTED_END_SEQ);
|
||||||
else
|
} else {
|
||||||
return SetError(ErrorMsg::UNEXPECTED_END_MAP);
|
return SetError(ErrorMsg::UNEXPECTED_END_MAP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get rid of the current group
|
// get rid of the current group
|
||||||
{
|
{
|
||||||
std::unique_ptr<Group> pFinishedGroup = m_groups.pop();
|
std::unique_ptr<Group> pFinishedGroup = std::move(m_groups.back());
|
||||||
if (pFinishedGroup->type != type)
|
m_groups.pop_back();
|
||||||
|
if (pFinishedGroup->type != type) {
|
||||||
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
|
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset old settings
|
// reset old settings
|
||||||
std::size_t lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
|
std::size_t lastIndent = (m_groups.empty() ? 0 : m_groups.back()->indent);
|
||||||
assert(m_curIndent >= lastIndent);
|
assert(m_curIndent >= lastIndent);
|
||||||
m_curIndent -= lastIndent;
|
m_curIndent -= lastIndent;
|
||||||
|
|
||||||
@@ -171,37 +178,39 @@ void EmitterState::EndedGroup(GroupType::value type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EmitterNodeType::value EmitterState::CurGroupNodeType() const {
|
EmitterNodeType::value EmitterState::CurGroupNodeType() const {
|
||||||
if (m_groups.empty())
|
if (m_groups.empty()) {
|
||||||
return EmitterNodeType::NoType;
|
return EmitterNodeType::NoType;
|
||||||
|
}
|
||||||
|
|
||||||
return m_groups.top().NodeType();
|
return m_groups.back()->NodeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupType::value EmitterState::CurGroupType() const {
|
GroupType::value EmitterState::CurGroupType() const {
|
||||||
return m_groups.empty() ? GroupType::NoType : m_groups.top().type;
|
return m_groups.empty() ? GroupType::NoType : m_groups.back()->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlowType::value EmitterState::CurGroupFlowType() const {
|
FlowType::value EmitterState::CurGroupFlowType() const {
|
||||||
return m_groups.empty() ? FlowType::NoType : m_groups.top().flowType;
|
return m_groups.empty() ? FlowType::NoType : m_groups.back()->flowType;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EmitterState::CurGroupIndent() const {
|
int EmitterState::CurGroupIndent() const {
|
||||||
return m_groups.empty() ? 0 : m_groups.top().indent;
|
return m_groups.empty() ? 0 : m_groups.back()->indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t EmitterState::CurGroupChildCount() const {
|
std::size_t EmitterState::CurGroupChildCount() const {
|
||||||
return m_groups.empty() ? m_docCount : m_groups.top().childCount;
|
return m_groups.empty() ? m_docCount : m_groups.back()->childCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmitterState::CurGroupLongKey() const {
|
bool EmitterState::CurGroupLongKey() const {
|
||||||
return m_groups.empty() ? false : m_groups.top().longKey;
|
return m_groups.empty() ? false : m_groups.back()->longKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EmitterState::LastIndent() const {
|
int EmitterState::LastIndent() const {
|
||||||
if (m_groups.size() <= 1)
|
if (m_groups.size() <= 1) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return m_curIndent - m_groups.top(-1).indent;
|
return m_curIndent - m_groups[m_groups.size() - 2]->indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitterState::ClearModifiedSettings() { m_modifiedSettings.clear(); }
|
void EmitterState::ClearModifiedSettings() { m_modifiedSettings.clear(); }
|
||||||
|
@@ -7,15 +7,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ptr_stack.h"
|
|
||||||
#include "setting.h"
|
#include "setting.h"
|
||||||
#include "yaml-cpp/emitterdef.h"
|
#include "yaml-cpp/emitterdef.h"
|
||||||
#include "yaml-cpp/emittermanip.h"
|
#include "yaml-cpp/emittermanip.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <vector>
|
|
||||||
#include <stack>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <stack>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
struct FmtScope {
|
struct FmtScope {
|
||||||
@@ -174,7 +174,7 @@ class EmitterState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ptr_stack<Group> m_groups;
|
std::vector<std::unique_ptr<Group>> m_groups;
|
||||||
std::size_t m_curIndent;
|
std::size_t m_curIndent;
|
||||||
bool m_hasAnchor;
|
bool m_hasAnchor;
|
||||||
bool m_hasTag;
|
bool m_hasTag;
|
||||||
|
@@ -1,58 +0,0 @@
|
|||||||
#ifndef PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
||||||
#define PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) || \
|
|
||||||
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
|
||||||
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
|
||||||
#pragma once
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "yaml-cpp/noncopyable.h"
|
|
||||||
|
|
||||||
// TODO: This class is no longer needed
|
|
||||||
template <typename T>
|
|
||||||
class ptr_stack : private YAML::noncopyable {
|
|
||||||
public:
|
|
||||||
ptr_stack() {}
|
|
||||||
|
|
||||||
void clear() {
|
|
||||||
m_data.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t size() const { return m_data.size(); }
|
|
||||||
bool empty() const { return m_data.empty(); }
|
|
||||||
|
|
||||||
void push(std::unique_ptr<T>&& t) {
|
|
||||||
m_data.push_back(std::move(t));
|
|
||||||
}
|
|
||||||
std::unique_ptr<T> pop() {
|
|
||||||
std::unique_ptr<T> t(std::move(m_data.back()));
|
|
||||||
m_data.pop_back();
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
T& top() {
|
|
||||||
return *(m_data.back().get());
|
|
||||||
}
|
|
||||||
const T& top() const {
|
|
||||||
return *(m_data.back().get());
|
|
||||||
}
|
|
||||||
|
|
||||||
T& top(std::ptrdiff_t diff) {
|
|
||||||
return *((m_data.end() - 1 + diff)->get());
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& top(std::ptrdiff_t diff) const {
|
|
||||||
return *((m_data.end() - 1 + diff)->get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<std::unique_ptr<T>> m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
Reference in New Issue
Block a user