summaryrefslogtreecommitdiff
path: root/src/generic/problemresolver/incremental_expression.h
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2009-05-23 12:44:54 -0700
committerDaniel Burrows <dburrows@debian.org>2009-05-23 12:44:54 -0700
commitd402def2347de99220cd9995d900e88a5408331b (patch)
tree3674d87888fb5cf884d44cd4325109c736e3855e /src/generic/problemresolver/incremental_expression.h
parent6d299befb680edc1bc19e3a57acbd94a702a035b (diff)
downloadaptitude-d402def2347de99220cd9995d900e88a5408331b.tar.gz
Fix up parent lists by removing parents that are going away.
This could be used to avoid weak references, but it would be a bit costly. I don't expect this will actually be used much, but it will avoid a correctness violation if we need it.
Diffstat (limited to 'src/generic/problemresolver/incremental_expression.h')
-rw-r--r--src/generic/problemresolver/incremental_expression.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/generic/problemresolver/incremental_expression.h b/src/generic/problemresolver/incremental_expression.h
index 0f670d57..737925b4 100644
--- a/src/generic/problemresolver/incremental_expression.h
+++ b/src/generic/problemresolver/incremental_expression.h
@@ -113,6 +113,16 @@ public:
return expr;
}
+ bool operator==(const expression_weak_ref &other) const
+ {
+ return expr == other.expr;
+ }
+
+ bool operator==(const T *other) const
+ {
+ return expr == other;
+ }
+
~expression_weak_ref();
};
@@ -198,6 +208,33 @@ public:
parents.push_back(parent);
}
+private:
+ class parent_equals_weak_ref
+ {
+ const expression_container<T> *parent;
+
+ public:
+ parent_equals_weak_ref(const expression_container<T> *_parent)
+ : parent(_parent)
+ {
+ }
+
+ bool operator()(const expression_weak_ref<expression_container<T> > &other) const
+ {
+ return other == parent;
+ }
+ };
+
+public:
+ void remove_parent(expression_container<T> *parent)
+ {
+ // Will be inefficient if this happens a lot, but I don't expect
+ // it to be a common operation.
+ parents.erase(std::remove_if(parents.begin(), parents.end(),
+ parent_equals_weak_ref(parent)),
+ parents.end());
+ }
+
virtual T get_value() = 0;
virtual void dump(std::ostream &out) = 0;
};
@@ -256,6 +293,7 @@ public:
typename std::vector<cwidget::util::ref_ptr<expression<T> > >::iterator
new_end = std::remove(children.begin(), children.end(), child);
+ child->remove_parent(this);
children.erase(new_end, children.end());
}