RangeCondition(Type, Type);
virtual RangeCondition<T> *clone() const;
+ virtual bool can_merge(const Condition &, const CompoundCondition &) const;
+ virtual RangeCondition<T> *merge(const std::vector<Condition *> &, const CompoundCondition &) const;
virtual void add_lines(std::list<FilterStatement> &) const;
};
return new RangeCondition<T>(min, max);
}
+template<typename T>
+bool RangeCondition<T>::can_merge(const Condition &other, const CompoundCondition &parent) const
+{
+ return dynamic_cast<const RangeCondition<T> *>(&other) && dynamic_cast<const AndCondition *>(&parent);
+}
+
+template<typename T>
+RangeCondition<T> *RangeCondition<T>::merge(const std::vector<Condition *> &conditions, const CompoundCondition &parent) const
+{
+ if(dynamic_cast<const AndCondition *>(&parent) && !conditions.empty())
+ {
+ RangeCondition<T> *result = new RangeCondition<T>(Traits::get_min(), Traits::get_max());
+ for(std::vector<Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
+ {
+ const RangeCondition<T> *c = static_cast<RangeCondition<T> *>(*i);
+ result->min = std::max(result->min, c->min);
+ result->max = std::min(result->max, c->max);
+ }
+ return result;
+ }
+ else
+ return 0;
+}
+
template<typename T>
void RangeCondition<T>::add_lines(std::list<FilterStatement> &st) const
{