From c8b1e9d7c5f569d105ec23a619ce4e59dc4afff7 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 18 Nov 2016 14:26:23 +0100 Subject: [PATCH] remove node_ref, use node_data directly --- include/yaml-cpp/node/detail/node.h | 20 ++--- include/yaml-cpp/node/detail/node_data.h | 1 + include/yaml-cpp/node/detail/node_ref.h | 98 ------------------------ include/yaml-cpp/node/impl.h | 4 +- include/yaml-cpp/node/node.h | 2 +- include/yaml-cpp/node/ptr.h | 2 - src/nodeevents.h | 4 +- 7 files changed, 16 insertions(+), 115 deletions(-) delete mode 100644 include/yaml-cpp/node/detail/node_ref.h diff --git a/include/yaml-cpp/node/detail/node.h b/include/yaml-cpp/node/detail/node.h index 3154a52..77d1859 100644 --- a/include/yaml-cpp/node/detail/node.h +++ b/include/yaml-cpp/node/detail/node.h @@ -11,19 +11,19 @@ #include "yaml-cpp/dll.h" #include "yaml-cpp/node/type.h" #include "yaml-cpp/node/ptr.h" -#include "yaml-cpp/node/detail/node_ref.h" +#include "yaml-cpp/node/detail/node_data.h" #include namespace YAML { namespace detail { class node { public: - node() : m_pRef(new node_ref) {} + node() : m_pRef(new node_data) {} 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(); } + const node_data* ref() const { return m_pRef.get(); } bool is_defined() const { return m_pRef->is_defined(); } const Mark& mark() const { return m_pRef->mark(); } @@ -60,10 +60,10 @@ class node { mark_defined(); m_pRef = rhs.m_pRef; } - void set_data(const node& rhs) { + void set_data(node&& rhs) { if (rhs.is_defined()) mark_defined(); - m_pRef->set_data(*rhs.m_pRef); + m_pRef = std::move(rhs.m_pRef); } void set_mark(const Mark& mark) { m_pRef->set_mark(mark); } @@ -96,12 +96,12 @@ class node { std::size_t size() const { return m_pRef->size(); } const_node_iterator begin() const { - return static_cast(*m_pRef).begin(); + return static_cast(*m_pRef).begin(); } node_iterator begin() { return m_pRef->begin(); } const_node_iterator end() const { - return static_cast(*m_pRef).end(); + return static_cast(*m_pRef).end(); } node_iterator end() { return m_pRef->end(); } @@ -122,7 +122,7 @@ class node { // NOTE: this returns a non-const node so that the top-level Node can wrap // it, and returns a pointer so that it can be NULL (if there is no such // key). - return static_cast(*m_pRef).get(key, pMemory); + return static_cast(*m_pRef).get(key, pMemory); } template node& get(const Key& key, shared_memory_holder pMemory) { @@ -139,7 +139,7 @@ class node { // NOTE: this returns a non-const node so that the top-level Node can wrap // it, and returns a pointer so that it can be NULL (if there is no such // key). - return static_cast(*m_pRef).get(key, pMemory); + return static_cast(*m_pRef).get(key, pMemory); } node& get(node& key, shared_memory_holder pMemory) { node& value = m_pRef->get(key, pMemory); @@ -159,7 +159,7 @@ class node { } private: - shared_node_ref m_pRef; + shared_node_data m_pRef; typedef std::set nodes; nodes m_dependencies; }; diff --git a/include/yaml-cpp/node/detail/node_data.h b/include/yaml-cpp/node/detail/node_data.h index 50bcd74..01cf7d4 100644 --- a/include/yaml-cpp/node/detail/node_data.h +++ b/include/yaml-cpp/node/detail/node_data.h @@ -32,6 +32,7 @@ class YAML_CPP_API node_data { node_data(); node_data(const node_data&) = delete; node_data& operator=(const node_data&) = delete; + node_data& operator=(node_data&&) = default; 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 deleted file mode 100644 index d8a94f8..0000000 --- a/include/yaml-cpp/node/detail/node_ref.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 -#define VALUE_DETAIL_NODE_REF_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 "yaml-cpp/dll.h" -#include "yaml-cpp/node/type.h" -#include "yaml-cpp/node/ptr.h" -#include "yaml-cpp/node/detail/node_data.h" - -namespace YAML { -namespace detail { -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(); } - NodeType::value type() const { return m_pData->type(); } - const std::string& scalar() const { return m_pData->scalar(); } - const std::string& tag() const { return m_pData->tag(); } - EmitterStyle::value style() const { return m_pData->style(); } - - void mark_defined() { m_pData->mark_defined(); } - void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; } - - void set_mark(const Mark& mark) { m_pData->set_mark(mark); } - void set_type(NodeType::value type) { m_pData->set_type(type); } - void set_tag(const std::string& tag) { m_pData->set_tag(tag); } - void set_null() { m_pData->set_null(); } - void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); } - void set_style(EmitterStyle::value style) { m_pData->set_style(style); } - - // size/iterator - std::size_t size() const { return m_pData->size(); } - - const_node_iterator begin() const { - return static_cast(*m_pData).begin(); - } - node_iterator begin() { return m_pData->begin(); } - - const_node_iterator end() const { - return static_cast(*m_pData).end(); - } - node_iterator end() { return m_pData->end(); } - - // sequence - void push_back(node& node, shared_memory_holder pMemory) { - m_pData->push_back(node, pMemory); - } - void insert(node& key, node& value, shared_memory_holder pMemory) { - m_pData->insert(key, value, pMemory); - } - - // indexing - template - node* get(const Key& key, shared_memory_holder pMemory) const { - return static_cast(*m_pData).get(key, pMemory); - } - template - node& get(const Key& key, shared_memory_holder pMemory) { - return m_pData->get(key, pMemory); - } - template - bool remove(const Key& key, shared_memory_holder pMemory) { - return m_pData->remove(key, pMemory); - } - - node* get(node& key, shared_memory_holder pMemory) const { - return static_cast(*m_pData).get(key, pMemory); - } - node& get(node& key, shared_memory_holder pMemory) { - return m_pData->get(key, pMemory); - } - bool remove(node& key, shared_memory_holder pMemory) { - return m_pData->remove(key, pMemory); - } - - // map - template - void force_insert(const Key& key, const Value& value, - shared_memory_holder pMemory) { - m_pData->force_insert(key, value, pMemory); - } - - private: - shared_node_data m_pData; -}; -} -} - -#endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index 20c487a..68cc582 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -247,13 +247,13 @@ inline Node& Node::operator=(const Node& rhs) { return *this; } -inline void Node::AssignData(const Node& rhs) { +inline void Node::AssignData(Node&& rhs) { if (!m_isValid || !rhs.m_isValid) throw InvalidNode(); EnsureNodeExists(); rhs.EnsureNodeExists(); - m_pNode->set_data(*rhs.m_pNode); + m_pNode->set_data(std::move(*rhs.m_pNode)); m_pMemory->merge(*rhs.m_pMemory); } diff --git a/include/yaml-cpp/node/node.h b/include/yaml-cpp/node/node.h index 1ded7d2..4e515d2 100644 --- a/include/yaml-cpp/node/node.h +++ b/include/yaml-cpp/node/node.h @@ -125,7 +125,7 @@ class YAML_CPP_API Node { void Assign(const char* rhs); void Assign(char* rhs); - void AssignData(const Node& rhs); + void AssignData(Node&& rhs); void AssignNode(const Node& rhs); private: diff --git a/include/yaml-cpp/node/ptr.h b/include/yaml-cpp/node/ptr.h index ce085dd..6ac80ac 100644 --- a/include/yaml-cpp/node/ptr.h +++ b/include/yaml-cpp/node/ptr.h @@ -13,13 +13,11 @@ namespace YAML { namespace detail { class node; -class node_ref; class node_data; class memory; class memory_holder; 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; diff --git a/src/nodeevents.h b/src/nodeevents.h index 49c18eb..6c26b96 100644 --- a/src/nodeevents.h +++ b/src/nodeevents.h @@ -41,7 +41,7 @@ class NodeEvents { anchor_t _CreateNewAnchor() { return ++m_curAnchor; } private: - typedef std::map AnchorByIdentity; + typedef std::map AnchorByIdentity; AnchorByIdentity m_anchorByIdentity; anchor_t m_curAnchor; @@ -56,7 +56,7 @@ class NodeEvents { detail::shared_memory_holder m_pMemory; detail::node* m_root; - typedef std::map RefCount; + typedef std::map RefCount; RefCount m_refCount; }; }