1 #ifndef RANGECONDITION_H_
2 #define RANGECONDITION_H_
8 class RangeCondition: public Condition
12 typedef typename Traits::Type Type;
20 RangeCondition(Type, Type);
22 virtual RangeCondition<T> *clone() const;
23 virtual bool can_merge(const Condition &, const CompoundCondition &) const;
24 virtual RangeCondition<T> *merge(const std::vector<Condition *> &, const CompoundCondition &) const;
25 virtual bool is_viable() const { return min<=max; }
26 virtual void add_lines(std::list<FilterStatement> &) const;
33 static Rarity get_min() { return NORMAL; }
34 static Rarity get_max() { return UNIQUE; }
35 static const char *get_keyword() { return "Rarity"; }
38 typedef RangeCondition<RarityTraits> RarityCondition;
43 typedef unsigned Type;
44 static unsigned get_min() { return 0; }
45 static unsigned get_max() { return 20; }
46 static const char *get_keyword() { return "Quality"; }
49 typedef RangeCondition<QualityTraits> QualityCondition;
52 struct ItemLevelTraits
54 typedef unsigned Type;
55 static unsigned get_min() { return 0; }
56 static unsigned get_max() { return 100; }
57 static const char *get_keyword() { return "ItemLevel"; }
60 typedef RangeCondition<ItemLevelTraits> ItemLevelCondition;
63 struct DropLevelTraits
65 typedef unsigned Type;
66 static unsigned get_min() { return 0; }
67 static unsigned get_max() { return 100; }
68 static const char *get_keyword() { return "DropLevel"; }
71 typedef RangeCondition<DropLevelTraits> DropLevelCondition;
76 typedef unsigned Type;
77 static unsigned get_min() { return 1; }
78 static unsigned get_max() { return 2; }
79 static const char *get_keyword() { return "Width"; }
82 typedef RangeCondition<WidthTraits> WidthCondition;
87 typedef unsigned Type;
88 static unsigned get_min() { return 1; }
89 static unsigned get_max() { return 4; }
90 static const char *get_keyword() { return "Height"; }
93 typedef RangeCondition<HeightTraits> HeightCondition;
98 typedef unsigned Type;
99 static unsigned get_min() { return 1; }
100 static unsigned get_max() { return 6; }
101 static const char *get_keyword() { return "Sockets"; }
104 typedef RangeCondition<SocketsTraits> SocketsCondition;
107 struct LinkedSocketsTraits
109 typedef unsigned Type;
110 static unsigned get_min() { return 1; }
111 static unsigned get_max() { return 6; }
112 static const char *get_keyword() { return "LinkedSockets"; }
115 typedef RangeCondition<LinkedSocketsTraits> LinkedSocketsCondition;
119 RangeCondition<T>::RangeCondition(Type v):
125 RangeCondition<T>::RangeCondition(Type n, Type x):
131 RangeCondition<T> *RangeCondition<T>::clone() const
133 return new RangeCondition<T>(min, max);
137 bool RangeCondition<T>::can_merge(const Condition &other, const CompoundCondition &parent) const
139 return dynamic_cast<const RangeCondition<T> *>(&other) && dynamic_cast<const AndCondition *>(&parent);
143 RangeCondition<T> *RangeCondition<T>::merge(const std::vector<Condition *> &conditions, const CompoundCondition &parent) const
145 if(dynamic_cast<const AndCondition *>(&parent) && !conditions.empty())
147 RangeCondition<T> *result = new RangeCondition<T>(Traits::get_min(), Traits::get_max());
148 for(std::vector<Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
150 const RangeCondition<T> *c = static_cast<RangeCondition<T> *>(*i);
151 result->min = std::max(result->min, c->min);
152 result->max = std::min(result->max, c->max);
161 void RangeCondition<T>::add_lines(std::list<FilterStatement> &st) const
163 const char *keyword = Traits::get_keyword();
165 FilterStatement::add_line(st, Msp::format("%s %s", keyword, min));
168 if(min!=Traits::get_min())
169 FilterStatement::add_line(st, Msp::format("%s >= %s", keyword, min));
170 if(max!=Traits::get_max())
171 FilterStatement::add_line(st, Msp::format("%s <= %s", keyword, max));