From 3d3c468ddb9fedd63466a49d0abc7259c2629a9a Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 16:58:38 -0400 Subject: [PATCH 01/21] Add to compiler flags --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1897775..f68ebff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,7 +177,7 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}") endif() # - set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${yaml_cxx_flags}") + set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long -std=c++11 ${yaml_cxx_flags}") ### Make specific if(${CMAKE_BUILD_TOOL} MATCHES make OR ${CMAKE_BUILD_TOOL} MATCHES gmake) From 79952950384e600e961a3018ada702176e7abf0f Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 17:14:42 -0400 Subject: [PATCH 02/21] Remove use of 'boost/type_traits.h' --- include/yaml-cpp/node/detail/impl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index f6d218c..e419827 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -9,7 +9,7 @@ #include "yaml-cpp/node/detail/node.h" #include "yaml-cpp/node/detail/node_data.h" -#include +#include namespace YAML { namespace detail { @@ -23,8 +23,8 @@ struct get_idx { template struct get_idx< - Key, typename boost::enable_if_c::value && - !boost::is_same::value>::type> { + Key, typename std::enable_if::value && + !std::is_same::value>::type> { static node* get(const std::vector& sequence, const Key& key, shared_memory_holder /* pMemory */) { return key < sequence.size() ? sequence[key] : 0; @@ -41,7 +41,7 @@ struct get_idx< }; template -struct get_idx >::type> { +struct get_idx::value >::type> { static node* get(const std::vector& sequence, const Key& key, shared_memory_holder pMemory) { return key >= 0 ? get_idx::get( From 1b9796cec5a83d35d2a0efe393beca13ed7747cd Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 17:18:09 -0400 Subject: [PATCH 03/21] Remove use of 'boost/shared_ptr.h' --- include/yaml-cpp/node/detail/memory.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/yaml-cpp/node/detail/memory.h b/include/yaml-cpp/node/detail/memory.h index e3d344b..3e6f083 100644 --- a/include/yaml-cpp/node/detail/memory.h +++ b/include/yaml-cpp/node/detail/memory.h @@ -7,8 +7,7 @@ #pragma once #endif -#include -#include +#include #include #include "yaml-cpp/dll.h" @@ -40,7 +39,7 @@ class YAML_CPP_API memory_holder { void merge(memory_holder& rhs); private: - boost::shared_ptr m_pMemory; + std::shared_ptr m_pMemory; }; } } From 52903e89a1fb75afd0e710f36c218c7d029b9b67 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 17:27:33 -0400 Subject: [PATCH 04/21] Replace boost::noncopyable with deleted copy and assignment --- include/yaml-cpp/node/detail/node.h | 5 +++-- include/yaml-cpp/node/detail/node_data.h | 6 +++--- include/yaml-cpp/node/detail/node_ref.h | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/yaml-cpp/node/detail/node.h b/include/yaml-cpp/node/detail/node.h index bbb497d..5f26738 100644 --- a/include/yaml-cpp/node/detail/node.h +++ b/include/yaml-cpp/node/detail/node.h @@ -13,13 +13,14 @@ #include "yaml-cpp/node/ptr.h" #include "yaml-cpp/node/detail/node_ref.h" #include -#include 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(); } diff --git a/include/yaml-cpp/node/detail/node_data.h b/include/yaml-cpp/node/detail/node_data.h index 6030867..64bbc05 100644 --- a/include/yaml-cpp/node/detail/node_data.h +++ b/include/yaml-cpp/node/detail/node_data.h @@ -7,8 +7,6 @@ #pragma once #endif -#include -#include #include #include #include @@ -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); diff --git a/include/yaml-cpp/node/detail/node_ref.h b/include/yaml-cpp/node/detail/node_ref.h index 26b1872..d8a94f8 100644 --- a/include/yaml-cpp/node/detail/node_ref.h +++ b/include/yaml-cpp/node/detail/node_ref.h @@ -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 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(); } From aa30edb3aafd70cf3f842a1c163b849c9f0246cd Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 17:31:30 -0400 Subject: [PATCH 05/21] Remove use of 'boost/shared_ptr.h' --- include/yaml-cpp/node/ptr.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/yaml-cpp/node/ptr.h b/include/yaml-cpp/node/ptr.h index 64c8689..ce085dd 100644 --- a/include/yaml-cpp/node/ptr.h +++ b/include/yaml-cpp/node/ptr.h @@ -8,7 +8,7 @@ #endif #include "yaml-cpp/dll.h" -#include +#include namespace YAML { namespace detail { @@ -18,11 +18,11 @@ class node_data; class memory; class memory_holder; -typedef boost::shared_ptr shared_node; -typedef boost::shared_ptr shared_node_ref; -typedef boost::shared_ptr shared_node_data; -typedef boost::shared_ptr shared_memory_holder; -typedef boost::shared_ptr shared_memory; +typedef std::shared_ptr shared_node; +typedef std::shared_ptr shared_node_ref; +typedef std::shared_ptr shared_node_data; +typedef std::shared_ptr shared_memory_holder; +typedef std::shared_ptr shared_memory; } } From 86610fcb75ca5e9b71d44350adaab21445a42b79 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 17:36:52 -0400 Subject: [PATCH 06/21] Replace boost::next with std::next --- src/node_data.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_data.cpp b/src/node_data.cpp index a1ca900..46e1463 100644 --- a/src/node_data.cpp +++ b/src/node_data.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include "yaml-cpp/exceptions.h" @@ -104,7 +104,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; From 3dc430e74a87167422728ea5f06cf5a5f9c827d8 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 18:03:23 -0400 Subject: [PATCH 07/21] Remove usages of boost::enable_if and boost::next --- include/yaml-cpp/node/detail/iterator.h | 5 ++--- include/yaml-cpp/node/detail/node_iterator.h | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index 2c701af..d170f81 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -11,7 +11,6 @@ #include "yaml-cpp/node/ptr.h" #include "yaml-cpp/node/detail/node_iterator.h" #include -#include namespace YAML { namespace detail { @@ -37,7 +36,7 @@ class iterator_base template iterator_base(const iterator_base& rhs, - typename boost::enable_if, + typename std::enable_if::value, enabler>::type = enabler()) : iterator_base::iterator_adaptor_(rhs.base()), m_pMemory(rhs.m_pMemory) {} @@ -45,7 +44,7 @@ class iterator_base private: friend class boost::iterator_core_access; - void increment() { this->base_reference() = boost::next(this->base()); } + void increment() { this->base_reference() = std::next(this->base()); } value_type dereference() const { const typename base_type::value_type& v = *this->base(); diff --git a/include/yaml-cpp/node/detail/node_iterator.h b/include/yaml-cpp/node/detail/node_iterator.h index 9669c81..1fa45f8 100644 --- a/include/yaml-cpp/node/detail/node_iterator.h +++ b/include/yaml-cpp/node/detail/node_iterator.h @@ -10,7 +10,6 @@ #include "yaml-cpp/dll.h" #include "yaml-cpp/node/ptr.h" #include -#include #include #include #include @@ -80,7 +79,7 @@ class node_iterator_base template node_iterator_base(const node_iterator_base& rhs, - typename boost::enable_if, + typename std::enable_if::value, enabler>::type = enabler()) : m_type(rhs.m_type), m_seqIt(rhs.m_seqIt), From dc3e416bb918848ec3a51bd1f3c611fb5e86fdd0 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 18:51:58 -0400 Subject: [PATCH 08/21] Add 'std=c++11' to test compiler flags --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 61f1f7f..cf06c9a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,7 +10,7 @@ endif() if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(yaml_test_flags "-Wno-c99-extensions -Wno-variadic-macros -Wno-sign-compare") + set(yaml_test_flags "-Wno-c99-extensions -Wno-variadic-macros -Wno-sign-compare -std=c++11") endif() file(GLOB test_headers [a-z_]*.h) From 7c26845bb47bffeb53b4cc28fd8881690088cda6 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Mon, 27 Apr 2015 19:23:54 -0400 Subject: [PATCH 09/21] Replace 'boost::is_convertible' with 'std::is_convertible' --- include/yaml-cpp/node/detail/iterator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index d170f81..8e82576 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -36,7 +36,7 @@ class iterator_base template iterator_base(const iterator_base& rhs, - typename std::enable_if::value, + typename std::enable_if::value, enabler>::type = enabler()) : iterator_base::iterator_adaptor_(rhs.base()), m_pMemory(rhs.m_pMemory) {} From f09c4b44e17944b32534ce499dc0ad660788a048 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Wed, 29 Apr 2015 17:47:30 -0400 Subject: [PATCH 10/21] Replace iterator_facade and iterator_adaptor with std iterators Borrows the 'proxy reference' technique used in the boost templates --- include/yaml-cpp/node/detail/iterator.h | 43 ++++++++++++++------ include/yaml-cpp/node/detail/node_iterator.h | 35 ++++++++++++---- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index 8e82576..7d2a398 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -10,7 +10,7 @@ #include "yaml-cpp/dll.h" #include "yaml-cpp/node/ptr.h" #include "yaml-cpp/node/detail/node_iterator.h" -#include +#include namespace YAML { namespace detail { @@ -18,13 +18,21 @@ struct iterator_value; template class iterator_base - : public boost::iterator_adaptor, node_iterator, V, - std::forward_iterator_tag, V> { + : public std::iterator { + private: template 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; @@ -32,22 +40,28 @@ class iterator_base public: iterator_base() {} 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 iterator_base(const iterator_base& rhs, typename std::enable_if::value, enabler>::type = enabler()) - : iterator_base::iterator_adaptor_(rhs.base()), - m_pMemory(rhs.m_pMemory) {} + : m_iterator(rhs.m_iterator), m_pMemory(rhs.m_pMemory) {} - private: - friend class boost::iterator_core_access; + iterator_base& operator++() { ++m_iterator; return *this; } - void increment() { this->base_reference() = std::next(this->base()); } + template + bool operator==(const iterator_base& rhs) { + return m_iterator == rhs.m_iterator; + } - value_type dereference() const { - const typename base_type::value_type& v = *this->base(); + template + bool operator!=(const iterator_base& 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) @@ -55,7 +69,12 @@ class iterator_base return value_type(); } + value_type* operator->() const { + return proxy(**this); + } + private: + base_type m_iterator; shared_memory_holder m_pMemory; }; } diff --git a/include/yaml-cpp/node/detail/node_iterator.h b/include/yaml-cpp/node/detail/node_iterator.h index 1fa45f8..00b8804 100644 --- a/include/yaml-cpp/node/detail/node_iterator.h +++ b/include/yaml-cpp/node/detail/node_iterator.h @@ -9,7 +9,8 @@ #include "yaml-cpp/dll.h" #include "yaml-cpp/node/ptr.h" -#include +#include +#include #include #include #include @@ -51,12 +52,20 @@ struct node_iterator_type { template class node_iterator_base - : public boost::iterator_facade< - node_iterator_base, node_iterator_value, - std::forward_iterator_tag, node_iterator_value > { + : public std::iterator< + std::forward_iterator_tag, node_iterator_value, + ptrdiff_t, node_iterator_value*, node_iterator_value > { private: struct enabler {}; + struct proxy { + explicit proxy(const node_iterator_value& x) : m_ref(x) {} + node_iterator_value* operator->() { return std::addressof(m_ref); } + operator node_iterator_value*() { return std::addressof(m_ref); } + + node_iterator_value m_ref; + }; + public: typedef typename node_iterator_type::seq SeqIter; typedef typename node_iterator_type::map MapIter; @@ -86,13 +95,11 @@ class node_iterator_base m_mapIt(rhs.m_mapIt), m_mapEnd(rhs.m_mapEnd) {} - private: - friend class boost::iterator_core_access; template friend class node_iterator_base; template - bool equal(const node_iterator_base& rhs) const { + bool operator==(const node_iterator_base& rhs) const { if (m_type != rhs.m_type) return false; @@ -107,7 +114,12 @@ class node_iterator_base return true; } - void increment() { + template + bool operator!=(const node_iterator_base& rhs) const { + return !(*this==rhs); + } + + node_iterator_base& operator++() { switch (m_type) { case iterator_type::None: break; @@ -119,9 +131,10 @@ class node_iterator_base m_mapIt = increment_until_defined(m_mapIt); break; } + return *this; } - value_type dereference() const { + value_type operator*() const { switch (m_type) { case iterator_type::None: return value_type(); @@ -133,6 +146,10 @@ class node_iterator_base return value_type(); } + value_type* operator->() const { + return proxy(**this); + } + MapIter increment_until_defined(MapIter it) { while (it != m_mapEnd && !is_defined(it)) ++it; From 4942ca572a4c270b9e1bbcd3ac6d016efcd4db55 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Wed, 29 Apr 2015 17:48:36 -0400 Subject: [PATCH 11/21] Remove Boost requirement from CMakeLists --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f68ebff..e7cf632 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,6 @@ endif() include_directories(${YAML_CPP_SOURCE_DIR}/src) include_directories(${YAML_CPP_SOURCE_DIR}/include) -find_package(Boost REQUIRED) -include_directories(${Boost_INCLUDE_DIRS}) ### From 6c7fddebbbbebdaedf3a3098ebddc07fb9640cf7 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Thu, 30 Apr 2015 14:19:40 -0400 Subject: [PATCH 12/21] Replace ptrdiff_t with std::ptrdiff_t --- include/yaml-cpp/node/detail/iterator.h | 3 ++- include/yaml-cpp/node/detail/node_iterator.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index 7d2a398..a3721b2 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -11,6 +11,7 @@ #include "yaml-cpp/node/ptr.h" #include "yaml-cpp/node/detail/node_iterator.h" #include +#include namespace YAML { namespace detail { @@ -18,7 +19,7 @@ struct iterator_value; template class iterator_base - : public std::iterator { + : public std::iterator { private: template diff --git a/include/yaml-cpp/node/detail/node_iterator.h b/include/yaml-cpp/node/detail/node_iterator.h index 00b8804..4622fd0 100644 --- a/include/yaml-cpp/node/detail/node_iterator.h +++ b/include/yaml-cpp/node/detail/node_iterator.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace YAML { namespace detail { @@ -54,7 +55,7 @@ template class node_iterator_base : public std::iterator< std::forward_iterator_tag, node_iterator_value, - ptrdiff_t, node_iterator_value*, node_iterator_value > { + std::ptrdiff_t, node_iterator_value*, node_iterator_value > { private: struct enabler {}; From 748148a81d33d9464f9efebaa5a8b4aec80b3391 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Thu, 30 Apr 2015 14:20:38 -0400 Subject: [PATCH 13/21] Add -std=c++11 to util build flags --- util/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 8a69631..2286627 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,11 +1,14 @@ add_sources(parse.cpp) add_executable(parse parse.cpp) target_link_libraries(parse yaml-cpp) +set_target_properties(parse PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(sandbox.cpp) add_executable(sandbox sandbox.cpp) target_link_libraries(sandbox yaml-cpp) +set_target_properties(sandbox PROPERTIES COMPILE_FLAGS "-std=c++11") add_sources(read.cpp) add_executable(read read.cpp) target_link_libraries(read yaml-cpp) +set_target_properties(read PROPERTIES COMPILE_FLAGS "-std=c++11") From c78d19bdccc3ac0a97da9bdbd4398165a0f4b4b7 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Thu, 30 Apr 2015 15:57:44 -0400 Subject: [PATCH 14/21] Initialize iterator_base members --- include/yaml-cpp/node/detail/iterator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index a3721b2..9338d53 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -39,7 +39,7 @@ class iterator_base 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) : m_iterator(rhs), m_pMemory(pMemory) {} From 012baa7d620eb7e04a575a8d900adf1d3a8f5c11 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Thu, 7 May 2015 13:11:47 -0400 Subject: [PATCH 15/21] Fix operator-> for iterators The proxy reference pattern used in Boost iterators to provide pointers to temporary values requires that -> actually returns a 'proxy' object that further has -> applied in the calling scope --- include/yaml-cpp/node/detail/iterator.h | 2 +- include/yaml-cpp/node/detail/node_iterator.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index 9338d53..ac762ad 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -70,7 +70,7 @@ class iterator_base return value_type(); } - value_type* operator->() const { + proxy operator->() const { return proxy(**this); } diff --git a/include/yaml-cpp/node/detail/node_iterator.h b/include/yaml-cpp/node/detail/node_iterator.h index 4622fd0..fffe3d7 100644 --- a/include/yaml-cpp/node/detail/node_iterator.h +++ b/include/yaml-cpp/node/detail/node_iterator.h @@ -147,7 +147,7 @@ class node_iterator_base return value_type(); } - value_type* operator->() const { + proxy operator->() const { return proxy(**this); } From 2703ef784ddc0a5e488d77a7ed8dd8831b64b868 Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Thu, 7 May 2015 13:26:01 -0400 Subject: [PATCH 16/21] clang-format --- include/yaml-cpp/node/detail/impl.h | 8 ++++---- include/yaml-cpp/node/detail/iterator.h | 15 ++++++++------- include/yaml-cpp/node/detail/node.h | 4 +--- include/yaml-cpp/node/detail/node_iterator.h | 14 ++++++-------- src/node_data.cpp | 4 +--- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index e419827..69f4476 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -22,9 +22,9 @@ struct get_idx { }; template -struct get_idx< - Key, typename std::enable_if::value && - !std::is_same::value>::type> { +struct get_idx::value && + !std::is_same::value>::type> { static node* get(const std::vector& sequence, const Key& key, shared_memory_holder /* pMemory */) { return key < sequence.size() ? sequence[key] : 0; @@ -41,7 +41,7 @@ struct get_idx< }; template -struct get_idx::value >::type> { +struct get_idx::value>::type> { static node* get(const std::vector& sequence, const Key& key, shared_memory_holder pMemory) { return key >= 0 ? get_idx::get( diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index ac762ad..a859449 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -18,8 +18,8 @@ namespace detail { struct iterator_value; template -class iterator_base - : public std::iterator { +class iterator_base : public std::iterator { private: template @@ -46,10 +46,13 @@ class iterator_base template iterator_base(const iterator_base& rhs, typename std::enable_if::value, - enabler>::type = enabler()) + enabler>::type = enabler()) : m_iterator(rhs.m_iterator), m_pMemory(rhs.m_pMemory) {} - iterator_base& operator++() { ++m_iterator; return *this; } + iterator_base& operator++() { + ++m_iterator; + return *this; + } template bool operator==(const iterator_base& rhs) { @@ -70,9 +73,7 @@ class iterator_base return value_type(); } - proxy operator->() const { - return proxy(**this); - } + proxy operator->() const { return proxy(**this); } private: base_type m_iterator; diff --git a/include/yaml-cpp/node/detail/node.h b/include/yaml-cpp/node/detail/node.h index 5f26738..3154a52 100644 --- a/include/yaml-cpp/node/detail/node.h +++ b/include/yaml-cpp/node/detail/node.h @@ -66,9 +66,7 @@ class node { 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) diff --git a/include/yaml-cpp/node/detail/node_iterator.h b/include/yaml-cpp/node/detail/node_iterator.h index fffe3d7..4734b6d 100644 --- a/include/yaml-cpp/node/detail/node_iterator.h +++ b/include/yaml-cpp/node/detail/node_iterator.h @@ -53,9 +53,9 @@ struct node_iterator_type { template class node_iterator_base - : public std::iterator< - std::forward_iterator_tag, node_iterator_value, - std::ptrdiff_t, node_iterator_value*, node_iterator_value > { + : public std::iterator, + std::ptrdiff_t, node_iterator_value*, + node_iterator_value > { private: struct enabler {}; @@ -90,7 +90,7 @@ class node_iterator_base template node_iterator_base(const node_iterator_base& rhs, typename std::enable_if::value, - enabler>::type = enabler()) + enabler>::type = enabler()) : m_type(rhs.m_type), m_seqIt(rhs.m_seqIt), m_mapIt(rhs.m_mapIt), @@ -117,7 +117,7 @@ class node_iterator_base template bool operator!=(const node_iterator_base& rhs) const { - return !(*this==rhs); + return !(*this == rhs); } node_iterator_base& operator++() { @@ -147,9 +147,7 @@ class node_iterator_base return value_type(); } - proxy operator->() const { - return proxy(**this); - } + proxy operator->() const { return proxy(**this); } MapIter increment_until_defined(MapIter it) { while (it != m_mapEnd && !is_defined(it)) diff --git a/src/node_data.cpp b/src/node_data.cpp index 46e1463..a862946 100644 --- a/src/node_data.cpp +++ b/src/node_data.cpp @@ -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) { From bdfb87b461234c7614f615da7127f41d3f8dd25c Mon Sep 17 00:00:00 2001 From: "U.G. Wilson" Date: Tue, 26 May 2015 17:13:50 -0500 Subject: [PATCH 17/21] Repalced auto_ptr with unique_ptr. --- include/yaml-cpp/emitter.h | 2 +- include/yaml-cpp/parser.h | 4 ++-- src/emitterstate.cpp | 4 ++-- src/ptr_stack.h | 6 +++--- src/ptr_vector.h | 2 +- src/scanner.cpp | 4 ++-- src/setting.h | 10 +++++----- src/singledocparser.h | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/yaml-cpp/emitter.h b/include/yaml-cpp/emitter.h index cc49659..5bffc25 100644 --- a/include/yaml-cpp/emitter.h +++ b/include/yaml-cpp/emitter.h @@ -122,7 +122,7 @@ class YAML_CPP_API Emitter : private noncopyable { bool CanEmitNewline() const; private: - std::auto_ptr m_pState; + std::unique_ptr m_pState; ostream_wrapper m_stream; }; diff --git a/include/yaml-cpp/parser.h b/include/yaml-cpp/parser.h index 24880e4..edbfd8f 100644 --- a/include/yaml-cpp/parser.h +++ b/include/yaml-cpp/parser.h @@ -40,8 +40,8 @@ class YAML_CPP_API Parser : private noncopyable { void HandleTagDirective(const Token& token); private: - std::auto_ptr m_pScanner; - std::auto_ptr m_pDirectives; + std::unique_ptr m_pScanner; + std::unique_ptr m_pDirectives; }; } diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index a0874ac..469040f 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -124,7 +124,7 @@ void EmitterState::StartedGroup(GroupType::value type) { const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.top().indent); m_curIndent += lastGroupIndent; - std::auto_ptr pGroup(new Group(type)); + std::unique_ptr pGroup(new Group(type)); // transfer settings (which last until this group is done) pGroup->modifiedSettings = m_modifiedSettings; @@ -149,7 +149,7 @@ void EmitterState::EndedGroup(GroupType::value type) { // get rid of the current group { - std::auto_ptr pFinishedGroup = m_groups.pop(); + std::unique_ptr pFinishedGroup = m_groups.pop(); if (pFinishedGroup->type != type) return SetError(ErrorMsg::UNMATCHED_GROUP_TAG); } diff --git a/src/ptr_stack.h b/src/ptr_stack.h index f378ffc..3757432 100644 --- a/src/ptr_stack.h +++ b/src/ptr_stack.h @@ -29,12 +29,12 @@ class ptr_stack : private YAML::noncopyable { std::size_t size() const { return m_data.size(); } bool empty() const { return m_data.empty(); } - void push(std::auto_ptr t) { + void push(std::unique_ptr &t) { m_data.push_back(NULL); m_data.back() = t.release(); } - std::auto_ptr pop() { - std::auto_ptr t(m_data.back()); + std::unique_ptr pop() { + std::unique_ptr t(m_data.back()); m_data.pop_back(); return t; } diff --git a/src/ptr_vector.h b/src/ptr_vector.h index a546a89..de4f8c4 100644 --- a/src/ptr_vector.h +++ b/src/ptr_vector.h @@ -31,7 +31,7 @@ class ptr_vector : private YAML::noncopyable { std::size_t size() const { return m_data.size(); } bool empty() const { return m_data.empty(); } - void push_back(std::auto_ptr t) { + void push_back(std::unique_ptr &t) { m_data.push_back(NULL); m_data.back() = t.release(); } diff --git a/src/scanner.cpp b/src/scanner.cpp index 680c73b..f89ed9b 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -233,7 +233,7 @@ const RegEx& Scanner::GetValueRegex() const { void Scanner::StartStream() { m_startedStream = true; m_simpleKeyAllowed = true; - std::auto_ptr pIndent(new IndentMarker(-1, IndentMarker::NONE)); + std::unique_ptr pIndent(new IndentMarker(-1, IndentMarker::NONE)); m_indentRefs.push_back(pIndent); m_indents.push(&m_indentRefs.back()); } @@ -281,7 +281,7 @@ Scanner::IndentMarker* Scanner::PushIndentTo(int column, if (InFlowContext()) return 0; - std::auto_ptr pIndent(new IndentMarker(column, type)); + std::unique_ptr pIndent(new IndentMarker(column, type)); IndentMarker& indent = *pIndent; const IndentMarker& lastIndent = *m_indents.top(); diff --git a/src/setting.h b/src/setting.h index 3ff8c20..508193e 100644 --- a/src/setting.h +++ b/src/setting.h @@ -20,7 +20,7 @@ class Setting { Setting() : m_value() {} const T get() const { return m_value; } - std::auto_ptr set(const T& value); + std::unique_ptr set(const T& value); void restore(const Setting& oldSetting) { m_value = oldSetting.get(); } private: @@ -49,8 +49,8 @@ class SettingChange : public SettingChangeBase { }; template -inline std::auto_ptr Setting::set(const T& value) { - std::auto_ptr pChange(new SettingChange(this)); +inline std::unique_ptr Setting::set(const T& value) { + std::unique_ptr pChange(new SettingChange(this)); m_value = value; return pChange; } @@ -75,11 +75,11 @@ class SettingChanges : private noncopyable { (*it)->pop(); } - void push(std::auto_ptr pSettingChange) { + void push(std::unique_ptr pSettingChange) { m_settingChanges.push_back(pSettingChange.release()); } - // like std::auto_ptr - assignment is transfer of ownership + // like std::unique_ptr - assignment is transfer of ownership SettingChanges& operator=(SettingChanges& rhs) { if (this == &rhs) return *this; diff --git a/src/singledocparser.h b/src/singledocparser.h index ed0aad5..2b92067 100644 --- a/src/singledocparser.h +++ b/src/singledocparser.h @@ -53,7 +53,7 @@ class SingleDocParser : private noncopyable { private: Scanner& m_scanner; const Directives& m_directives; - std::auto_ptr m_pCollectionStack; + std::unique_ptr m_pCollectionStack; typedef std::map Anchors; Anchors m_anchors; From 398ec19e817d65f80402e296b395994e01cb67ff Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 3 Jul 2015 15:09:58 +0200 Subject: [PATCH 18/21] convert ptr_stack to unique_ptr --- src/emitterstate.cpp | 2 +- src/ptr_stack.h | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index 469040f..3ea5570 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -136,7 +136,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) { diff --git a/src/ptr_stack.h b/src/ptr_stack.h index 3757432..7767813 100644 --- a/src/ptr_stack.h +++ b/src/ptr_stack.h @@ -18,36 +18,40 @@ template 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::unique_ptr &t) { - m_data.push_back(NULL); - m_data.back() = t.release(); + void push(std::unique_ptr&& t) { + m_data.push_back(std::move(t)); } std::unique_ptr pop() { - std::unique_ptr t(m_data.back()); + std::unique_ptr 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 m_data; + std::vector> m_data; }; #endif // PTR_STACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 From e32999b5995094fd98a063b0a2be6a3eb8e3b788 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 3 Jul 2015 15:10:07 +0200 Subject: [PATCH 19/21] convert ptr_vector to unique_ptr --- src/ptr_vector.h | 19 ++++++++++--------- src/scanner.cpp | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ptr_vector.h b/src/ptr_vector.h index de4f8c4..b592ccd 100644 --- a/src/ptr_vector.h +++ b/src/ptr_vector.h @@ -20,29 +20,30 @@ template 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::unique_ptr &t) { - m_data.push_back(NULL); - m_data.back() = t.release(); + void push_back(std::unique_ptr&& 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 m_data; + std::vector> m_data; }; } diff --git a/src/scanner.cpp b/src/scanner.cpp index f89ed9b..767b8e1 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -234,7 +234,7 @@ void Scanner::StartStream() { m_startedStream = true; m_simpleKeyAllowed = true; std::unique_ptr pIndent(new IndentMarker(-1, IndentMarker::NONE)); - m_indentRefs.push_back(pIndent); + m_indentRefs.push_back(std::move(pIndent)); m_indents.push(&m_indentRefs.back()); } @@ -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(); } From a7c6cdcbc166966db05a568fcf1840a9c3d671cb Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 3 Jul 2015 15:22:56 +0200 Subject: [PATCH 20/21] use unique_ptr in SettingChanges --- src/emitterstate.cpp | 5 ++++- src/setting.h | 12 ++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index 3ea5570..124dc1c 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -127,7 +127,10 @@ void EmitterState::StartedGroup(GroupType::value type) { std::unique_ptr 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) diff --git a/src/setting.h b/src/setting.h index 508193e..5f09d1d 100644 --- a/src/setting.h +++ b/src/setting.h @@ -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(); } @@ -76,22 +72,22 @@ class SettingChanges : private noncopyable { } void push(std::unique_ptr pSettingChange) { - m_settingChanges.push_back(pSettingChange.release()); + m_settingChanges.push_back(std::move(pSettingChange)); } // like std::unique_ptr - assignment is transfer of ownership - SettingChanges& operator=(SettingChanges& rhs) { + SettingChanges& operator=(SettingChanges&& rhs) { if (this == &rhs) return *this; clear(); - m_settingChanges = rhs.m_settingChanges; + m_settingChanges = std::move(rhs.m_settingChanges); rhs.m_settingChanges.clear(); return *this; } private: - typedef std::vector setting_changes; + typedef std::vector> setting_changes; setting_changes m_settingChanges; }; } From efbb4c20f6124aa19f3dd9f6f0cea1d9faee8ef5 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 3 Jul 2015 15:37:55 +0200 Subject: [PATCH 21/21] swap cleared settings vector --- src/setting.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setting.h b/src/setting.h index 5f09d1d..b78d40e 100644 --- a/src/setting.h +++ b/src/setting.h @@ -81,8 +81,8 @@ class SettingChanges : private noncopyable { return *this; clear(); - m_settingChanges = std::move(rhs.m_settingChanges); - rhs.m_settingChanges.clear(); + std::swap(m_settingChanges, rhs.m_settingChanges); + return *this; }