implement Node move
This commit is contained in:
parent
7a52c16563
commit
52cc604c3f
@ -51,6 +51,14 @@ inline Node::Node(Zombie)
|
||||
m_pMemory(nullptr),
|
||||
m_pNode(NULL) {}
|
||||
|
||||
inline Node::Node(Node&& rhs)
|
||||
: m_isValid(rhs.m_isValid),
|
||||
m_pMemory(rhs.m_pMemory), // move ?
|
||||
m_pNode(rhs.m_pNode) {
|
||||
|
||||
rhs.m_pNode = nullptr;
|
||||
}
|
||||
|
||||
inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory)
|
||||
: m_isValid(true),
|
||||
m_pMemory(pMemory),
|
||||
@ -256,6 +264,17 @@ 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);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::AssignData(Node&& rhs) {
|
||||
if (!m_isValid || !rhs.m_isValid)
|
||||
throw InvalidNode();
|
||||
|
||||
@ -18,18 +18,23 @@
|
||||
namespace YAML {
|
||||
namespace detail {
|
||||
struct iterator_value : public Node, std::pair<Node, Node> {
|
||||
iterator_value() {}
|
||||
iterator_value()
|
||||
: Node(Node::ZombieNode),
|
||||
std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {}
|
||||
|
||||
explicit iterator_value(const Node& rhs)
|
||||
: Node(rhs),
|
||||
std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {}
|
||||
: Node(rhs),
|
||||
std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {}
|
||||
|
||||
explicit iterator_value(const Node& key, const Node& value)
|
||||
: Node(Node::ZombieNode), std::pair<Node, Node>(key, value) {}
|
||||
: Node(Node::ZombieNode), std::pair<Node, Node>(key, value) {}
|
||||
|
||||
explicit iterator_value(Node&& rhs)
|
||||
: Node(std::move(rhs)),
|
||||
std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {}
|
||||
: Node(std::move(rhs)),
|
||||
std::pair<Node, Node>(Node(Node::ZombieNode), Node(Node::ZombieNode)) {}
|
||||
|
||||
explicit iterator_value(Node&& key, Node&& value)
|
||||
: Node(Node::ZombieNode), std::pair<Node, Node>(std::move(key), std::move(value)) {}
|
||||
: Node(Node::ZombieNode), std::pair<Node, Node>(std::move(key), std::move(value)) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 <typename T>
|
||||
Node& operator=(const T& rhs);
|
||||
Node& operator=(const Node& rhs);
|
||||
Node& operator=(Node&& rhs);
|
||||
void reset(const Node& rhs = Node());
|
||||
|
||||
// size/iterator
|
||||
|
||||
Loading…
Reference in New Issue
Block a user