virtual ChoiceCondition<T> *clone() const;
virtual bool can_merge(const Condition &, const CompoundCondition &) const;
- virtual ChoiceCondition<T> *merge(const std::vector<Condition *> &, const CompoundCondition &) const;
+ virtual ChoiceCondition<T> *merge(const std::vector<const Condition *> &, const CompoundCondition &) const;
virtual void add_lines(std::list<FilterStatement> &) const;
};
}
template<typename T>
-ChoiceCondition<T> *ChoiceCondition<T>::merge(const std::vector<Condition *> &conditions, const CompoundCondition &parent) const
+ChoiceCondition<T> *ChoiceCondition<T>::merge(const std::vector<const Condition *> &conditions, const CompoundCondition &parent) const
{
if(dynamic_cast<const OrCondition *>(&parent) && !conditions.empty())
{
ChoiceCondition<T> *result = new ChoiceCondition<T>(std::vector<Type>());
- for(std::vector<Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
+ for(std::vector<const Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
{
- const std::vector<Type> &v = static_cast<ChoiceCondition<T> *>(*i)->values;
+ const std::vector<Type> &v = static_cast<const ChoiceCondition<T> *>(*i)->values;
for(typename std::vector<Type>::const_iterator j=v.begin(); j!=v.end(); ++j)
if(Msp::find(result->values, *j)==result->values.end())
result->values.push_back(*j);
void CompoundCondition::add(Condition *cond)
{
+ if(!cond)
+ throw invalid_argument("CompoundCondition::add");
conditions.push_back(cond);
}
-const Condition *CompoundCondition::get(unsigned i) const
+const Condition &CompoundCondition::get(unsigned i) const
{
if(i>=conditions.size())
throw out_of_range("CompoundCondition::get");
- return conditions[i];
+ return *conditions[i];
}
Condition *CompoundCondition::flatten() const
merge = conditions.front()->can_merge(**i, *this);
if(merge)
- return conditions.front()->merge(conditions, *this);
+ {
+ vector<const Condition *> merge_conds(conditions.begin(), conditions.end());
+ return conditions.front()->merge(merge_conds, *this);
+ }
else
{
Condition *result = 0;
Condition *CompoundCondition::merge_two(Condition *cond1, Condition *cond2, bool del) const
{
- vector<Condition *> parts;
- parts.reserve(2);
- parts.push_back(cond1);
- parts.push_back(cond2);
+ vector<const Condition *> parts(2);
+ parts[0] = cond1;
+ parts[1] = cond2;
Condition *result = cond1->merge(parts, *this);
if(del)
OrCondition *result = new OrCondition;
unsigned count = cond1->count();
for(unsigned i=0; i<count; ++i)
- if(Condition *sub = dispatch_flatten(cond1->get(i)->clone(), (i+1<count ? cond2->clone() : cond2)))
+ if(Condition *sub = dispatch_flatten(cond1->get(i).clone(), (i+1<count ? cond2->clone() : cond2)))
result->add(sub);
delete cond1;
OrCondition *result = new OrCondition;
for(unsigned i=0; i<count1; ++i)
for(unsigned j=0; j<count2; ++j)
- if(Condition *sub = dispatch_flatten(cond1->get(i)->clone(), cond2->get(j)->clone()))
+ if(Condition *sub = dispatch_flatten(cond1->get(i).clone(), cond2->get(j).clone()))
result->add(sub);
delete cond1;
virtual Condition *clone() const = 0;
virtual Condition *flatten() const { return clone(); }
virtual bool can_merge(const Condition &, const CompoundCondition &) const { return false; }
- virtual Condition *merge(const std::vector<Condition *> &, const CompoundCondition &) const { return 0; }
+ virtual Condition *merge(const std::vector<const Condition *> &, const CompoundCondition &) const { return 0; }
virtual bool is_viable() const { return true; }
virtual void add_lines(std::list<FilterStatement> &) const = 0;
};
public:
void add(Condition *);
unsigned count() const { return conditions.size(); }
- const Condition *get(unsigned) const;
+ const Condition &get(unsigned) const;
virtual Condition *flatten() const;
protected:
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 RangeCondition<T> *merge(const std::vector<const Condition *> &, const CompoundCondition &) const;
virtual bool is_viable() const { return min<=max; }
virtual void add_lines(std::list<FilterStatement> &) const;
};
}
template<typename T>
-RangeCondition<T> *RangeCondition<T>::merge(const std::vector<Condition *> &conditions, const CompoundCondition &parent) const
+RangeCondition<T> *RangeCondition<T>::merge(const std::vector<const Condition *> &conditions, const CompoundCondition &parent) const
{
if(conditions.empty())
return 0;
result = new RangeCondition<T>(Traits::get_min(), Traits::get_max());
else
result = new RangeCondition<T>(Traits::get_max(), Traits::get_min());
- for(std::vector<Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
+ for(std::vector<const Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
{
- const RangeCondition<T> *c = static_cast<RangeCondition<T> *>(*i);
+ const RangeCondition<T> *c = static_cast<const RangeCondition<T> *>(*i);
if(intersect)
{
result->min = std::max(result->min, c->min);