Converted indexing to std::size_t, and fixed the Node templated overloads to properly index any index type (determining what is an index type is a bit of a hack - it should be is_convertible<T, std::size_t> (I think), but I just explicitly wrote down a list)

This commit is contained in:
Jesse Beder
2009-08-19 20:58:07 +00:00
parent ba11f5ae15
commit 81c2e6b6ca
17 changed files with 134 additions and 78 deletions

View File

@@ -4,6 +4,8 @@
#define NODEIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#include "nodeutil.h"
namespace YAML
{
// implementation of templated things
@@ -31,9 +33,18 @@ namespace YAML
template <typename T>
inline const Node *Node::FindValue(const T& key) const {
if(!m_pContent)
return 0;
switch(GetType()) {
case CT_MAP:
return FindValueForKey(key);
case CT_SEQUENCE:
return FindFromNodeAtIndex(*this, key);
default:
return 0;
}
}
template <typename T>
inline const Node *Node::FindValueForKey(const T& key) const {
for(Iterator it=begin();it!=end();++it) {
T t;
if(it.first().Read(t)) {
@@ -45,24 +56,16 @@ namespace YAML
return 0;
}
inline const Node *Node::FindValue(const char *key) const {
return FindValue(std::string(key));
}
template <typename T>
inline const Node& Node::GetValue(const T& key) const {
if(!m_pContent)
throw BadDereference();
for(Iterator it=begin();it!=end();++it) {
T t;
if(it.first().Read(t)) {
if(key == t)
return it.second();
}
}
throw MakeTypedKeyNotFound(m_mark, key);
const Node *pValue = FindValue(key);
if(!pValue)
throw MakeTypedKeyNotFound(m_mark, key);
return *pValue;
}
template <typename T>
@@ -70,6 +73,10 @@ namespace YAML
return GetValue(key);
}
inline const Node *Node::FindValue(const char *key) const {
return FindValue(std::string(key));
}
inline const Node& Node::operator [] (const char *key) const {
return GetValue(std::string(key));
}