mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Set up map searching by templated key
This commit is contained in:
@@ -15,13 +15,13 @@ namespace YAML
|
||||
{
|
||||
// indexing
|
||||
template<typename Key>
|
||||
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<typename Key>
|
||||
inline shared_node node_data::operator[](const Key& key)
|
||||
inline shared_node node_data::get(const Key& key, shared_memory_holder pMemory)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Key>
|
||||
inline bool node_data::remove(const Key& key)
|
||||
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -28,25 +29,18 @@ namespace YAML
|
||||
void set_null() { m_pData->set_null(); }
|
||||
void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); }
|
||||
|
||||
template<typename T> bool equals(const T& rhs) const;
|
||||
|
||||
// indexing
|
||||
template<typename Key> shared_node operator[](const Key& key) const { return (static_cast<const node_data&>(*m_pData))[key]; }
|
||||
template<typename Key> shared_node operator[](const Key& key) { return (*m_pData)[key]; }
|
||||
template<typename Key> bool remove(const Key& key) { return m_pData->remove(key); }
|
||||
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) const { return static_cast<const node_data&>(*m_pData).get(key, pMemory); }
|
||||
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); }
|
||||
template<typename Key> 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<const node_data&>(*m_pData))[pKey]; }
|
||||
shared_node operator[](shared_node pKey) { return (*m_pData)[pKey]; }
|
||||
shared_node get(shared_node pKey) const { return static_cast<const node_data&>(*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<typename T>
|
||||
inline bool node::equals(const T& rhs) const
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -30,12 +30,12 @@ namespace YAML
|
||||
const std::string scalar() const { return m_scalar; }
|
||||
|
||||
// indexing
|
||||
template<typename Key> shared_node operator[](const Key& key) const;
|
||||
template<typename Key> shared_node operator[](const Key& key);
|
||||
template<typename Key> bool remove(const Key& key);
|
||||
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory) const;
|
||||
template<typename Key> shared_node get(const Key& key, shared_memory_holder pMemory);
|
||||
template<typename Key> 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:
|
||||
|
@@ -136,38 +136,38 @@ namespace YAML
|
||||
template<typename Key>
|
||||
inline const Value Value::operator[](const Key& key) const
|
||||
{
|
||||
detail::shared_node pValue = (static_cast<const detail::node&>(*m_pNode))[key];
|
||||
detail::shared_node pValue = static_cast<const detail::node&>(*m_pNode).get(key, m_pMemory);
|
||||
return Value(pValue, m_pMemory);
|
||||
}
|
||||
|
||||
template<typename Key>
|
||||
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<typename Key>
|
||||
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<const detail::node&>(*m_pNode))[*key.m_pNode];
|
||||
detail::shared_node pValue = static_cast<const detail::node&>(*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<typename T>
|
||||
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
|
||||
|
@@ -61,6 +61,9 @@ namespace YAML
|
||||
private:
|
||||
explicit Value(detail::shared_node pNode, detail::shared_memory_holder pMemory);
|
||||
|
||||
template<typename T>
|
||||
friend bool equals(detail::shared_node pNode, const T& rhs, detail::shared_memory_holder pMemory);
|
||||
|
||||
template<typename T> void Assign(const T& rhs);
|
||||
void Assign(const char *rhs);
|
||||
void Assign(char *rhs);
|
||||
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user