diff options
-rw-r--r-- | src/amount.cc | 6 | ||||
-rw-r--r-- | src/balance.cc | 2 | ||||
-rw-r--r-- | src/balance.h | 10 | ||||
-rw-r--r-- | src/commodity.cc | 2 | ||||
-rw-r--r-- | src/commodity.h | 8 | ||||
-rw-r--r-- | src/format.cc | 2 | ||||
-rw-r--r-- | src/main.cc | 6 | ||||
-rw-r--r-- | src/scoped_execute.h | 164 | ||||
-rw-r--r-- | src/value.cc | 10 | ||||
-rw-r--r-- | src/value.h | 2 | ||||
-rw-r--r-- | src/xml.cc | 10 | ||||
-rw-r--r-- | src/xml.h | 8 | ||||
-rw-r--r-- | src/xpath.cc | 110 | ||||
-rw-r--r-- | src/xpath.h | 14 |
14 files changed, 255 insertions, 99 deletions
diff --git a/src/amount.cc b/src/amount.cc index 88717e24..36c8fec9 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -1176,8 +1176,7 @@ void amount_t::print(std::ostream& _out, bool omit_commodity, } if (! omit_commodity && ! comm.has_flags(COMMODITY_STYLE_SUFFIXED)) { - comm.write(out); - + comm.print(out); if (comm.has_flags(COMMODITY_STYLE_SEPARATED)) out << " "; } @@ -1262,8 +1261,7 @@ void amount_t::print(std::ostream& _out, bool omit_commodity, if (! omit_commodity && comm.has_flags(COMMODITY_STYLE_SUFFIXED)) { if (comm.has_flags(COMMODITY_STYLE_SEPARATED)) out << " "; - - comm.write(out); + comm.print(out); } mpz_clear(quotient); diff --git a/src/balance.cc b/src/balance.cc index cafd0f01..83f09e45 100644 --- a/src/balance.cc +++ b/src/balance.cc @@ -196,7 +196,7 @@ balance_t balance_t::strip_annotations(const bool keep_price, return temp; } -void balance_t::write(std::ostream& out, +void balance_t::print(std::ostream& out, const int first_width, const int latter_width) const { diff --git a/src/balance.h b/src/balance.h index 769d8d83..bbb054ee 100644 --- a/src/balance.h +++ b/src/balance.h @@ -159,7 +159,7 @@ public: const bool keep_date = amount_t::keep_date, const bool keep_tag = amount_t::keep_tag) const; - void write(std::ostream& out, const int first_width, + void print(std::ostream& out, const int first_width, const int latter_width = -1) const; balance_t abs() const { @@ -216,7 +216,7 @@ public: }; inline std::ostream& operator<<(std::ostream& out, const balance_t& bal) { - bal.write(out, 12); + bal.print(out, 12); return out; } @@ -351,9 +351,9 @@ public: return quantity.strip_annotations(keep_price, keep_date, keep_tag); } - void write(std::ostream& out, const int first_width, + void print(std::ostream& out, const int first_width, const int latter_width = -1) const { - quantity.write(out, first_width, latter_width); + quantity.print(out, first_width, latter_width); } balance_pair_t& add(const amount_t& amt, @@ -404,7 +404,7 @@ public: inline std::ostream& operator<<(std::ostream& out, const balance_pair_t& bal_pair) { - bal_pair.quantity.write(out, 12); + bal_pair.quantity.print(out, 12); return out; } diff --git a/src/commodity.cc b/src/commodity.cc index 7d769364..6731992d 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -371,7 +371,7 @@ namespace { throw_(amount_error, "A commodity's price may not be negative"); std::ostringstream name; - comm.write(name); + comm.print(name); annotated_commodity_t::write_annotations(name, details); DEBUG("amounts.commodities", "make_qualified_name for " diff --git a/src/commodity.h b/src/commodity.h index 96c39c1b..2ed8b7b4 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -192,7 +192,7 @@ public: optional<amount_t> value(const optional<moment_t>& moment = optional<moment_t>()); - void write(std::ostream& out) const { + void print(std::ostream& out) const { out << symbol(); } @@ -200,7 +200,7 @@ public: }; inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) { - comm.write(out); + comm.print(out); return out; } @@ -226,7 +226,7 @@ struct annotation_t : public equality_comparable<annotation_t> tag == rhs.tag); } - void write(std::ostream& out) const { + void print(std::ostream& out) const { out << "price " << (price ? price->to_string() : "NONE") << " " << "date " << (date ? *date : moment_t()) << " " << "tag " << (tag ? *tag : "NONE"); @@ -238,7 +238,7 @@ struct annotation_t : public equality_comparable<annotation_t> }; inline std::ostream& operator<<(std::ostream& out, const annotation_t& details) { - details.write(out); + details.print(out); return out; } diff --git a/src/format.cc b/src/format.cc index 9c34f876..d155d419 100644 --- a/src/format.cc +++ b/src/format.cc @@ -190,7 +190,7 @@ int format_t::element_formatter_t::operator() if (elem->kind == element_t::XPATH) elem->xpath->calc(context).strip_annotations() - .write(out, elem->min_width, elem->max_width); + .print(out, elem->min_width, elem->max_width); else if (elem->kind == element_t::GROUP) column = elem->format->format(out, context, column); else if (elem->kind == element_t::TEXT) diff --git a/src/main.cc b/src/main.cc index 6908be3d..9147d4ee 100644 --- a/src/main.cc +++ b/src/main.cc @@ -151,7 +151,7 @@ static int read_and_report(report_t * report, int argc, char * argv[], expr.dump(std::cout); std::cout << std::endl; std::cout << "Value expression parsed was:" << std::endl; - expr.write(std::cout); + expr.print(std::cout); std::cout << std::endl << std::endl; std::cout << "Result of calculation: "; } @@ -250,7 +250,7 @@ static int read_and_report(report_t * report, int argc, char * argv[], expr.dump(*out); *out << std::endl; *out << "Value expression parsed was:" << std::endl; - expr.write(*out); + expr.print(*out); *out << std::endl << std::endl; *out << "Result of calculation: "; } @@ -263,7 +263,7 @@ static int read_and_report(report_t * report, int argc, char * argv[], else if (verb == "xpath") { std::cout << "XPath parsed:" << std::endl; xml::xpath_t xpath(*arg); - xpath.write(*out); + xpath.print(*out); *out << std::endl; #if 0 diff --git a/src/scoped_execute.h b/src/scoped_execute.h index da3f388e..20032748 100644 --- a/src/scoped_execute.h +++ b/src/scoped_execute.h @@ -1,5 +1,163 @@ -#ifndef _SCOPE_EXECUTE_H -#define _SCOPE_EXECUTE_H +#ifndef _SCOPED_EXECUTE_H +#define _SCOPED_EXECUTE_H + +/** + * @file scoped_execute.h + * @author John Wiegley + * @date Sun May 6 20:10:52 2007 + * + * @brief Adds a facility to C++ for handling "scoped executions". + * + * There are sometimes cases where you would like to guarantee that + * something happens at the end of a scope, such as calling a function + * to close a resource for you. + * + * The common idiom for this has become to write a helper class whose + * destructor will call that function. Of course, it must then be + * passed information from the calling scope to hold onto as state + * information, since the code within the class itself has no access + * to its points of use. + * + * This type of solution is cumbersome enough that it's sometimes + * avoided. Take calling pthread_mutex_unlock(pthread_mutex_t *) for + * example. A typical snippet of safe C++ code might look like this: + * + * @code + * void foo(pthread_mutex_t * mutex) { + * if (pthread_mutex_lock(mutex) == 0) { + * try { + * // Do work that requires the mutex to be locked; then... + * pthread_mutex_unlock(mutex); + * } + * catch (std::logic_error& exc) { + * // This is an exception we actually handle, and then exit + * pthread_mutex_unlock(mutex); + * } + * catch (...) { + * // These are exceptions we do not handle, but still the + * // mutex must be unlocked + * pthread_mutex_unlock(mutex); + * throw; + * } + * } + * } + * @endcode + * + * The alternative to this, as mentioned above, is to create a helper + * class named pthread_scoped_lock, which might look like this: + * + * @code + * class pthread_scoped_lock : public boost::noncopyable { + * pthread_mutex_t * mutex; + * public: + * explicit pthread_scoped_lock(pthread_mutex_t * locked_mutex) + * : mutex(locked_mutex) {} + * ~pthread_scoped_lock() { + * pthread_mutex_unlock(mutex); + * } + * }; + * @endcode + * + * Although this helper class is just as much work as writing the code + * above, it only needs to be written once. Now the access code can + * look like this: + * + * @code + * void foo(pthread_mutex_t * mutex) { + * if (pthread_mutex_lock(mutex) == 0) { + * pthread_scoped_lock(mutex); + * try { + * // Do work that requires the mutex to be locked + * } + * catch (std::logic_error& exc) { + * // This is an exception we actually handle, and then exit + * } + * } + * } + * @endcode + * + * But what if it could be even easier? That is what this file is + * for, to provide a scoped_execute<> class which guarantees execution + * of arbtirary code after a scope has terminated, without having to + * resort to custom utility classes. It relies on boost::bind to + * declare pending function calls. Here it what the above would look + * like: + * + * @code + * void foo(pthread_mutex_t * mutex) { + * if (pthread_mutex_lock(mutex) == 0) { + * scoped_execute<void> unlock_mutex + * (boost::bind(pthread_mutex_unlock, mutex)); + * try { + * // Do work that requires the mutex to be locked + * } + * catch (std::logic_error& exc) { + * // This is an exception we actually handle, and then exit + * } + * } + * } + * @endcode + * + * The advantage here is that no helper class ever needs to created, + * and hence no bugs from such helper classes can creep into the code. + * The single call to boost::bind creates a closure binding that will + * be invoked once the containing scope has terminated. + * + * Another kind of scoped_execute is useful for setting the values of + * variables to a predetermined value upon completion of a scope. + * Consider this example: + * + * @code + * bool foo_was_run; + * + * void foo() { + * scoped_execute<bool&> set_success((_1 = true), foo_was_run); + * // do some code, and make sure foo_was_run is set to true + * // once the scope is exited -- however this happens. + * } + * @endcode + * + * In this case, the Boost.Lambda library is used to create an + * anonymous functor whose job is to set the global variable + * `foo_was_run' to a predetermined value. + * + * Lastly, there is another helper class, `scoped_variable' whose job + * is solely to return variables to the value they had at the moment + * the scoped_variable class was instantiated. For example, let's say + * you have a `bar' variable that you want to work on, but you want to + * guarantee that its value is restored upon exiting the scope. This + * can be useful in recursion, for "pushing" and "popping" variable + * values during execution, for example: + * + * @code + * std::string bar = "Hello"; + * void foo() { + * scoped_variable<std::string> restore_bar(bar); + * bar = "Goodbye"; + * // do work with the changed bar; it gets restored upon exit + * } + * @endcode + * + * As a shortcut, you can specify the new value for the pushed + * variable as a second constructor argument: + * + * @code + * std::string bar = "Hello"; + * void foo() { + * scoped_variable<std::string> restore_bar(bar, "Goodbye"); + * // do work with the changed bar; it gets restored upon exit + * } + * @endcode + * + * Finally, you can stop a scoped_execute or scoped_variable from + * invoking its completion code by calling the `clear' method on the + * object instance. Once `clear' is called, the scoped execution + * becomes inert and will do nothing when the enclosing scope is + * exited. + */ + +#include <boost/noncopyable.hpp> +#include <boost/function.hpp> template <typename T> class scoped_variable : public boost::noncopyable @@ -70,4 +228,4 @@ public: } }; -#endif // _SCOPE_EXECUTE_H +#endif // _SCOPED_EXECUTE_H diff --git a/src/value.cc b/src/value.cc index 2c9f307a..4473878d 100644 --- a/src/value.cc +++ b/src/value.cc @@ -2215,7 +2215,7 @@ value_t& value_t::add(const amount_t& amount, const optional<amount_t>& tcost) return *this; } -void value_t::write(std::ostream& out, const int first_width, +void value_t::print(std::ostream& out, const int first_width, const int latter_width) const { switch (type) { @@ -2229,7 +2229,7 @@ void value_t::write(std::ostream& out, const int first_width, break; case XML_NODE: - (*(xml::node_t **) data)->write(out); + (*(xml::node_t **) data)->print(out); break; case SEQUENCE: @@ -2237,10 +2237,10 @@ void value_t::write(std::ostream& out, const int first_width, throw_(value_error, "Cannot write out a sequence"); case BALANCE: - ((balance_t *) data)->write(out, first_width, latter_width); + ((balance_t *) data)->print(out, first_width, latter_width); break; case BALANCE_PAIR: - ((balance_pair_t *) data)->write(out, first_width, latter_width); + ((balance_pair_t *) data)->print(out, first_width, latter_width); break; } } @@ -2344,7 +2344,7 @@ void value_context::describe(std::ostream& out) const throw() if (! ptr) ptr = &((balance_pair_t *) bal->data)->quantity; - ptr->write(out, 20); + ptr->print(out, 20); break; default: assert(0); diff --git a/src/value.h b/src/value.h index 7d6f36be..ad4ce26f 100644 --- a/src/value.h +++ b/src/value.h @@ -392,7 +392,7 @@ class value_t value_t round() const; value_t unround() const; - void write(std::ostream& out, const int first_width, + void print(std::ostream& out, const int first_width, const int latter_width = -1) const; friend std::ostream& operator<<(std::ostream& out, const value_t& val); @@ -116,11 +116,11 @@ const char * document_t::lookup_name(int id) const } } -void document_t::write(std::ostream& out) const +void document_t::print(std::ostream& out) const { if (top) { out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; - top->write(out); + top->print(out); } } @@ -222,19 +222,19 @@ void parent_node_t::add_child(node_t * node) _last_child = node; } -void parent_node_t::write(std::ostream& out, int depth) const +void parent_node_t::print(std::ostream& out, int depth) const { for (int i = 0; i < depth; i++) out << " "; out << '<' << name() << ">\n"; for (node_t * child = children(); child; child = child->next) - child->write(out, depth + 1); + child->print(out, depth + 1); for (int i = 0; i < depth; i++) out << " "; out << "</" << name() << ">\n"; } -void terminal_node_t::write(std::ostream& out, int depth) const +void terminal_node_t::print(std::ostream& out, int depth) const { for (int i = 0; i < depth; i++) out << " "; @@ -89,7 +89,7 @@ public: throw_(conversion_error, "Cannot convert node to a value"); } - virtual void write(std::ostream& out, int depth = 0) const = 0; + virtual void print(std::ostream& out, int depth = 0) const = 0; private: node_t(const node_t&); @@ -124,7 +124,7 @@ public: } virtual void add_child(node_t * node); - void write(std::ostream& out, int depth = 0) const; + void print(std::ostream& out, int depth = 0) const; private: parent_node_t(const parent_node_t&); @@ -159,7 +159,7 @@ public: return text(); } - void write(std::ostream& out, int depth = 0) const; + void print(std::ostream& out, int depth = 0) const; private: terminal_node_t(const node_t&); @@ -218,7 +218,7 @@ private: static int lookup_builtin_id(const string& name); const char * lookup_name(int id) const; - void write(std::ostream& out) const; + void print(std::ostream& out) const; #if defined(HAVE_EXPAT) || defined(HAVE_XMLPARSE) class parser_t diff --git a/src/xpath.cc b/src/xpath.cc index 8fea995e..52861eb0 100644 --- a/src/xpath.cc +++ b/src/xpath.cc @@ -1954,7 +1954,7 @@ void xpath_t::context::describe(std::ostream& out) const throw() unsigned long end; bool found = false; if (xpath) - xpath.write(out, true, err_node, &begin, &end); + xpath.print(out, true, err_node, &begin, &end); out << std::endl; if (found) { out << " "; @@ -1969,11 +1969,11 @@ void xpath_t::context::describe(std::ostream& out) const throw() } #endif -bool xpath_t::op_t::write(std::ostream& out, - const bool relaxed, - const op_t * op_to_find, - unsigned long * start_pos, - unsigned long * end_pos) const +bool xpath_t::op_t::print(std::ostream& out, + const bool relaxed, + const op_t * op_to_find, + unsigned long * start_pos, + unsigned long * end_pos) const { int arg_index = 0; bool found = false; @@ -2062,211 +2062,211 @@ bool xpath_t::op_t::write(std::ostream& out, case O_NOT: out << "!"; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_NEG: out << "-"; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_UNION: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " | "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_ADD: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " + "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_SUB: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " - "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_MUL: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " * "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_DIV: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " / "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_NEQ: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " != "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_EQ: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " == "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_LT: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " < "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_LTE: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " <= "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_GT: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " > "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_GTE: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " >= "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_AND: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " & "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_OR: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " | "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_QUES: out << "("; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " ? "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_COLON: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " : "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_COMMA: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ", "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; #if 0 case O_MATCH: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " =~ "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_NMATCH: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << " !~ "; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; #endif case O_DEFINE: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << '='; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_EVAL: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << "("; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case O_FIND: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << "/"; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_RFIND: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << "//"; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; case O_PRED: - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << "["; - if (right && right->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (right && right->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; out << "]"; break; @@ -2274,7 +2274,7 @@ bool xpath_t::op_t::write(std::ostream& out, #if 0 case O_PERC: out << "%"; - if (left && left->write(out, relaxed, op_to_find, start_pos, end_pos)) + if (left && left->print(out, relaxed, op_to_find, start_pos, end_pos)) found = true; break; #endif diff --git a/src/xpath.h b/src/xpath.h index 638ec482..7d1f1f44 100644 --- a/src/xpath.h +++ b/src/xpath.h @@ -475,7 +475,7 @@ public: static op_t * defer_sequence(value_t::sequence_t& result_seq); - bool write(std::ostream& out, + bool print(std::ostream& out, const bool relaxed = true, const op_t * op_to_find = NULL, unsigned long * start_pos = NULL, @@ -597,13 +597,13 @@ public: return parse_expr(string(p), tflags); } - bool write(std::ostream& out, + bool print(std::ostream& out, const bool relaxed, const op_t * op_to_find, unsigned long * start_pos, unsigned long * end_pos) const { if (ptr) - ptr->write(out, relaxed, op_to_find, start_pos, end_pos); + ptr->print(out, relaxed, op_to_find, start_pos, end_pos); return true; } @@ -739,8 +739,8 @@ public: return temp.calc(document, scope); } - void write(std::ostream& out) const { - write(out, true, NULL, NULL, NULL); + void print(std::ostream& out) const { + print(out, true, NULL, NULL, NULL); } void dump(std::ostream& out) const { if (ptr) @@ -751,7 +751,7 @@ public: }; inline std::ostream& operator<<(std::ostream& out, const xpath_t::op_t& op) { - op.write(out); + op.print(out); return out; }; @@ -774,7 +774,7 @@ class xml_command : public xml::xpath_t::functor_t std::ostream * out = get_ptr<std::ostream>(locals, 0); xml::document_t * doc = get_ptr<xml::document_t>(locals, 1); - doc->write(*out); + doc->print(*out); } }; |