+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);
+ Condition *result = cond1->merge(parts, *this);
+ if(del)
+ {
+ delete cond1;
+ delete cond2;
+ }
+ return result;
+}
+
+Condition *CompoundCondition::add_merged_to(Condition *cond, CompoundCondition *target, bool del) const
+{
+ for(vector<Condition *>::iterator i=target->conditions.begin(); i!=target->conditions.end(); ++i)
+ if((*i)->can_merge(*cond, *target))
+ {
+ Condition *m = merge_two(cond, *i, false);
+ delete *i;
+ if(del)
+ delete cond;
+ *i = m;
+ return target;
+ }
+
+ target->add(del ? cond : cond->clone());
+ return target;
+}
+
+Condition *CompoundCondition::merge_contents_to(CompoundCondition *cond, CompoundCondition *target) const
+{
+ for(vector<Condition *>::iterator i=cond->conditions.begin(); i!=cond->conditions.end(); ++i)
+ add_merged_to(*i, target, false);
+
+ delete cond;
+ return target;
+}
+