From: Mikko Rasa Date: Fri, 17 Aug 2018 17:23:02 +0000 (+0300) Subject: Make the helper functions in CompoundCondition static X-Git-Url: http://git.tdb.fi/?p=poefilter.git;a=commitdiff_plain;h=8dcb2ed5219429c1c7d543c422a7471c18917f55 Make the helper functions in CompoundCondition static Merge_two now takes an explicit parent parameter to fix an inconsistency between the can_merge call from add_merged_to and the actual merge call in merge_two. --- diff --git a/source/condition.cpp b/source/condition.cpp index 1ff316c..6d383ea 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -100,12 +100,12 @@ Condition *CompoundCondition::dispatch_flatten(Condition *cond1, Condition *cond throw logic_error("CompoundCondition::dispatch_flatten"); } -Condition *CompoundCondition::merge_two(Condition *cond1, Condition *cond2, bool del) const +Condition *CompoundCondition::merge_two(Condition *cond1, Condition *cond2, const CompoundCondition &parent, bool del) { vector parts(2); parts[0] = cond1; parts[1] = cond2; - Condition *result = cond1->merge(parts, *this); + Condition *result = cond1->merge(parts, parent); if(del) { @@ -122,13 +122,13 @@ Condition *CompoundCondition::merge_two(Condition *cond1, Condition *cond2, bool return result; } -Condition *CompoundCondition::add_merged_to(Condition *cond, CompoundCondition *target, bool del) const +Condition *CompoundCondition::add_merged_to(Condition *cond, CompoundCondition *target, bool del) { bool merged = false; for(vector::iterator i=target->conditions.begin(); i!=target->conditions.end(); ++i) if((*i)->can_merge(*cond, *target)) { - Condition *m = merge_two(cond, *i, false); + Condition *m = merge_two(cond, *i, *target, false); delete *i; if(del) delete cond; @@ -149,7 +149,7 @@ Condition *CompoundCondition::add_merged_to(Condition *cond, CompoundCondition * return target; } -Condition *CompoundCondition::merge_contents_to(CompoundCondition *cond, CompoundCondition *target) const +Condition *CompoundCondition::merge_contents_to(CompoundCondition *cond, CompoundCondition *target) { for(vector::iterator i=cond->conditions.begin(); i!=cond->conditions.end(); ++i) add_merged_to(*i, target, false); @@ -174,7 +174,7 @@ AndCondition *AndCondition::clone() const Condition *AndCondition::flatten(Condition *cond1, Condition *cond2) const { if(cond1->can_merge(*cond2, *this)) - return merge_two(cond1, cond2, true); + return merge_two(cond1, cond2, *this, true); AndCondition *result = new AndCondition; result->add(cond1); @@ -258,7 +258,7 @@ OrCondition *OrCondition::clone() const Condition *OrCondition::flatten(Condition *cond1, Condition *cond2) const { if(cond1->can_merge(*cond2, *this)) - return merge_two(cond1, cond2, true); + return merge_two(cond1, cond2, *this, true); OrCondition *result = new OrCondition; result->add(cond1); diff --git a/source/condition.h b/source/condition.h index bbabf22..af8aa95 100644 --- a/source/condition.h +++ b/source/condition.h @@ -48,9 +48,9 @@ public: virtual Condition *flatten() const; protected: Condition *dispatch_flatten(Condition *, Condition *) const; - Condition *merge_two(Condition *, Condition *, bool) const; - Condition *add_merged_to(Condition *, CompoundCondition *, bool) const; - Condition *merge_contents_to(CompoundCondition *, CompoundCondition *) const; + static Condition *merge_two(Condition *, Condition *, const CompoundCondition &, bool); + static Condition *add_merged_to(Condition *, CompoundCondition *, bool); + static Condition *merge_contents_to(CompoundCondition *, CompoundCondition *); virtual Condition *flatten(Condition *, Condition *) const = 0; virtual Condition *flatten(AndCondition *, Condition *) const = 0; virtual Condition *flatten(AndCondition *, AndCondition *) const = 0;