summaryrefslogtreecommitdiff
path: root/src/pugixml.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-01-27 03:54:05 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-01-27 03:54:05 +0000
commit0938714fa010b23e2d2a43606ae0eb8280c481fe (patch)
tree1944b008403cac5b785941627328c3cdc7593ff5 /src/pugixml.cpp
parent4d8974f1fd3e5366e93464a7ab68a35777354886 (diff)
Change xml_named_node_iterator to be bidirectional and to match xml_node_iterator in terms of internals
git-svn-id: http://pugixml.googlecode.com/svn/trunk@960 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src/pugixml.cpp')
-rw-r--r--src/pugixml.cpp54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 848b4cb..149b5d9 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -4038,7 +4038,7 @@ namespace pugi
PUGI__FN xml_object_range<xml_named_node_iterator> xml_node::children(const char_t* name_) const
{
- return xml_object_range<xml_named_node_iterator>(xml_named_node_iterator(child(name_), name_), xml_named_node_iterator());
+ return xml_object_range<xml_named_node_iterator>(xml_named_node_iterator(child(name_)._root, _root, name_), xml_named_node_iterator(0, _root, name_));
}
PUGI__FN xml_object_range<xml_attribute_iterator> xml_node::attributes() const
@@ -5133,36 +5133,40 @@ namespace pugi
{
}
- PUGI__FN xml_named_node_iterator::xml_named_node_iterator(const xml_node& node, const char_t* name): _node(node), _name(name)
+ PUGI__FN xml_named_node_iterator::xml_named_node_iterator(const xml_node& node, const char_t* name): _wrap(node), _parent(node.parent()), _name(name)
+ {
+ }
+
+ PUGI__FN xml_named_node_iterator::xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, const char_t* name): _wrap(ref), _parent(parent), _name(name)
{
}
PUGI__FN bool xml_named_node_iterator::operator==(const xml_named_node_iterator& rhs) const
{
- return _node == rhs._node;
+ return _wrap._root == rhs._wrap._root && _parent._root == rhs._parent._root;
}
PUGI__FN bool xml_named_node_iterator::operator!=(const xml_named_node_iterator& rhs) const
{
- return _node != rhs._node;
+ return _wrap._root != rhs._wrap._root || _parent._root != rhs._parent._root;
}
PUGI__FN xml_node& xml_named_node_iterator::operator*() const
{
- assert(_node._root);
- return _node;
+ assert(_wrap._root);
+ return _wrap;
}
PUGI__FN xml_node* xml_named_node_iterator::operator->() const
{
- assert(_node._root);
- return const_cast<xml_node*>(&_node); // BCC32 workaround
+ assert(_wrap._root);
+ return const_cast<xml_node*>(&_wrap); // BCC32 workaround
}
PUGI__FN const xml_named_node_iterator& xml_named_node_iterator::operator++()
{
- assert(_node._root);
- _node = _node.next_sibling(_name);
+ assert(_wrap._root);
+ _wrap = _wrap.next_sibling(_name);
return *this;
}
@@ -5173,6 +5177,28 @@ namespace pugi
return temp;
}
+ PUGI__FN const xml_named_node_iterator& xml_named_node_iterator::operator--()
+ {
+ if (_wrap._root)
+ _wrap = _wrap.previous_sibling(_name);
+ else
+ {
+ _wrap = _parent.last_child();
+
+ if (!impl::strequal(_wrap.name(), _name))
+ _wrap = _wrap.previous_sibling(_name);
+ }
+
+ return *this;
+ }
+
+ PUGI__FN xml_named_node_iterator xml_named_node_iterator::operator--(int)
+ {
+ xml_named_node_iterator temp = *this;
+ --*this;
+ return temp;
+ }
+
PUGI__FN xml_parse_result::xml_parse_result(): status(status_internal_error), offset(0), encoding(encoding_auto)
{
}
@@ -5481,9 +5507,9 @@ namespace std
return std::bidirectional_iterator_tag();
}
- PUGI__FN std::forward_iterator_tag _Iter_cat(const pugi::xml_named_node_iterator&)
+ PUGI__FN std::bidirectional_iterator_tag _Iter_cat(const pugi::xml_named_node_iterator&)
{
- return std::forward_iterator_tag();
+ return std::bidirectional_iterator_tag();
}
}
#endif
@@ -5502,9 +5528,9 @@ namespace std
return std::bidirectional_iterator_tag();
}
- PUGI__FN std::forward_iterator_tag __iterator_category(const pugi::xml_named_node_iterator&)
+ PUGI__FN std::bidirectional_iterator_tag __iterator_category(const pugi::xml_named_node_iterator&)
{
- return std::forward_iterator_tag();
+ return std::bidirectional_iterator_tag();
}
}
#endif