From d402def2347de99220cd9995d900e88a5408331b Mon Sep 17 00:00:00 2001 From: Daniel Burrows Date: Sat, 23 May 2009 12:44:54 -0700 Subject: 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. --- .../problemresolver/incremental_expression.h | 38 ++++++++++++++++++++++ 1 file changed, 38 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 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 *parent; + + public: + parent_equals_weak_ref(const expression_container *_parent) + : parent(_parent) + { + } + + bool operator()(const expression_weak_ref > &other) const + { + return other == parent; + } + }; + +public: + void remove_parent(expression_container *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 > >::iterator new_end = std::remove(children.begin(), children.end(), child); + child->remove_parent(this); children.erase(new_end, children.end()); } -- cgit v1.2.3