summaryrefslogtreecommitdiff
path: root/src/generic/problemresolver/incremental_expression.h
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2009-05-26 07:48:58 -0700
committerDaniel Burrows <dburrows@debian.org>2009-05-26 07:48:58 -0700
commit6278813c55c587b6097585503bc55dea2a5a637b (patch)
tree94d0b0f23722ea3497c60a992d51ca26b23cb73b /src/generic/problemresolver/incremental_expression.h
parentfd9d589e704ed6bc527050444d77160a95255c85 (diff)
downloadaptitude-6278813c55c587b6097585503bc55dea2a5a637b.tar.gz
Write a helper class that contains the code needed to manage a container that contains just one value.
Diffstat (limited to 'src/generic/problemresolver/incremental_expression.h')
-rw-r--r--src/generic/problemresolver/incremental_expression.h44
1 files changed, 44 insertions, 0 deletions
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<typename T>
+class expression_box : public expression_container<T>
+{
+ cwidget::util::ref_ptr<expression<T> > child;
+
+public:
+ expression_box() : child() { }
+
+ expression_box(const cwidget::util::ref_ptr<expression<T> > &_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<expression<T> > &new_child)
+ {
+ child->remove_parent(this);
+ child = new_child;
+ new_child->add_parent(this);
+ }
+
+ const cwidget::util::ref_ptr<expression<T> > &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.
*/