diff options
author | Daniel Burrows <dburrows@debian.org> | 2009-05-22 07:29:53 -0700 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2009-05-22 07:29:53 -0700 |
commit | 10d07302179b83de4d574c437ac0428c9ba18f85 (patch) | |
tree | a2ae5074bf340e2086e3fa03a0ed00451c92bc54 /src/generic/problemresolver/incremental_expression.h | |
parent | f167c75c57f71666aeef540a9084d5da673c3134 (diff) | |
download | aptitude-10d07302179b83de4d574c437ac0428c9ba18f85.tar.gz |
Add support for dumping incremental expression trees.
Current values aren't dumped at the moment.
Diffstat (limited to 'src/generic/problemresolver/incremental_expression.h')
-rw-r--r-- | src/generic/problemresolver/incremental_expression.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/generic/problemresolver/incremental_expression.h b/src/generic/problemresolver/incremental_expression.h index c0bbf03a..0456b95e 100644 --- a/src/generic/problemresolver/incremental_expression.h +++ b/src/generic/problemresolver/incremental_expression.h @@ -29,6 +29,8 @@ #include <algorithm> #include <set> +#include <ostream> + // A system of incrementally computed expressions stored as a DAG. // NOT THREADSAFE (the weak-reference system would utterly break in // the presence of threads without a lot of expensive locking, and @@ -187,6 +189,7 @@ public: } virtual T get_value() = 0; + virtual void dump(std::ostream &out) = 0; }; /** \brief Base class for expressions that can contain other @@ -242,6 +245,22 @@ public: children.erase(new_end, children.end()); } + + virtual std::string get_name() = 0; + + virtual void dump(std::ostream &out) + { + out << get_name() << "("; + for(std::vector<cwidget::util::ref_ptr<expression<bool> > >::const_iterator + it = get_children().begin(); it != get_children().end(); ++it) + { + if(it != get_children().begin()) + out << ", "; + + (*it)->dump(out); + } + out << ")"; + } }; template<typename T> @@ -285,6 +304,9 @@ expression_weak_ref<T>::~expression_weak_ref() * * Variables can be modified arbitrarily; changes are immediately * propagated to parent expressions. + * + * It would be nice if the user could attach names for better + * printing of expressions, but that would take a lot of memory. */ template<typename T> class var_e : public expression<T> @@ -318,6 +340,11 @@ public: signal_value_changed(old_value, new_value); } } + + void dump(std::ostream &out) + { + out << "v" << this; + } }; /** \brief Boolean-specific expressions. */ @@ -383,6 +410,8 @@ public: } bool get_value(); + std::string get_name(); + void dump(std::ostream &out); }; class or_e : public counting_bool_e @@ -413,6 +442,8 @@ public: } bool get_value(); + std::string get_name(); + void dump(std::ostream &out); }; class not_e : public expression_container<bool> @@ -435,8 +466,17 @@ public: bool old_value, bool new_value); bool get_value(); + void dump(std::ostream &out); }; +template<typename T> +std::ostream &operator<<(std::ostream &out, + const cwidget::util::ref_ptr<expression<T> > &o) +{ + o->dump(out); + return out; +} + // @} #endif |