]> git.tdb.fi Git - poefilter.git/commitdiff
Make the helper functions in CompoundCondition static
authorMikko Rasa <tdb@tdb.fi>
Fri, 17 Aug 2018 17:23:02 +0000 (20:23 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 17 Aug 2018 17:23:02 +0000 (20:23 +0300)
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.

source/condition.cpp
source/condition.h

index 1ff316c361f76f51d6f0c13db000cd21a4b621f1..6d383eafb278bf6592b1bca5447e1506d56fb541 100644 (file)
@@ -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<const Condition *> 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<Condition *>::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<Condition *>::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);
index bbabf22e5f27d98c8de47b0b4a58622a910dff63..af8aa95faa282c364c515111eb93e33dad6c061e 100644 (file)
@@ -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;