Changed write methods to print.
This commit is contained in:
parent
8aada79971
commit
a07e20c14e
14 changed files with 255 additions and 99 deletions
|
|
@ -1176,8 +1176,7 @@ void amount_t::print(std::ostream& _out, bool omit_commodity,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! omit_commodity && ! comm.has_flags(COMMODITY_STYLE_SUFFIXED)) {
|
if (! omit_commodity && ! comm.has_flags(COMMODITY_STYLE_SUFFIXED)) {
|
||||||
comm.write(out);
|
comm.print(out);
|
||||||
|
|
||||||
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))
|
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))
|
||||||
out << " ";
|
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 (! omit_commodity && comm.has_flags(COMMODITY_STYLE_SUFFIXED)) {
|
||||||
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))
|
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))
|
||||||
out << " ";
|
out << " ";
|
||||||
|
comm.print(out);
|
||||||
comm.write(out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mpz_clear(quotient);
|
mpz_clear(quotient);
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ balance_t balance_t::strip_annotations(const bool keep_price,
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void balance_t::write(std::ostream& out,
|
void balance_t::print(std::ostream& out,
|
||||||
const int first_width,
|
const int first_width,
|
||||||
const int latter_width) const
|
const int latter_width) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ public:
|
||||||
const bool keep_date = amount_t::keep_date,
|
const bool keep_date = amount_t::keep_date,
|
||||||
const bool keep_tag = amount_t::keep_tag) const;
|
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;
|
const int latter_width = -1) const;
|
||||||
|
|
||||||
balance_t abs() const {
|
balance_t abs() const {
|
||||||
|
|
@ -216,7 +216,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, const balance_t& bal) {
|
inline std::ostream& operator<<(std::ostream& out, const balance_t& bal) {
|
||||||
bal.write(out, 12);
|
bal.print(out, 12);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,9 +351,9 @@ public:
|
||||||
return quantity.strip_annotations(keep_price, keep_date, keep_tag);
|
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 {
|
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,
|
balance_pair_t& add(const amount_t& amt,
|
||||||
|
|
@ -404,7 +404,7 @@ public:
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out,
|
inline std::ostream& operator<<(std::ostream& out,
|
||||||
const balance_pair_t& bal_pair) {
|
const balance_pair_t& bal_pair) {
|
||||||
bal_pair.quantity.write(out, 12);
|
bal_pair.quantity.print(out, 12);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,7 @@ namespace {
|
||||||
throw_(amount_error, "A commodity's price may not be negative");
|
throw_(amount_error, "A commodity's price may not be negative");
|
||||||
|
|
||||||
std::ostringstream name;
|
std::ostringstream name;
|
||||||
comm.write(name);
|
comm.print(name);
|
||||||
annotated_commodity_t::write_annotations(name, details);
|
annotated_commodity_t::write_annotations(name, details);
|
||||||
|
|
||||||
DEBUG("amounts.commodities", "make_qualified_name for "
|
DEBUG("amounts.commodities", "make_qualified_name for "
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ public:
|
||||||
optional<amount_t> value(const optional<moment_t>& moment =
|
optional<amount_t> value(const optional<moment_t>& moment =
|
||||||
optional<moment_t>());
|
optional<moment_t>());
|
||||||
|
|
||||||
void write(std::ostream& out) const {
|
void print(std::ostream& out) const {
|
||||||
out << symbol();
|
out << symbol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +200,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
|
inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
|
||||||
comm.write(out);
|
comm.print(out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +226,7 @@ struct annotation_t : public equality_comparable<annotation_t>
|
||||||
tag == rhs.tag);
|
tag == rhs.tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(std::ostream& out) const {
|
void print(std::ostream& out) const {
|
||||||
out << "price " << (price ? price->to_string() : "NONE") << " "
|
out << "price " << (price ? price->to_string() : "NONE") << " "
|
||||||
<< "date " << (date ? *date : moment_t()) << " "
|
<< "date " << (date ? *date : moment_t()) << " "
|
||||||
<< "tag " << (tag ? *tag : "NONE");
|
<< "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) {
|
inline std::ostream& operator<<(std::ostream& out, const annotation_t& details) {
|
||||||
details.write(out);
|
details.print(out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ int format_t::element_formatter_t::operator()
|
||||||
|
|
||||||
if (elem->kind == element_t::XPATH)
|
if (elem->kind == element_t::XPATH)
|
||||||
elem->xpath->calc(context).strip_annotations()
|
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)
|
else if (elem->kind == element_t::GROUP)
|
||||||
column = elem->format->format(out, context, column);
|
column = elem->format->format(out, context, column);
|
||||||
else if (elem->kind == element_t::TEXT)
|
else if (elem->kind == element_t::TEXT)
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ static int read_and_report(report_t * report, int argc, char * argv[],
|
||||||
expr.dump(std::cout);
|
expr.dump(std::cout);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "Value expression parsed was:" << 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 << std::endl << std::endl;
|
||||||
std::cout << "Result of calculation: ";
|
std::cout << "Result of calculation: ";
|
||||||
}
|
}
|
||||||
|
|
@ -250,7 +250,7 @@ static int read_and_report(report_t * report, int argc, char * argv[],
|
||||||
expr.dump(*out);
|
expr.dump(*out);
|
||||||
*out << std::endl;
|
*out << std::endl;
|
||||||
*out << "Value expression parsed was:" << std::endl;
|
*out << "Value expression parsed was:" << std::endl;
|
||||||
expr.write(*out);
|
expr.print(*out);
|
||||||
*out << std::endl << std::endl;
|
*out << std::endl << std::endl;
|
||||||
*out << "Result of calculation: ";
|
*out << "Result of calculation: ";
|
||||||
}
|
}
|
||||||
|
|
@ -263,7 +263,7 @@ static int read_and_report(report_t * report, int argc, char * argv[],
|
||||||
else if (verb == "xpath") {
|
else if (verb == "xpath") {
|
||||||
std::cout << "XPath parsed:" << std::endl;
|
std::cout << "XPath parsed:" << std::endl;
|
||||||
xml::xpath_t xpath(*arg);
|
xml::xpath_t xpath(*arg);
|
||||||
xpath.write(*out);
|
xpath.print(*out);
|
||||||
*out << std::endl;
|
*out << std::endl;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,163 @@
|
||||||
#ifndef _SCOPE_EXECUTE_H
|
#ifndef _SCOPED_EXECUTE_H
|
||||||
#define _SCOPE_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>
|
template <typename T>
|
||||||
class scoped_variable : public boost::noncopyable
|
class scoped_variable : public boost::noncopyable
|
||||||
|
|
@ -70,4 +228,4 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _SCOPE_EXECUTE_H
|
#endif // _SCOPED_EXECUTE_H
|
||||||
|
|
|
||||||
10
src/value.cc
10
src/value.cc
|
|
@ -2215,7 +2215,7 @@ value_t& value_t::add(const amount_t& amount, const optional<amount_t>& tcost)
|
||||||
return *this;
|
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
|
const int latter_width) const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
@ -2229,7 +2229,7 @@ void value_t::write(std::ostream& out, const int first_width,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XML_NODE:
|
case XML_NODE:
|
||||||
(*(xml::node_t **) data)->write(out);
|
(*(xml::node_t **) data)->print(out);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEQUENCE:
|
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");
|
throw_(value_error, "Cannot write out a sequence");
|
||||||
|
|
||||||
case BALANCE:
|
case BALANCE:
|
||||||
((balance_t *) data)->write(out, first_width, latter_width);
|
((balance_t *) data)->print(out, first_width, latter_width);
|
||||||
break;
|
break;
|
||||||
case BALANCE_PAIR:
|
case BALANCE_PAIR:
|
||||||
((balance_pair_t *) data)->write(out, first_width, latter_width);
|
((balance_pair_t *) data)->print(out, first_width, latter_width);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2344,7 +2344,7 @@ void value_context::describe(std::ostream& out) const throw()
|
||||||
if (! ptr)
|
if (! ptr)
|
||||||
ptr = &((balance_pair_t *) bal->data)->quantity;
|
ptr = &((balance_pair_t *) bal->data)->quantity;
|
||||||
|
|
||||||
ptr->write(out, 20);
|
ptr->print(out, 20);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,7 @@ class value_t
|
||||||
value_t round() const;
|
value_t round() const;
|
||||||
value_t unround() 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;
|
const int latter_width = -1) const;
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& out, const value_t& val);
|
friend std::ostream& operator<<(std::ostream& out, const value_t& val);
|
||||||
|
|
|
||||||
10
src/xml.cc
10
src/xml.cc
|
|
@ -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) {
|
if (top) {
|
||||||
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
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;
|
_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 << " ";
|
for (int i = 0; i < depth; i++) out << " ";
|
||||||
out << '<' << name() << ">\n";
|
out << '<' << name() << ">\n";
|
||||||
|
|
||||||
for (node_t * child = children(); child; child = child->next)
|
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 << " ";
|
for (int i = 0; i < depth; i++) out << " ";
|
||||||
out << "</" << name() << ">\n";
|
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 << " ";
|
for (int i = 0; i < depth; i++) out << " ";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ public:
|
||||||
throw_(conversion_error, "Cannot convert node to a value");
|
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:
|
private:
|
||||||
node_t(const node_t&);
|
node_t(const node_t&);
|
||||||
|
|
@ -124,7 +124,7 @@ public:
|
||||||
}
|
}
|
||||||
virtual void add_child(node_t * node);
|
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:
|
private:
|
||||||
parent_node_t(const parent_node_t&);
|
parent_node_t(const parent_node_t&);
|
||||||
|
|
@ -159,7 +159,7 @@ public:
|
||||||
return text();
|
return text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(std::ostream& out, int depth = 0) const;
|
void print(std::ostream& out, int depth = 0) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
terminal_node_t(const node_t&);
|
terminal_node_t(const node_t&);
|
||||||
|
|
@ -218,7 +218,7 @@ private:
|
||||||
static int lookup_builtin_id(const string& name);
|
static int lookup_builtin_id(const string& name);
|
||||||
const char * lookup_name(int id) const;
|
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)
|
#if defined(HAVE_EXPAT) || defined(HAVE_XMLPARSE)
|
||||||
class parser_t
|
class parser_t
|
||||||
|
|
|
||||||
102
src/xpath.cc
102
src/xpath.cc
|
|
@ -1954,7 +1954,7 @@ void xpath_t::context::describe(std::ostream& out) const throw()
|
||||||
unsigned long end;
|
unsigned long end;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (xpath)
|
if (xpath)
|
||||||
xpath.write(out, true, err_node, &begin, &end);
|
xpath.print(out, true, err_node, &begin, &end);
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
if (found) {
|
if (found) {
|
||||||
out << " ";
|
out << " ";
|
||||||
|
|
@ -1969,7 +1969,7 @@ void xpath_t::context::describe(std::ostream& out) const throw()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool xpath_t::op_t::write(std::ostream& out,
|
bool xpath_t::op_t::print(std::ostream& out,
|
||||||
const bool relaxed,
|
const bool relaxed,
|
||||||
const op_t * op_to_find,
|
const op_t * op_to_find,
|
||||||
unsigned long * start_pos,
|
unsigned long * start_pos,
|
||||||
|
|
@ -2062,211 +2062,211 @@ bool xpath_t::op_t::write(std::ostream& out,
|
||||||
|
|
||||||
case O_NOT:
|
case O_NOT:
|
||||||
out << "!";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case O_NEG:
|
case O_NEG:
|
||||||
out << "-";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_UNION:
|
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;
|
found = true;
|
||||||
out << " | ";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_ADD:
|
case O_ADD:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " + ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_SUB:
|
case O_SUB:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " - ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_MUL:
|
case O_MUL:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " * ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_DIV:
|
case O_DIV:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " / ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_NEQ:
|
case O_NEQ:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " != ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_EQ:
|
case O_EQ:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " == ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_LT:
|
case O_LT:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " < ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_LTE:
|
case O_LTE:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " <= ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_GT:
|
case O_GT:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " > ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_GTE:
|
case O_GTE:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " >= ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_AND:
|
case O_AND:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " & ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_OR:
|
case O_OR:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " | ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_QUES:
|
case O_QUES:
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << " ? ";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
case O_COLON:
|
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;
|
found = true;
|
||||||
out << " : ";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_COMMA:
|
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;
|
found = true;
|
||||||
out << ", ";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
case O_MATCH:
|
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;
|
found = true;
|
||||||
out << " =~ ";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case O_NMATCH:
|
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;
|
found = true;
|
||||||
out << " !~ ";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case O_DEFINE:
|
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;
|
found = true;
|
||||||
out << '=';
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case O_EVAL:
|
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;
|
found = true;
|
||||||
out << "(";
|
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;
|
found = true;
|
||||||
out << ")";
|
out << ")";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_FIND:
|
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;
|
found = true;
|
||||||
out << "/";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case O_RFIND:
|
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;
|
found = true;
|
||||||
out << "//";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
case O_PRED:
|
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;
|
found = true;
|
||||||
out << "[";
|
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;
|
found = true;
|
||||||
out << "]";
|
out << "]";
|
||||||
break;
|
break;
|
||||||
|
|
@ -2274,7 +2274,7 @@ bool xpath_t::op_t::write(std::ostream& out,
|
||||||
#if 0
|
#if 0
|
||||||
case O_PERC:
|
case O_PERC:
|
||||||
out << "%";
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
14
src/xpath.h
14
src/xpath.h
|
|
@ -475,7 +475,7 @@ public:
|
||||||
|
|
||||||
static op_t * defer_sequence(value_t::sequence_t& result_seq);
|
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 bool relaxed = true,
|
||||||
const op_t * op_to_find = NULL,
|
const op_t * op_to_find = NULL,
|
||||||
unsigned long * start_pos = NULL,
|
unsigned long * start_pos = NULL,
|
||||||
|
|
@ -597,13 +597,13 @@ public:
|
||||||
return parse_expr(string(p), tflags);
|
return parse_expr(string(p), tflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write(std::ostream& out,
|
bool print(std::ostream& out,
|
||||||
const bool relaxed,
|
const bool relaxed,
|
||||||
const op_t * op_to_find,
|
const op_t * op_to_find,
|
||||||
unsigned long * start_pos,
|
unsigned long * start_pos,
|
||||||
unsigned long * end_pos) const {
|
unsigned long * end_pos) const {
|
||||||
if (ptr)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -739,8 +739,8 @@ public:
|
||||||
return temp.calc(document, scope);
|
return temp.calc(document, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(std::ostream& out) const {
|
void print(std::ostream& out) const {
|
||||||
write(out, true, NULL, NULL, NULL);
|
print(out, true, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
void dump(std::ostream& out) const {
|
void dump(std::ostream& out) const {
|
||||||
if (ptr)
|
if (ptr)
|
||||||
|
|
@ -751,7 +751,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, const xpath_t::op_t& op) {
|
inline std::ostream& operator<<(std::ostream& out, const xpath_t::op_t& op) {
|
||||||
op.write(out);
|
op.print(out);
|
||||||
return 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);
|
std::ostream * out = get_ptr<std::ostream>(locals, 0);
|
||||||
xml::document_t * doc = get_ptr<xml::document_t>(locals, 1);
|
xml::document_t * doc = get_ptr<xml::document_t>(locals, 1);
|
||||||
|
|
||||||
doc->write(*out);
|
doc->print(*out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue