X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frangecondition.h;h=d4d11fa852605bb4f93b13be0e97c14ea5dc8c5c;hb=51ea3d1cf0f411f0a41367bf218e28f9c16d86e0;hp=d4cc19a7889e460351506628d37c0b89bfdd8a4f;hpb=fc27eb63c05d915d606e17992ecd5b7f68478101;p=poefilter.git diff --git a/source/rangecondition.h b/source/rangecondition.h index d4cc19a..d4d11fa 100644 --- a/source/rangecondition.h +++ b/source/rangecondition.h @@ -19,7 +19,10 @@ public: RangeCondition(Type); RangeCondition(Type, Type); - virtual Condition *clone() const; + virtual RangeCondition *clone() const; + virtual bool can_merge(const Condition &, 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; }; @@ -49,7 +52,7 @@ typedef RangeCondition QualityCondition; struct ItemLevelTraits { typedef unsigned Type; - static unsigned get_min() { return 0; } + static unsigned get_min() { return 1; } static unsigned get_max() { return 100; } static const char *get_keyword() { return "ItemLevel"; } }; @@ -60,7 +63,7 @@ typedef RangeCondition ItemLevelCondition; struct DropLevelTraits { typedef unsigned Type; - static unsigned get_min() { return 0; } + static unsigned get_min() { return 1; } static unsigned get_max() { return 100; } static const char *get_keyword() { return "DropLevel"; } }; @@ -112,26 +115,50 @@ struct LinkedSocketsTraits typedef RangeCondition LinkedSocketsCondition; -template -RangeCondition::RangeCondition(Type v): +template +RangeCondition::RangeCondition(Type v): min(v), max(v) { } -template -RangeCondition::RangeCondition(Type n, Type x): +template +RangeCondition::RangeCondition(Type n, Type x): min(n), max(x) { } -template -Condition *RangeCondition::clone() const +template +RangeCondition *RangeCondition::clone() const { - return new RangeCondition(min, max); + return new RangeCondition(min, max); } -template -void RangeCondition::add_lines(std::list &st) const +template +bool RangeCondition::can_merge(const Condition &other, const CompoundCondition &parent) const +{ + return dynamic_cast *>(&other) && dynamic_cast(&parent); +} + +template +RangeCondition *RangeCondition::merge(const std::vector &conditions, const CompoundCondition &parent) const +{ + if(dynamic_cast(&parent) && !conditions.empty()) + { + 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); + result->min = std::max(result->min, c->min); + result->max = std::min(result->max, c->max); + } + return result; + } + else + return 0; +} + +template +void RangeCondition::add_lines(std::list &st) const { const char *keyword = Traits::get_keyword(); if(min==max)