X-Git-Url: http://git.tdb.fi/?p=poefilter.git;a=blobdiff_plain;f=source%2Fcondition.cpp;fp=source%2Fcondition.cpp;h=e9400c4c2721fe07ec4510db2ccb916d96119daa;hp=6d383eafb278bf6592b1bca5447e1506d56fb541;hb=7d7eaf754af04f81bb1e7a8872272ea15e01d0c4;hpb=8dcb2ed5219429c1c7d543c422a7471c18917f55 diff --git a/source/condition.cpp b/source/condition.cpp index 6d383ea..e9400c4 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -16,6 +16,18 @@ void CompoundCondition::clone_to(CompoundCondition &other) const other.add((*i)->clone()); } +bool CompoundCondition::sub_equals(const CompoundCondition &other) const +{ + if(other.count()!=conditions.size()) + return false; + + for(unsigned i=0; iequals(other.get(i))) + return false; + + return true; +} + void CompoundCondition::add(Condition *cond) { if(!cond) @@ -171,6 +183,12 @@ AndCondition *AndCondition::clone() const return result; } +bool AndCondition::equals(const Condition &other) const +{ + const AndCondition *other_and = dynamic_cast(&other); + return (other_and ? sub_equals(*other_and) : false); +} + Condition *AndCondition::flatten(Condition *cond1, Condition *cond2) const { if(cond1->can_merge(*cond2, *this)) @@ -255,6 +273,12 @@ OrCondition *OrCondition::clone() const return result; } +bool OrCondition::equals(const Condition &other) const +{ + const OrCondition *other_or = dynamic_cast(&other); + return (other_or ? sub_equals(*other_or) : false); +} + Condition *OrCondition::flatten(Condition *cond1, Condition *cond2) const { if(cond1->can_merge(*cond2, *this)) @@ -321,6 +345,23 @@ LinkedColorsCondition *LinkedColorsCondition::clone() const return new LinkedColorsCondition(colors); } +bool LinkedColorsCondition::equals(const Condition &other) const +{ + const LinkedColorsCondition *other_linked = dynamic_cast(&other); + if(!other_linked) + return false; + + for(unsigned i=0; i<7; ++i) + { + if(colors.colors[i]!=other_linked->colors.colors[i]) + return false; + if(!colors.colors[i]) + break; + } + + return true; +} + void LinkedColorsCondition::add_lines(list &st) const { FilterStatement::add_line(st, format("SocketGroup %s", colors.colors));