mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-10 04:51:17 +00:00
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:
15
node.h
15
node.h
@@ -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);
|
||||
|
Reference in New Issue
Block a user