From 2d75a631e2e3357640d396f3b2b2808e01bbfcff Mon Sep 17 00:00:00 2001 From: beder Date: Wed, 7 Sep 2011 03:21:24 -0500 Subject: [PATCH] Set up map searching by templated key --- include/yaml-cpp/value/detail/impl.h | 8 ++++---- include/yaml-cpp/value/detail/node.h | 20 +++++++------------- include/yaml-cpp/value/detail/node_data.h | 10 +++++----- include/yaml-cpp/value/impl.h | 23 ++++++++++++++++------- include/yaml-cpp/value/value.h | 3 +++ src/value/detail/node_data.cpp | 4 ++-- 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/include/yaml-cpp/value/detail/impl.h b/include/yaml-cpp/value/detail/impl.h index a1906db..c115cf4 100644 --- a/include/yaml-cpp/value/detail/impl.h +++ b/include/yaml-cpp/value/detail/impl.h @@ -15,13 +15,13 @@ namespace YAML { // indexing template - inline shared_node node_data::operator[](const Key& key) const + inline shared_node node_data::get(const Key& key, shared_memory_holder pMemory) const { if(m_type != ValueType::Map) return shared_node(new node); for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) { - if(it->first->equals(key)) + if(equals(it->first, key, pMemory)) return it->second; } @@ -29,12 +29,12 @@ namespace YAML } template - inline shared_node node_data::operator[](const Key& key) + inline shared_node node_data::get(const Key& key, shared_memory_holder pMemory) { } template - inline bool node_data::remove(const Key& key) + inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { } } diff --git a/include/yaml-cpp/value/detail/node.h b/include/yaml-cpp/value/detail/node.h index ddbd1bc..1943046 100644 --- a/include/yaml-cpp/value/detail/node.h +++ b/include/yaml-cpp/value/detail/node.h @@ -9,6 +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" namespace YAML @@ -27,26 +28,19 @@ namespace YAML 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); } - - template bool equals(const T& rhs) const; - + // indexing - template shared_node operator[](const Key& key) const { return (static_cast(*m_pData))[key]; } - template shared_node operator[](const Key& key) { return (*m_pData)[key]; } - template bool remove(const Key& key) { return m_pData->remove(key); } + 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 operator[](shared_node pKey) const { return (static_cast(*m_pData))[pKey]; } - shared_node operator[](shared_node pKey) { return (*m_pData)[pKey]; } + 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; }; - - template - inline bool node::equals(const T& rhs) const - { - } } } diff --git a/include/yaml-cpp/value/detail/node_data.h b/include/yaml-cpp/value/detail/node_data.h index eb524b7..0f5c9c9 100644 --- a/include/yaml-cpp/value/detail/node_data.h +++ b/include/yaml-cpp/value/detail/node_data.h @@ -30,12 +30,12 @@ namespace YAML const std::string scalar() const { return m_scalar; } // indexing - template shared_node operator[](const Key& key) const; - template shared_node operator[](const Key& key); - template bool remove(const Key& key); + template shared_node get(const Key& key, shared_memory_holder pMemory) const; + template shared_node get(const Key& key, shared_memory_holder pMemory); + template bool remove(const Key& key, shared_memory_holder pMemory); - shared_node operator[](shared_node pKey) const; - shared_node operator[](shared_node pKey); + shared_node get(shared_node pKey) const; + shared_node get(shared_node pKey); bool remove(shared_node pKey); private: diff --git a/include/yaml-cpp/value/impl.h b/include/yaml-cpp/value/impl.h index 319c772..f0a03c3 100644 --- a/include/yaml-cpp/value/impl.h +++ b/include/yaml-cpp/value/impl.h @@ -136,38 +136,38 @@ namespace YAML template inline const Value Value::operator[](const Key& key) const { - detail::shared_node pValue = (static_cast(*m_pNode))[key]; + detail::shared_node pValue = static_cast(*m_pNode).get(key, m_pMemory); return Value(pValue, m_pMemory); } template inline Value Value::operator[](const Key& key) { - detail::shared_node pValue = (*m_pNode)[key]; + detail::shared_node pValue = m_pNode->get(key, m_pMemory); return Value(pValue, m_pMemory); } template inline bool Value::remove(const Key& key) { - return m_pNode->remove(key); + return m_pNode->remove(key, m_pMemory); } inline const Value Value::operator[](const Value& key) const { - detail::shared_node pValue = (static_cast(*m_pNode))[*key.m_pNode]; + detail::shared_node pValue = static_cast(*m_pNode).get(key.m_pNode); return Value(pValue, m_pMemory); } inline Value Value::operator[](const Value& key) { - detail::shared_node pValue = (*m_pNode)[*key.m_pNode]; + detail::shared_node pValue = m_pNode->get(key.m_pNode); 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); } inline const Value Value::operator[](const char *key) const @@ -182,7 +182,7 @@ namespace YAML inline bool Value::remove(const char *key) { - return m_pNode->remove(std::string(key)); + return remove(std::string(key)); } inline const Value Value::operator[](char *key) const @@ -215,6 +215,15 @@ namespace YAML { return false; } + + template + inline bool equals(detail::shared_node pNode, const T& rhs, detail::shared_memory_holder pMemory) + { + T lhs; + if(convert(Value(pNode, pMemory), lhs)) + return lhs == rhs; + return false; + } } #endif // VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/include/yaml-cpp/value/value.h b/include/yaml-cpp/value/value.h index 510cce8..445b9ae 100644 --- a/include/yaml-cpp/value/value.h +++ b/include/yaml-cpp/value/value.h @@ -61,6 +61,9 @@ namespace YAML private: explicit Value(detail::shared_node pNode, detail::shared_memory_holder pMemory); + template + friend bool equals(detail::shared_node pNode, const T& rhs, detail::shared_memory_holder pMemory); + template void Assign(const T& rhs); void Assign(const char *rhs); void Assign(char *rhs); diff --git a/src/value/detail/node_data.cpp b/src/value/detail/node_data.cpp index 11ed462..5e3327d 100644 --- a/src/value/detail/node_data.cpp +++ b/src/value/detail/node_data.cpp @@ -57,7 +57,7 @@ namespace YAML } // indexing - shared_node node_data::operator[](shared_node pKey) const + shared_node node_data::get(shared_node pKey) const { if(m_type != ValueType::Map) return shared_node(new node); @@ -70,7 +70,7 @@ namespace YAML return shared_node(new node); } - shared_node node_data::operator[](shared_node pKey) + shared_node node_data::get(shared_node pKey) { switch(m_type) { case ValueType::Undefined: