summaryrefslogtreecommitdiff
path: root/src/pugixml.hpp
diff options
context:
space:
mode:
authorarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-03-27 05:23:24 +0000
committerarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-03-27 05:23:24 +0000
commita10bb9d7660637aa23ee86cb4a741f1b7c334357 (patch)
tree49178ea881fe8fb49a7b088123e77baabd707c00 /src/pugixml.hpp
parent579adaf3017191ae4b1ba2097265f3443a142623 (diff)
Introduced xml_named_node_iterator, introduced xml_node::children() and xml_node::attributes() for C++11 range-based for loop
git-svn-id: http://pugixml.googlecode.com/svn/trunk@889 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src/pugixml.hpp')
-rw-r--r--src/pugixml.hpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/pugixml.hpp b/src/pugixml.hpp
index 4b7a655..f4dfdf2 100644
--- a/src/pugixml.hpp
+++ b/src/pugixml.hpp
@@ -197,6 +197,7 @@ namespace pugi
class xml_node_iterator;
class xml_attribute_iterator;
+ class xml_named_node_iterator;
class xml_tree_walker;
@@ -211,6 +212,21 @@ namespace pugi
class xpath_variable_set;
#endif
+ // Range-based for loop support
+ template <typename It> class xml_object_range
+ {
+ public:
+ xml_object_range(It b, It e): _begin(b), _end(e)
+ {
+ }
+
+ It begin() const { return _begin; }
+ It end() const { return _end; }
+
+ private:
+ It _begin, _end;
+ };
+
// Writer interface for node printing (see xml_node::print)
class PUGIXML_CLASS xml_writer
{
@@ -544,6 +560,11 @@ namespace pugi
attribute_iterator attributes_begin() const;
attribute_iterator attributes_end() const;
+ // Range-based for support
+ xml_object_range<xml_node_iterator> children() const;
+ xml_object_range<xml_named_node_iterator> children(const char_t* name) const;
+ xml_object_range<xml_attribute_iterator> attributes() const;
+
// Get node offset in parsed file/string (in char_t units) for debugging purposes
ptrdiff_t offset_debug() const;
@@ -709,6 +730,41 @@ namespace pugi
xml_attribute_iterator operator--(int);
};
+ // Named node range helper
+ class xml_named_node_iterator
+ {
+ public:
+ // Iterator traits
+ typedef ptrdiff_t difference_type;
+ typedef xml_node value_type;
+ typedef xml_node* pointer;
+ typedef xml_node& reference;
+
+ #ifndef PUGIXML_NO_STL
+ typedef std::forward_iterator_tag iterator_category;
+ #endif
+
+ // Default constructor
+ xml_named_node_iterator();
+
+ // Construct an iterator which points to the specified node
+ xml_named_node_iterator(const xml_node& node, const char_t* name);
+
+ // Iterator operators
+ bool operator==(const xml_named_node_iterator& rhs) const;
+ bool operator!=(const xml_named_node_iterator& rhs) const;
+
+ xml_node& operator*() const;
+ xml_node* operator->() const;
+
+ const xml_named_node_iterator& operator++();
+ xml_named_node_iterator operator++(int);
+
+ private:
+ mutable xml_node _node;
+ const char_t* _name;
+ };
+
// Abstract tree walker class (see xml_node::traverse)
class PUGIXML_CLASS xml_tree_walker
{