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 void add_lines(std::list<FilterStatement> &) const;
32 static Rarity get_min() { return NORMAL; }
33 static Rarity get_max() { return UNIQUE; }
34 static const char *get_keyword() { return "Rarity"; }
37 typedef RangeCondition<RarityTraits> RarityCondition;
42 typedef unsigned Type;
43 static unsigned get_min() { return 0; }
44 static unsigned get_max() { return 20; }
45 static const char *get_keyword() { return "Quality"; }
48 typedef RangeCondition<QualityTraits> QualityCondition;
51 struct ItemLevelTraits
53 typedef unsigned Type;
54 static unsigned get_min() { return 0; }
55 static unsigned get_max() { return 100; }
56 static const char *get_keyword() { return "ItemLevel"; }
59 typedef RangeCondition<ItemLevelTraits> ItemLevelCondition;
62 struct DropLevelTraits
64 typedef unsigned Type;
65 static unsigned get_min() { return 0; }
66 static unsigned get_max() { return 100; }
67 static const char *get_keyword() { return "DropLevel"; }
70 typedef RangeCondition<DropLevelTraits> DropLevelCondition;
75 typedef unsigned Type;
76 static unsigned get_min() { return 1; }
77 static unsigned get_max() { return 2; }
78 static const char *get_keyword() { return "Width"; }
81 typedef RangeCondition<WidthTraits> WidthCondition;
86 typedef unsigned Type;
87 static unsigned get_min() { return 1; }
88 static unsigned get_max() { return 4; }
89 static const char *get_keyword() { return "Height"; }
92 typedef RangeCondition<HeightTraits> HeightCondition;
97 typedef unsigned Type;
98 static unsigned get_min() { return 1; }
99 static unsigned get_max() { return 6; }
100 static const char *get_keyword() { return "Sockets"; }
103 typedef RangeCondition<SocketsTraits> SocketsCondition;
106 struct LinkedSocketsTraits
108 typedef unsigned Type;
109 static unsigned get_min() { return 1; }
110 static unsigned get_max() { return 6; }
111 static const char *get_keyword() { return "LinkedSockets"; }
114 typedef RangeCondition<LinkedSocketsTraits> LinkedSocketsCondition;
118 RangeCondition<T>::RangeCondition(Type v):
124 RangeCondition<T>::RangeCondition(Type n, Type x):
130 RangeCondition<T> *RangeCondition<T>::clone() const
132 return new RangeCondition<T>(min, max);
136 bool RangeCondition<T>::can_merge(const Condition &other, const CompoundCondition &parent) const
138 return dynamic_cast<const RangeCondition<T> *>(&other) && dynamic_cast<const AndCondition *>(&parent);
142 RangeCondition<T> *RangeCondition<T>::merge(const std::vector<Condition *> &conditions, const CompoundCondition &parent) const
144 if(dynamic_cast<const AndCondition *>(&parent) && !conditions.empty())
146 RangeCondition<T> *result = new RangeCondition<T>(Traits::get_min(), Traits::get_max());
147 for(std::vector<Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
149 const RangeCondition<T> *c = static_cast<RangeCondition<T> *>(*i);
150 result->min = std::max(result->min, c->min);
151 result->max = std::min(result->max, c->max);
160 void RangeCondition<T>::add_lines(std::list<FilterStatement> &st) const
162 const char *keyword = Traits::get_keyword();
164 FilterStatement::add_line(st, Msp::format("%s %s", keyword, min));
167 if(min!=Traits::get_min())
168 FilterStatement::add_line(st, Msp::format("%s >= %s", keyword, min));
169 if(max!=Traits::get_max())
170 FilterStatement::add_line(st, Msp::format("%s <= %s", keyword, max));