diff --git a/include/yaml-cpp/value/detail/impl.h b/include/yaml-cpp/value/detail/impl.h index e6847a7..52a450b 100644 --- a/include/yaml-cpp/value/detail/impl.h +++ b/include/yaml-cpp/value/detail/impl.h @@ -18,14 +18,14 @@ namespace YAML inline shared_node node_data::get(const Key& key, shared_memory_holder pMemory) const { if(m_type != ValueType::Map) - return shared_node(new node); + return pMemory->create_node(); for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { if(equals(it->first, key, pMemory)) return it->second; } - return shared_node(new node); + return pMemory->create_node(); } template @@ -41,7 +41,7 @@ namespace YAML m_map.clear(); break; case ValueType::Sequence: - convert_sequence_to_map(); + convert_sequence_to_map(pMemory); break; case ValueType::Map: break; @@ -53,7 +53,7 @@ namespace YAML } shared_node pKey = convert_to_node(key, pMemory); - shared_node pValue(new node); + shared_node pValue = pMemory->create_node(); m_map.push_back(kv_pair(pKey, pValue)); return pValue; } diff --git a/include/yaml-cpp/value/detail/memory.h b/include/yaml-cpp/value/detail/memory.h index 475a341..4504332 100644 --- a/include/yaml-cpp/value/detail/memory.h +++ b/include/yaml-cpp/value/detail/memory.h @@ -19,7 +19,7 @@ namespace YAML void merge(const memory& rhs); private: - typedef std::set Nodes; + typedef std::set Nodes; Nodes m_nodes; }; diff --git a/include/yaml-cpp/value/detail/node.h b/include/yaml-cpp/value/detail/node.h index fdd5ecd..97b3c3e 100644 --- a/include/yaml-cpp/value/detail/node.h +++ b/include/yaml-cpp/value/detail/node.h @@ -18,7 +18,7 @@ namespace YAML class node { public: - node(): m_pRef(new node_ref) {} + explicit node(shared_node_ref pRef): m_pRef(pRef) {} ValueType::value type() const { return m_pRef->type(); } @@ -36,9 +36,9 @@ namespace YAML 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_pRef).get(pKey); } - shared_node get(shared_node pKey) { return m_pRef->get(pKey); } - bool remove(shared_node pKey) { return m_pRef->remove(pKey); } + shared_node get(shared_node pKey, shared_memory_holder pMemory) const { return static_cast(*m_pRef).get(pKey, pMemory); } + shared_node get(shared_node pKey, shared_memory_holder pMemory) { return m_pRef->get(pKey, pMemory); } + bool remove(shared_node pKey, shared_memory_holder pMemory) { return m_pRef->remove(pKey, pMemory); } private: shared_node_ref m_pRef; diff --git a/include/yaml-cpp/value/detail/node_data.h b/include/yaml-cpp/value/detail/node_data.h index 9aa798e..7fe8405 100644 --- a/include/yaml-cpp/value/detail/node_data.h +++ b/include/yaml-cpp/value/detail/node_data.h @@ -34,12 +34,12 @@ namespace YAML template shared_node get(const Key& key, shared_memory_holder pMemory); template bool remove(const Key& key, shared_memory_holder pMemory); - shared_node get(shared_node pKey) const; - shared_node get(shared_node pKey); - bool remove(shared_node pKey); + shared_node get(shared_node pKey, shared_memory_holder pMemory) const; + shared_node get(shared_node pKey, shared_memory_holder pMemory); + bool remove(shared_node pKey, shared_memory_holder pMemory); private: - void convert_sequence_to_map(); + void convert_sequence_to_map(shared_memory_holder pMemory); template static bool equals(detail::shared_node pNode, const T& rhs, detail::shared_memory_holder pMemory); diff --git a/include/yaml-cpp/value/detail/node_ref.h b/include/yaml-cpp/value/detail/node_ref.h index 6c8d696..6c34042 100644 --- a/include/yaml-cpp/value/detail/node_ref.h +++ b/include/yaml-cpp/value/detail/node_ref.h @@ -33,9 +33,9 @@ namespace YAML 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); } + shared_node get(shared_node pKey, shared_memory_holder pMemory) const { return static_cast(*m_pData).get(pKey, pMemory); } + shared_node get(shared_node pKey, shared_memory_holder pMemory) { return m_pData->get(pKey, pMemory); } + bool remove(shared_node pKey, shared_memory_holder pMemory) { return m_pData->remove(pKey, pMemory); } private: shared_node_data m_pData; diff --git a/include/yaml-cpp/value/impl.h b/include/yaml-cpp/value/impl.h index 566e333..c4625f8 100644 --- a/include/yaml-cpp/value/impl.h +++ b/include/yaml-cpp/value/impl.h @@ -160,19 +160,19 @@ namespace YAML inline const Value Value::operator[](const Value& key) const { - detail::shared_node pValue = static_cast(*m_pNode).get(key.m_pNode); + detail::shared_node pValue = static_cast(*m_pNode).get(key.m_pNode, m_pMemory); return Value(pValue, m_pMemory); } inline Value Value::operator[](const Value& key) { - detail::shared_node pValue = m_pNode->get(key.m_pNode); + detail::shared_node pValue = m_pNode->get(key.m_pNode, m_pMemory); return Value(pValue, m_pMemory); } inline bool Value::remove(const Value& key) { - return m_pNode->remove(key.m_pNode); + return m_pNode->remove(key.m_pNode, m_pMemory); } inline const Value Value::operator[](const char *key) const diff --git a/src/value/detail/memory.cpp b/src/value/detail/memory.cpp index 3e529a8..3082939 100644 --- a/src/value/detail/memory.cpp +++ b/src/value/detail/memory.cpp @@ -16,9 +16,9 @@ namespace YAML shared_node memory::create_node() { - shared_node pNode(new node); - m_nodes.insert(pNode); - return pNode; + shared_node_ref pRef(new node_ref); + m_nodes.insert(pRef); + return shared_node(new node(pRef)); } void memory::merge(const memory& rhs) diff --git a/src/value/detail/node_data.cpp b/src/value/detail/node_data.cpp index 5e3327d..d9215b7 100644 --- a/src/value/detail/node_data.cpp +++ b/src/value/detail/node_data.cpp @@ -1,4 +1,5 @@ #include "yaml-cpp/value/detail/node_data.h" +#include "yaml-cpp/value/detail/memory.h" #include "yaml-cpp/value/detail/node.h" #include @@ -57,20 +58,20 @@ namespace YAML } // indexing - shared_node node_data::get(shared_node pKey) const + shared_node node_data::get(shared_node pKey, shared_memory_holder pMemory) const { if(m_type != ValueType::Map) - return shared_node(new node); + return pMemory->create_node(); for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { if(it->first == pKey) return it->second; } - return shared_node(new node); + return pMemory->create_node(); } - shared_node node_data::get(shared_node pKey) + shared_node node_data::get(shared_node pKey, shared_memory_holder pMemory) { switch(m_type) { case ValueType::Undefined: @@ -80,7 +81,7 @@ namespace YAML m_map.clear(); break; case ValueType::Sequence: - convert_sequence_to_map(); + convert_sequence_to_map(pMemory); break; case ValueType::Map: break; @@ -91,12 +92,12 @@ namespace YAML return it->second; } - shared_node pValue(new node); + shared_node pValue = pMemory->create_node(); m_map.push_back(kv_pair(pKey, pValue)); return pValue; } - bool node_data::remove(shared_node pKey) + bool node_data::remove(shared_node pKey, shared_memory_holder /* pMemory */) { if(m_type != ValueType::Map) return false; @@ -111,7 +112,7 @@ namespace YAML return false; } - void node_data::convert_sequence_to_map() + void node_data::convert_sequence_to_map(shared_memory_holder pMemory) { assert(m_type == ValueType::Sequence); @@ -120,7 +121,7 @@ namespace YAML std::stringstream stream; stream << i; - shared_node pKey(new node); + shared_node pKey = pMemory->create_node(); pKey->set_scalar(stream.str()); m_map.push_back(kv_pair(pKey, m_sequence[i])); }