diff --git a/include/yaml-cpp/value/detail/node.h b/include/yaml-cpp/value/detail/node.h index 1943046..3932129 100644 --- a/include/yaml-cpp/value/detail/node.h +++ b/include/yaml-cpp/value/detail/node.h @@ -9,8 +9,7 @@ #include "yaml-cpp/dll.h" #include "yaml-cpp/value/type.h" #include "yaml-cpp/value/ptr.h" -#include "yaml-cpp/value/value.h" -#include "yaml-cpp/value/detail/node_data.h" +#include "yaml-cpp/value/detail/node_ref.h" namespace YAML { @@ -19,27 +18,28 @@ namespace YAML class node { public: - node(): m_pData(new node_data) {} + node(): m_pRef(new node_ref) {} - ValueType::value type() const { return m_pData->type(); } + ValueType::value type() const { return m_pRef->type(); } - void set_data(const node& rhs) { m_pData = rhs.m_pData; } + void set_ref(const node& rhs) { m_pRef = rhs.m_pRef; } + void set_data(const node& rhs) { m_pRef->set_data(*rhs.m_pRef); } - void set_type(ValueType::value type) { m_pData->set_type(type); } - void set_null() { m_pData->set_null(); } - void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); } + void set_type(ValueType::value type) { m_pRef->set_type(type); } + void set_null() { m_pRef->set_null(); } + void set_scalar(const std::string& scalar) { m_pRef->set_scalar(scalar); } // indexing - template shared_node get(const Key& key, shared_memory_holder pMemory) const { return static_cast(*m_pData).get(key, pMemory); } - template shared_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); } + template shared_node get(const Key& key, shared_memory_holder pMemory) const { return static_cast(*m_pRef).get(key, pMemory); } + template shared_node get(const Key& key, shared_memory_holder pMemory) { return m_pRef->get(key, pMemory); } + template bool remove(const Key& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); } - shared_node get(shared_node pKey) const { return static_cast(*m_pData).get(pKey); } - shared_node get(shared_node pKey) { return m_pData->get(pKey); } - bool remove(shared_node pKey) { return m_pData->remove(pKey); } + shared_node get(shared_node pKey) const { return static_cast(*m_pRef).get(pKey); } + shared_node get(shared_node pKey) { return m_pRef->get(pKey); } + bool remove(shared_node pKey) { return m_pRef->remove(pKey); } private: - shared_node_data m_pData; + shared_node_ref m_pRef; }; } } diff --git a/include/yaml-cpp/value/detail/node_ref.h b/include/yaml-cpp/value/detail/node_ref.h new file mode 100644 index 0000000..6c8d696 --- /dev/null +++ b/include/yaml-cpp/value/detail/node_ref.h @@ -0,0 +1,46 @@ +#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/value/type.h" +#include "yaml-cpp/value/ptr.h" +#include "yaml-cpp/value/detail/node_data.h" + +namespace YAML +{ + namespace detail + { + class node_ref + { + public: + node_ref(): m_pData(new node_data) {} + + ValueType::value type() const { return m_pData->type(); } + + void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; } + + void set_type(ValueType::value type) { m_pData->set_type(type); } + void set_null() { m_pData->set_null(); } + void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); } + + // indexing + template shared_node get(const Key& key, shared_memory_holder pMemory) const { return static_cast(*m_pData).get(key, pMemory); } + template shared_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); } + + shared_node get(shared_node pKey) const { return static_cast(*m_pData).get(pKey); } + shared_node get(shared_node pKey) { return m_pData->get(pKey); } + bool remove(shared_node pKey) { return m_pData->remove(pKey); } + + private: + shared_node_data m_pData; + }; + } +} + +#endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/value/impl.h b/include/yaml-cpp/value/impl.h index 52f06f4..197441d 100644 --- a/include/yaml-cpp/value/impl.h +++ b/include/yaml-cpp/value/impl.h @@ -102,7 +102,7 @@ namespace YAML void Value::AssignNode(const Value& rhs) { - m_pNode = rhs.m_pNode; + m_pNode->set_ref(*rhs.m_pNode); m_pMemory->merge(*rhs.m_pMemory); } diff --git a/include/yaml-cpp/value/ptr.h b/include/yaml-cpp/value/ptr.h index 7a9d35e..316dbd2 100644 --- a/include/yaml-cpp/value/ptr.h +++ b/include/yaml-cpp/value/ptr.h @@ -13,11 +13,13 @@ namespace YAML { namespace detail { class node; + class node_ref; 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;