From 6278813c55c587b6097585503bc55dea2a5a637b Mon Sep 17 00:00:00 2001 From: Daniel Burrows Date: Tue, 26 May 2009 07:48:58 -0700 Subject: Write a helper class that contains the code needed to manage a container that contains just one value. --- .../problemresolver/incremental_expression.h | 44 ++++++++++++++++++++++ 1 file changed, 44 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 73037133..3284163f 100644 --- a/src/generic/problemresolver/incremental_expression.h +++ b/src/generic/problemresolver/incremental_expression.h @@ -251,6 +251,50 @@ public: T new_value) = 0; }; +/** \brief Base class for objects that have a single sub-expression. */ +template +class expression_box : public expression_container +{ + cwidget::util::ref_ptr > child; + +public: + expression_box() : child() { } + + expression_box(const cwidget::util::ref_ptr > &_child) + : child(_child) + { + if(child.valid()) + child->add_parent(this); + } + + expression_box(const expression_box &other) + : child(other.child) + { + if(child.valid()) + child->add_parent(this); + } + + ~expression_box() + { + child->remove_parent(this); + } + + void set_child(const cwidget::util::ref_ptr > &new_child) + { + child->remove_parent(this); + child = new_child; + new_child->add_parent(this); + } + + const cwidget::util::ref_ptr > &get_child() const + { + return child; + } + + /** \brief Returns the child's value. */ + T get_value() { return child->get_value(); } +}; + /** \brief Base class for N-ary containers that support adding and * removing children. */ -- cgit v1.2.3