From 7c7bf899b795a541bafe7d843a510b971125b498 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Tue, 21 Jun 2016 14:33:30 +0200 Subject: [PATCH] implement move - copy constructor seems to be broken! --- include/yaml-cpp/node/impl.h | 24 ++++++++++++++++++++++++ include/yaml-cpp/node/node.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index 50af6b6..666bb02 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -42,6 +42,16 @@ inline Node::Node(const Node& rhs) m_pMemory(rhs.m_pMemory), m_pNode(rhs.m_pNode) {} +inline Node::Node(Node&& rhs) + : m_isValid(rhs.m_isValid), + m_pMemory(rhs.m_pMemory), + m_pNode(rhs.m_pNode) { + + rhs.m_pMemory.reset(new detail::memory_holder); + rhs.m_pNode = &rhs.m_pMemory->create_node(); + rhs.m_pNode->set_null(); +} + inline Node::Node(Zombie) : m_isValid(false), m_pNode(NULL) {} inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory) @@ -247,6 +257,20 @@ inline Node& Node::operator=(const Node& rhs) { return *this; } +inline Node& Node::operator=(Node&& rhs) { + if (!m_isValid || !rhs.m_isValid) + throw InvalidNode(); + if (is(rhs)) + return *this; + AssignNode(rhs); + + rhs.m_pMemory.reset(new detail::memory_holder); + rhs.m_pNode = &rhs.m_pMemory->create_node(); + rhs.m_pNode->set_null(); + + return *this; +} + inline void Node::AssignData(const Node& rhs) { if (!m_isValid || !rhs.m_isValid) throw InvalidNode(); diff --git a/include/yaml-cpp/node/node.h b/include/yaml-cpp/node/node.h index 1ded7d2..e459242 100644 --- a/include/yaml-cpp/node/node.h +++ b/include/yaml-cpp/node/node.h @@ -47,6 +47,8 @@ class YAML_CPP_API Node { explicit Node(const T& rhs); explicit Node(const detail::iterator_value& rhs); Node(const Node& rhs); + Node(Node&& rhs); + ~Node(); YAML::Mark Mark() const; @@ -81,6 +83,7 @@ class YAML_CPP_API Node { template Node& operator=(const T& rhs); Node& operator=(const Node& rhs); + Node& operator=(Node&& rhs); void reset(const Node& rhs = Node()); // size/iterator