diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-15 05:44:06 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:51 -0400 |
commit | d89f6e1c447fc5e7fcd0d6e5a236298323f9596e (patch) | |
tree | c044f2774a73c17401234a7c50254f1bb29ddc66 /src/xpath.h | |
parent | 7747a8f93bbc582a183fd4c7b8d5f8fd492b8608 (diff) | |
download | fork-ledger-d89f6e1c447fc5e7fcd0d6e5a236298323f9596e.tar.gz fork-ledger-d89f6e1c447fc5e7fcd0d6e5a236298323f9596e.tar.bz2 fork-ledger-d89f6e1c447fc5e7fcd0d6e5a236298323f9596e.zip |
The XPath visitor class is now working
Diffstat (limited to 'src/xpath.h')
-rw-r--r-- | src/xpath.h | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/xpath.h b/src/xpath.h index 9ec78489..485b5585 100644 --- a/src/xpath.h +++ b/src/xpath.h @@ -271,8 +271,12 @@ public: class path_iterator_t { - path_t path; - std::vector<node_t *> sequence; + path_t path; + node_t& start; + scope_t * scope; + + mutable std::vector<node_t *> sequence; + mutable bool searched; struct node_appender_t { std::vector<node_t *>& sequence; @@ -288,13 +292,21 @@ public: typedef std::vector<node_t *>::const_iterator const_iterator; path_iterator_t(const xpath_t& path_expr, - node_t& start, scope_t * scope) - : path(path_expr) { - path.visit(start, scope, node_appender_t(sequence)); + node_t& _start, scope_t * _scope) + : path(path_expr), start(_start), scope(_scope), + searched(false) { } - iterator begin() { return sequence.begin(); } - const_iterator begin() const { return sequence.begin(); } + iterator begin() { + if (! searched) { + path.visit(start, scope, node_appender_t(sequence)); + searched = true; + } + return sequence.begin(); + } + const_iterator begin() const { + return const_cast<path_iterator_t *>(this)->begin(); + } iterator end() { return sequence.end(); } const_iterator end() const { return sequence.end(); } @@ -748,6 +760,9 @@ public: path_t path(*this); path.find_all(result, start, scope); } + path_iterator_t find_all(node_t& start, scope_t * scope) { + return path_iterator_t(*this, start, scope); + } void visit(node_t& start, scope_t * scope, const function<void (node_t&)>& func) { @@ -755,10 +770,6 @@ public: path.visit(start, scope, func); } - path_iterator_t sequence(node_t& start, scope_t * scope) { - return path_iterator_t(*this, start, scope); - } - void print(std::ostream& out, xml::document_t& document) const { print(out, document, true, NULL, NULL, NULL); } |