mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Implemented map get(), and it would work (I think) if we implemented convert() for strings
This commit is contained in:
@@ -31,11 +31,64 @@ namespace YAML
|
|||||||
template<typename Key>
|
template<typename Key>
|
||||||
inline shared_node node_data::get(const Key& key, shared_memory_holder pMemory)
|
inline shared_node node_data::get(const Key& key, shared_memory_holder pMemory)
|
||||||
{
|
{
|
||||||
|
// TODO: check if 'key' is index-like, and we're a sequence
|
||||||
|
|
||||||
|
switch(m_type) {
|
||||||
|
case ValueType::Undefined:
|
||||||
|
case ValueType::Null:
|
||||||
|
case ValueType::Scalar:
|
||||||
|
m_type = ValueType::Map;
|
||||||
|
m_map.clear();
|
||||||
|
break;
|
||||||
|
case ValueType::Sequence:
|
||||||
|
convert_sequence_to_map();
|
||||||
|
break;
|
||||||
|
case ValueType::Map:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||||
|
if(equals(it->first, key, pMemory))
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_node pKey = convert_to_node(key, pMemory);
|
||||||
|
shared_node pValue(new node);
|
||||||
|
m_map.push_back(kv_pair(pKey, pValue));
|
||||||
|
return pValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key>
|
template<typename Key>
|
||||||
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory)
|
inline bool node_data::remove(const Key& key, shared_memory_holder pMemory)
|
||||||
{
|
{
|
||||||
|
if(m_type != ValueType::Map)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||||
|
if(equals(it->first, key, pMemory)) {
|
||||||
|
m_map.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool node_data::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline shared_node node_data::convert_to_node(const T& rhs, detail::shared_memory_holder pMemory)
|
||||||
|
{
|
||||||
|
Value value = convert(rhs);
|
||||||
|
pMemory->merge(*value.m_pMemory);
|
||||||
|
return value.m_pNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,12 @@ namespace YAML
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void convert_sequence_to_map();
|
void convert_sequence_to_map();
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static bool equals(detail::shared_node pNode, const T& rhs, detail::shared_memory_holder pMemory);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static shared_node convert_to_node(const T& rhs, detail::shared_memory_holder pMemory);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isDefined;
|
bool m_isDefined;
|
||||||
|
@@ -215,15 +215,6 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
return false;
|
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
|
#endif // VALUE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||||
|
@@ -17,6 +17,8 @@ namespace YAML
|
|||||||
class Value
|
class Value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
friend class detail::node_data;
|
||||||
|
|
||||||
Value();
|
Value();
|
||||||
explicit Value(ValueType::value type);
|
explicit Value(ValueType::value type);
|
||||||
template<typename T> explicit Value(const T& rhs);
|
template<typename T> explicit Value(const T& rhs);
|
||||||
@@ -61,9 +63,6 @@ namespace YAML
|
|||||||
private:
|
private:
|
||||||
explicit Value(detail::shared_node pNode, detail::shared_memory_holder pMemory);
|
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);
|
template<typename T> void Assign(const T& rhs);
|
||||||
void Assign(const char *rhs);
|
void Assign(const char *rhs);
|
||||||
void Assign(char *rhs);
|
void Assign(char *rhs);
|
||||||
|
Reference in New Issue
Block a user