mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Replace Boost usage with C++11 features
- Adds 'std=c++11' compiler flags - Replaces boost::type_traits with std::type_traits - Replaces boost::shared_ptr with std::shared_ptr - Replaces std::auto_ptr with std::unique_ptr - Replaces raw pointers with std::unique_ptr in ptr_vector, ptr_stack, and SettingChanges - Replaces boost::noncopyable with deleted copy and assignment operators - Replaces boost::next with std::next - Replaces boost::enable_if with std::enable_if - Replaces boost::is_convertible with std::is_convertible - Replaces ptrdiff_t with std::ptrdiff_t - Replaces boost::iterator_facade and boost::iterator_adaptor with std::iterator, borrowing the 'proxy reference' technique from boost - Removes Boost dependency from CMakeLists - Formats changed files using clang-format
This commit is contained in:
@@ -124,10 +124,14 @@ void EmitterState::StartedGroup(GroupType::value type) {
|
||||
const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
|
||||
m_curIndent += lastGroupIndent;
|
||||
|
||||
std::auto_ptr<Group> pGroup(new Group(type));
|
||||
// TODO: Create move constructors for settings types to simplify transfer
|
||||
std::unique_ptr<Group> pGroup(new Group(type));
|
||||
|
||||
// transfer settings (which last until this group is done)
|
||||
pGroup->modifiedSettings = m_modifiedSettings;
|
||||
//
|
||||
// NB: if pGroup->modifiedSettings == m_modifiedSettings,
|
||||
// m_modifiedSettings is not changed!
|
||||
pGroup->modifiedSettings = std::move(m_modifiedSettings);
|
||||
|
||||
// set up group
|
||||
if (GetFlowType(type) == Block)
|
||||
@@ -136,7 +140,7 @@ void EmitterState::StartedGroup(GroupType::value type) {
|
||||
pGroup->flowType = FlowType::Flow;
|
||||
pGroup->indent = GetIndent();
|
||||
|
||||
m_groups.push(pGroup);
|
||||
m_groups.push(std::move(pGroup));
|
||||
}
|
||||
|
||||
void EmitterState::EndedGroup(GroupType::value type) {
|
||||
@@ -149,7 +153,7 @@ void EmitterState::EndedGroup(GroupType::value type) {
|
||||
|
||||
// get rid of the current group
|
||||
{
|
||||
std::auto_ptr<Group> pFinishedGroup = m_groups.pop();
|
||||
std::unique_ptr<Group> pFinishedGroup = m_groups.pop();
|
||||
if (pFinishedGroup->type != type)
|
||||
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
@@ -28,9 +28,7 @@ void node_data::mark_defined() {
|
||||
m_isDefined = true;
|
||||
}
|
||||
|
||||
void node_data::set_mark(const Mark& mark) {
|
||||
m_mark = mark;
|
||||
}
|
||||
void node_data::set_mark(const Mark& mark) { m_mark = mark; }
|
||||
|
||||
void node_data::set_type(NodeType::value type) {
|
||||
if (type == NodeType::Undefined) {
|
||||
@@ -104,7 +102,7 @@ void node_data::compute_seq_size() const {
|
||||
void node_data::compute_map_size() const {
|
||||
kv_pairs::iterator it = m_undefinedPairs.begin();
|
||||
while (it != m_undefinedPairs.end()) {
|
||||
kv_pairs::iterator jt = boost::next(it);
|
||||
kv_pairs::iterator jt = std::next(it);
|
||||
if (it->first->is_defined() && it->second->is_defined())
|
||||
m_undefinedPairs.erase(it);
|
||||
it = jt;
|
||||
|
@@ -14,40 +14,45 @@
|
||||
|
||||
#include "yaml-cpp/noncopyable.h"
|
||||
|
||||
// TODO: This class is no longer needed
|
||||
template <typename T>
|
||||
class ptr_stack : private YAML::noncopyable {
|
||||
public:
|
||||
ptr_stack() {}
|
||||
~ptr_stack() { clear(); }
|
||||
|
||||
void clear() {
|
||||
for (std::size_t i = 0; i < m_data.size(); i++)
|
||||
delete m_data[i];
|
||||
m_data.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const { return m_data.size(); }
|
||||
bool empty() const { return m_data.empty(); }
|
||||
|
||||
void push(std::auto_ptr<T> t) {
|
||||
m_data.push_back(NULL);
|
||||
m_data.back() = t.release();
|
||||
void push(std::unique_ptr<T>&& t) {
|
||||
m_data.push_back(std::move(t));
|
||||
}
|
||||
std::auto_ptr<T> pop() {
|
||||
std::auto_ptr<T> t(m_data.back());
|
||||
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(); }
|
||||
const T& top() const { return *m_data.back(); }
|
||||
|
||||
T& top(std::ptrdiff_t diff) { return **(m_data.end() - 1 + diff); }
|
||||
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);
|
||||
return *((m_data.end() - 1 + diff)->get());
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T*> m_data;
|
||||
std::vector<std::unique_ptr<T>> m_data;
|
||||
};
|
||||
|
||||
#endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@@ -16,33 +16,35 @@
|
||||
|
||||
namespace YAML {
|
||||
|
||||
// TODO: This class is no longer needed
|
||||
template <typename T>
|
||||
class ptr_vector : private YAML::noncopyable {
|
||||
public:
|
||||
ptr_vector() {}
|
||||
~ptr_vector() { clear(); }
|
||||
|
||||
void clear() {
|
||||
for (std::size_t i = 0; i < m_data.size(); i++)
|
||||
delete m_data[i];
|
||||
m_data.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const { return m_data.size(); }
|
||||
bool empty() const { return m_data.empty(); }
|
||||
|
||||
void push_back(std::auto_ptr<T> t) {
|
||||
m_data.push_back(NULL);
|
||||
m_data.back() = t.release();
|
||||
void push_back(std::unique_ptr<T>&& t) {
|
||||
m_data.push_back(std::move(t));
|
||||
}
|
||||
T& operator[](std::size_t i) { return *m_data[i]; }
|
||||
const T& operator[](std::size_t i) const { return *m_data[i]; }
|
||||
|
||||
T& back() { return *m_data.back(); }
|
||||
const T& back() const { return *m_data.back(); }
|
||||
T& back() {
|
||||
return *(m_data.back().get());
|
||||
}
|
||||
|
||||
const T& back() const {
|
||||
return *(m_data.back().get());
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T*> m_data;
|
||||
std::vector<std::unique_ptr<T>> m_data;
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -233,8 +233,8 @@ const RegEx& Scanner::GetValueRegex() const {
|
||||
void Scanner::StartStream() {
|
||||
m_startedStream = true;
|
||||
m_simpleKeyAllowed = true;
|
||||
std::auto_ptr<IndentMarker> pIndent(new IndentMarker(-1, IndentMarker::NONE));
|
||||
m_indentRefs.push_back(pIndent);
|
||||
std::unique_ptr<IndentMarker> pIndent(new IndentMarker(-1, IndentMarker::NONE));
|
||||
m_indentRefs.push_back(std::move(pIndent));
|
||||
m_indents.push(&m_indentRefs.back());
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ Scanner::IndentMarker* Scanner::PushIndentTo(int column,
|
||||
if (InFlowContext())
|
||||
return 0;
|
||||
|
||||
std::auto_ptr<IndentMarker> pIndent(new IndentMarker(column, type));
|
||||
std::unique_ptr<IndentMarker> pIndent(new IndentMarker(column, type));
|
||||
IndentMarker& indent = *pIndent;
|
||||
const IndentMarker& lastIndent = *m_indents.top();
|
||||
|
||||
@@ -298,7 +298,7 @@ Scanner::IndentMarker* Scanner::PushIndentTo(int column,
|
||||
|
||||
// and then the indent
|
||||
m_indents.push(&indent);
|
||||
m_indentRefs.push_back(pIndent);
|
||||
m_indentRefs.push_back(std::move(pIndent));
|
||||
return &m_indentRefs.back();
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@ class Setting {
|
||||
Setting() : m_value() {}
|
||||
|
||||
const T get() const { return m_value; }
|
||||
std::auto_ptr<SettingChangeBase> set(const T& value);
|
||||
std::unique_ptr<SettingChangeBase> set(const T& value);
|
||||
void restore(const Setting<T>& oldSetting) { m_value = oldSetting.get(); }
|
||||
|
||||
private:
|
||||
@@ -49,8 +49,8 @@ class SettingChange : public SettingChangeBase {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline std::auto_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
|
||||
std::auto_ptr<SettingChangeBase> pChange(new SettingChange<T>(this));
|
||||
inline std::unique_ptr<SettingChangeBase> Setting<T>::set(const T& value) {
|
||||
std::unique_ptr<SettingChangeBase> pChange(new SettingChange<T>(this));
|
||||
m_value = value;
|
||||
return pChange;
|
||||
}
|
||||
@@ -62,10 +62,6 @@ class SettingChanges : private noncopyable {
|
||||
|
||||
void clear() {
|
||||
restore();
|
||||
|
||||
for (setting_changes::const_iterator it = m_settingChanges.begin();
|
||||
it != m_settingChanges.end(); ++it)
|
||||
delete *it;
|
||||
m_settingChanges.clear();
|
||||
}
|
||||
|
||||
@@ -75,23 +71,23 @@ class SettingChanges : private noncopyable {
|
||||
(*it)->pop();
|
||||
}
|
||||
|
||||
void push(std::auto_ptr<SettingChangeBase> pSettingChange) {
|
||||
m_settingChanges.push_back(pSettingChange.release());
|
||||
void push(std::unique_ptr<SettingChangeBase> pSettingChange) {
|
||||
m_settingChanges.push_back(std::move(pSettingChange));
|
||||
}
|
||||
|
||||
// like std::auto_ptr - assignment is transfer of ownership
|
||||
SettingChanges& operator=(SettingChanges& rhs) {
|
||||
// like std::unique_ptr - assignment is transfer of ownership
|
||||
SettingChanges& operator=(SettingChanges&& rhs) {
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
clear();
|
||||
m_settingChanges = rhs.m_settingChanges;
|
||||
rhs.m_settingChanges.clear();
|
||||
std::swap(m_settingChanges, rhs.m_settingChanges);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector<SettingChangeBase*> setting_changes;
|
||||
typedef std::vector<std::unique_ptr<SettingChangeBase>> setting_changes;
|
||||
setting_changes m_settingChanges;
|
||||
};
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ class SingleDocParser : private noncopyable {
|
||||
private:
|
||||
Scanner& m_scanner;
|
||||
const Directives& m_directives;
|
||||
std::auto_ptr<CollectionStack> m_pCollectionStack;
|
||||
std::unique_ptr<CollectionStack> m_pCollectionStack;
|
||||
|
||||
typedef std::map<std::string, anchor_t> Anchors;
|
||||
Anchors m_anchors;
|
||||
|
Reference in New Issue
Block a user