Specialized the overloaded [] operator for int/unsigned, and added a size() function, so that you can iterate through a sequence node like a vector.

This commit is contained in:
Jesse Beder 2008-07-02 21:41:54 +00:00
parent 2ccbfeff47
commit 2be40919de
8 changed files with 81 additions and 25 deletions

15
node.h
View file

@ -50,9 +50,10 @@ namespace YAML
Iterator begin() const;
Iterator end() const;
unsigned size() const;
template <typename T>
const Node& operator [] (const T& key) const {
const Node& GetValue(const T& key) const {
if(!m_pContent)
throw BadDereference();
@ -69,10 +70,18 @@ namespace YAML
throw BadDereference();
}
const Node& operator [] (const char *key) const {
return operator [] (std::string(key));
template <typename T>
const Node& operator [] (const T& key) const {
return GetValue(key);
}
const Node& operator [] (const char *key) const {
return GetValue(std::string(key));
}
const Node& operator [] (unsigned u) const;
const Node& operator [] (int i) const;
// extraction
friend void operator >> (const Node& node, std::string& s);
friend void operator >> (const Node& node, int& i);