From 10d07302179b83de4d574c437ac0428c9ba18f85 Mon Sep 17 00:00:00 2001 From: Daniel Burrows Date: Fri, 22 May 2009 07:29:53 -0700 Subject: Add support for dumping incremental expression trees. Current values aren't dumped at the moment. --- .../problemresolver/incremental_expression.h | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/generic/problemresolver/incremental_expression.h') 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 #include +#include + // 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 > >::const_iterator + it = get_children().begin(); it != get_children().end(); ++it) + { + if(it != get_children().begin()) + out << ", "; + + (*it)->dump(out); + } + out << ")"; + } }; template @@ -285,6 +304,9 @@ expression_weak_ref::~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 class var_e : public expression @@ -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 @@ -435,8 +466,17 @@ public: bool old_value, bool new_value); bool get_value(); + void dump(std::ostream &out); }; +template +std::ostream &operator<<(std::ostream &out, + const cwidget::util::ref_ptr > &o) +{ + o->dump(out); + return out; +} + // @} #endif -- cgit v1.2.3