mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +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:
@@ -122,7 +122,7 @@ class YAML_CPP_API Emitter : private noncopyable {
|
||||
bool CanEmitNewline() const;
|
||||
|
||||
private:
|
||||
std::auto_ptr<EmitterState> m_pState;
|
||||
std::unique_ptr<EmitterState> m_pState;
|
||||
ostream_wrapper m_stream;
|
||||
};
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "yaml-cpp/node/detail/node.h"
|
||||
#include "yaml-cpp/node/detail/node_data.h"
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
@@ -22,9 +22,9 @@ struct get_idx {
|
||||
};
|
||||
|
||||
template <typename Key>
|
||||
struct get_idx<
|
||||
Key, typename boost::enable_if_c<boost::is_unsigned<Key>::value &&
|
||||
!boost::is_same<Key, bool>::value>::type> {
|
||||
struct get_idx<Key,
|
||||
typename std::enable_if<std::is_unsigned<Key>::value &&
|
||||
!std::is_same<Key, bool>::value>::type> {
|
||||
static node* get(const std::vector<node*>& sequence, const Key& key,
|
||||
shared_memory_holder /* pMemory */) {
|
||||
return key < sequence.size() ? sequence[key] : 0;
|
||||
@@ -41,7 +41,7 @@ struct get_idx<
|
||||
};
|
||||
|
||||
template <typename Key>
|
||||
struct get_idx<Key, typename boost::enable_if<boost::is_signed<Key> >::type> {
|
||||
struct get_idx<Key, typename std::enable_if<std::is_signed<Key>::value>::type> {
|
||||
static node* get(const std::vector<node*>& sequence, const Key& key,
|
||||
shared_memory_holder pMemory) {
|
||||
return key >= 0 ? get_idx<std::size_t>::get(
|
||||
|
@@ -10,45 +10,68 @@
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include "yaml-cpp/node/detail/node_iterator.h"
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
struct iterator_value;
|
||||
|
||||
template <typename V>
|
||||
class iterator_base
|
||||
: public boost::iterator_adaptor<iterator_base<V>, node_iterator, V,
|
||||
std::forward_iterator_tag, V> {
|
||||
class iterator_base : public std::iterator<std::forward_iterator_tag, V,
|
||||
std::ptrdiff_t, V*, V> {
|
||||
|
||||
private:
|
||||
template <typename>
|
||||
friend class iterator_base;
|
||||
struct enabler {};
|
||||
typedef typename iterator_base::base_type base_type;
|
||||
typedef node_iterator base_type;
|
||||
|
||||
struct proxy {
|
||||
explicit proxy(const V& x) : m_ref(x) {}
|
||||
V* operator->() { return std::addressof(m_ref); }
|
||||
operator V*() { return std::addressof(m_ref); }
|
||||
|
||||
V m_ref;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename iterator_base::value_type value_type;
|
||||
|
||||
public:
|
||||
iterator_base() {}
|
||||
iterator_base() : m_iterator(), m_pMemory() {}
|
||||
explicit iterator_base(base_type rhs, shared_memory_holder pMemory)
|
||||
: iterator_base::iterator_adaptor_(rhs), m_pMemory(pMemory) {}
|
||||
: m_iterator(rhs), m_pMemory(pMemory) {}
|
||||
|
||||
template <class W>
|
||||
iterator_base(const iterator_base<W>& rhs,
|
||||
typename boost::enable_if<boost::is_convertible<W*, V*>,
|
||||
enabler>::type = enabler())
|
||||
: iterator_base::iterator_adaptor_(rhs.base()),
|
||||
m_pMemory(rhs.m_pMemory) {}
|
||||
typename std::enable_if<std::is_convertible<W*, V*>::value,
|
||||
enabler>::type = enabler())
|
||||
: m_iterator(rhs.m_iterator), m_pMemory(rhs.m_pMemory) {}
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
iterator_base<V>& operator++() {
|
||||
++m_iterator;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void increment() { this->base_reference() = boost::next(this->base()); }
|
||||
iterator_base<V> operator++(int) {
|
||||
iterator_base<V> iterator_pre(*this);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
value_type dereference() const {
|
||||
const typename base_type::value_type& v = *this->base();
|
||||
template <typename W>
|
||||
bool operator==(const iterator_base<W>& rhs) {
|
||||
return m_iterator == rhs.m_iterator;
|
||||
}
|
||||
|
||||
template <typename W>
|
||||
bool operator!=(const iterator_base<W>& rhs) {
|
||||
return m_iterator != rhs.m_iterator;
|
||||
}
|
||||
|
||||
value_type operator*() const {
|
||||
const typename base_type::value_type& v = *m_iterator;
|
||||
if (v.pNode)
|
||||
return value_type(Node(*v, m_pMemory));
|
||||
if (v.first && v.second)
|
||||
@@ -56,7 +79,10 @@ class iterator_base
|
||||
return value_type();
|
||||
}
|
||||
|
||||
proxy operator->() const { return proxy(**this); }
|
||||
|
||||
private:
|
||||
base_type m_iterator;
|
||||
shared_memory_holder m_pMemory;
|
||||
};
|
||||
}
|
||||
|
@@ -13,13 +13,14 @@
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include "yaml-cpp/node/detail/node_ref.h"
|
||||
#include <set>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
class node : private boost::noncopyable {
|
||||
class node {
|
||||
public:
|
||||
node() : m_pRef(new node_ref) {}
|
||||
node(const node&) = delete;
|
||||
node& operator=(const node&) = delete;
|
||||
|
||||
bool is(const node& rhs) const { return m_pRef == rhs.m_pRef; }
|
||||
const node_ref* ref() const { return m_pRef.get(); }
|
||||
@@ -65,9 +66,7 @@ class node : private boost::noncopyable {
|
||||
m_pRef->set_data(*rhs.m_pRef);
|
||||
}
|
||||
|
||||
void set_mark(const Mark& mark) {
|
||||
m_pRef->set_mark(mark);
|
||||
}
|
||||
void set_mark(const Mark& mark) { m_pRef->set_mark(mark); }
|
||||
|
||||
void set_type(NodeType::value type) {
|
||||
if (type != NodeType::Undefined)
|
||||
|
@@ -7,8 +7,6 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -29,9 +27,11 @@ class node;
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
class YAML_CPP_API node_data : private boost::noncopyable {
|
||||
class YAML_CPP_API node_data {
|
||||
public:
|
||||
node_data();
|
||||
node_data(const node_data&) = delete;
|
||||
node_data& operator=(const node_data&) = delete;
|
||||
|
||||
void mark_defined();
|
||||
void set_mark(const Mark& mark);
|
||||
|
@@ -9,8 +9,9 @@
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -52,12 +53,20 @@ struct node_iterator_type<const V> {
|
||||
|
||||
template <typename V>
|
||||
class node_iterator_base
|
||||
: public boost::iterator_facade<
|
||||
node_iterator_base<V>, node_iterator_value<V>,
|
||||
std::forward_iterator_tag, node_iterator_value<V> > {
|
||||
: public std::iterator<std::forward_iterator_tag, node_iterator_value<V>,
|
||||
std::ptrdiff_t, node_iterator_value<V>*,
|
||||
node_iterator_value<V> > {
|
||||
private:
|
||||
struct enabler {};
|
||||
|
||||
struct proxy {
|
||||
explicit proxy(const node_iterator_value<V>& x) : m_ref(x) {}
|
||||
node_iterator_value<V>* operator->() { return std::addressof(m_ref); }
|
||||
operator node_iterator_value<V>*() { return std::addressof(m_ref); }
|
||||
|
||||
node_iterator_value<V> m_ref;
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename node_iterator_type<V>::seq SeqIter;
|
||||
typedef typename node_iterator_type<V>::map MapIter;
|
||||
@@ -80,20 +89,18 @@ class node_iterator_base
|
||||
|
||||
template <typename W>
|
||||
node_iterator_base(const node_iterator_base<W>& rhs,
|
||||
typename boost::enable_if<boost::is_convertible<W*, V*>,
|
||||
enabler>::type = enabler())
|
||||
typename std::enable_if<std::is_convertible<W*, V*>::value,
|
||||
enabler>::type = enabler())
|
||||
: m_type(rhs.m_type),
|
||||
m_seqIt(rhs.m_seqIt),
|
||||
m_mapIt(rhs.m_mapIt),
|
||||
m_mapEnd(rhs.m_mapEnd) {}
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
template <typename>
|
||||
friend class node_iterator_base;
|
||||
|
||||
template <typename W>
|
||||
bool equal(const node_iterator_base<W>& rhs) const {
|
||||
bool operator==(const node_iterator_base<W>& rhs) const {
|
||||
if (m_type != rhs.m_type)
|
||||
return false;
|
||||
|
||||
@@ -108,7 +115,12 @@ class node_iterator_base
|
||||
return true;
|
||||
}
|
||||
|
||||
void increment() {
|
||||
template <typename W>
|
||||
bool operator!=(const node_iterator_base<W>& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
node_iterator_base<V>& operator++() {
|
||||
switch (m_type) {
|
||||
case iterator_type::None:
|
||||
break;
|
||||
@@ -120,9 +132,16 @@ class node_iterator_base
|
||||
m_mapIt = increment_until_defined(m_mapIt);
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
value_type dereference() const {
|
||||
node_iterator_base<V> operator++(int) {
|
||||
node_iterator_base<V> iterator_pre(*this);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
value_type operator*() const {
|
||||
switch (m_type) {
|
||||
case iterator_type::None:
|
||||
return value_type();
|
||||
@@ -134,6 +153,8 @@ class node_iterator_base
|
||||
return value_type();
|
||||
}
|
||||
|
||||
proxy operator->() const { return proxy(**this); }
|
||||
|
||||
MapIter increment_until_defined(MapIter it) {
|
||||
while (it != m_mapEnd && !is_defined(it))
|
||||
++it;
|
||||
|
@@ -11,13 +11,14 @@
|
||||
#include "yaml-cpp/node/type.h"
|
||||
#include "yaml-cpp/node/ptr.h"
|
||||
#include "yaml-cpp/node/detail/node_data.h"
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
class node_ref : private boost::noncopyable {
|
||||
class node_ref {
|
||||
public:
|
||||
node_ref() : m_pData(new node_data) {}
|
||||
node_ref(const node_ref&) = delete;
|
||||
node_ref& operator=(const node_ref&) = delete;
|
||||
|
||||
bool is_defined() const { return m_pData->is_defined(); }
|
||||
const Mark& mark() const { return m_pData->mark(); }
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#endif
|
||||
|
||||
#include "yaml-cpp/dll.h"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
@@ -18,11 +18,11 @@ class node_data;
|
||||
class memory;
|
||||
class memory_holder;
|
||||
|
||||
typedef boost::shared_ptr<node> shared_node;
|
||||
typedef boost::shared_ptr<node_ref> shared_node_ref;
|
||||
typedef boost::shared_ptr<node_data> shared_node_data;
|
||||
typedef boost::shared_ptr<memory_holder> shared_memory_holder;
|
||||
typedef boost::shared_ptr<memory> shared_memory;
|
||||
typedef std::shared_ptr<node> shared_node;
|
||||
typedef std::shared_ptr<node_ref> shared_node_ref;
|
||||
typedef std::shared_ptr<node_data> shared_node_data;
|
||||
typedef std::shared_ptr<memory_holder> shared_memory_holder;
|
||||
typedef std::shared_ptr<memory> shared_memory;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -40,8 +40,8 @@ class YAML_CPP_API Parser : private noncopyable {
|
||||
void HandleTagDirective(const Token& token);
|
||||
|
||||
private:
|
||||
std::auto_ptr<Scanner> m_pScanner;
|
||||
std::auto_ptr<Directives> m_pDirectives;
|
||||
std::unique_ptr<Scanner> m_pScanner;
|
||||
std::unique_ptr<Directives> m_pDirectives;
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user