X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frangecondition.h;h=7d85125b6dae6392be187bf4932bf14b54f57867;hb=HEAD;hp=d4d11fa852605bb4f93b13be0e97c14ea5dc8c5c;hpb=51ea3d1cf0f411f0a41367bf218e28f9c16d86e0;p=poefilter.git diff --git a/source/rangecondition.h b/source/rangecondition.h index d4d11fa..7d85125 100644 --- a/source/rangecondition.h +++ b/source/rangecondition.h @@ -20,8 +20,9 @@ public: RangeCondition(Type, Type); virtual RangeCondition *clone() const; + virtual bool equals(const Condition &) const; virtual bool can_merge(const Condition &, const CompoundCondition &) const; - virtual RangeCondition *merge(const std::vector &, const CompoundCondition &) const; + virtual RangeCondition *merge(const std::vector &, const CompoundCondition &) const; virtual bool is_viable() const { return min<=max; } virtual void add_lines(std::list &) const; }; @@ -71,6 +72,17 @@ struct DropLevelTraits typedef RangeCondition DropLevelCondition; +struct MapTierTraits +{ + typedef unsigned Type; + static unsigned get_min() { return 1; } + static unsigned get_max() { return 17; } + static const char *get_keyword() { return "MapTier"; } +}; + +typedef RangeCondition MapTierCondition; + + struct WidthTraits { typedef unsigned Type; @@ -133,28 +145,58 @@ RangeCondition *RangeCondition::clone() const return new RangeCondition(min, max); } +template +bool RangeCondition::equals(const Condition &other) const +{ + const RangeCondition *other_range = dynamic_cast *>(&other); + if(!other_range) + return false; + + return (min==other_range->min && max==other_range->max); +} + template bool RangeCondition::can_merge(const Condition &other, const CompoundCondition &parent) const { - return dynamic_cast *>(&other) && dynamic_cast(&parent); + const RangeCondition *other_range = dynamic_cast *>(&other); + if(!other_range) + return false; + + if(dynamic_cast(&parent)) + return true; + else if(dynamic_cast(&parent)) + return min<=other_range->max+1 && max+1>=other_range->min; + else + return false; } template -RangeCondition *RangeCondition::merge(const std::vector &conditions, const CompoundCondition &parent) const +RangeCondition *RangeCondition::merge(const std::vector &conditions, const CompoundCondition &parent) const { - if(dynamic_cast(&parent) && !conditions.empty()) + if(conditions.empty()) + return 0; + + bool intersect = dynamic_cast(&parent); + RangeCondition *result; + if(intersect) + result = new RangeCondition(Traits::get_min(), Traits::get_max()); + else + result = new RangeCondition(Traits::get_max(), Traits::get_min()); + for(std::vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) { - RangeCondition *result = new RangeCondition(Traits::get_min(), Traits::get_max()); - for(std::vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) + const RangeCondition *c = static_cast *>(*i); + if(intersect) { - const RangeCondition *c = static_cast *>(*i); result->min = std::max(result->min, c->min); result->max = std::min(result->max, c->max); } - return result; + else + { + result->min = std::min(result->min, c->min); + result->max = std::max(result->max, c->max); + } } - else - return 0; + return result; } template