diff --git a/libwccl/ops/intersects.h b/libwccl/ops/intersects.h index ad4716d26dfdac548aa50f18291134c56badec28..39ed2723a42b66a5e2dab9c744f42a11c9d9b8de 100644 --- a/libwccl/ops/intersects.h +++ b/libwccl/ops/intersects.h @@ -29,10 +29,7 @@ protected: virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { boost::shared_ptr<T> set1 = this->set1_expr_->apply(context); boost::shared_ptr<T> set2 = this->set2_expr_->apply(context); - if(set1->is_subset_of(*set2)) { - return Predicate::True(context); - } - return Predicate::False(context); + return Predicate::evaluate(set1->intersects(*set2), context); } }; diff --git a/libwccl/ops/isinside.h b/libwccl/ops/isinside.h index 1a3339df488524bdbda8b182464064c8ea7747d1..0acbb86e86e911ebbbbd914edf2383b1d69bf629 100644 --- a/libwccl/ops/isinside.h +++ b/libwccl/ops/isinside.h @@ -42,10 +42,7 @@ protected: */ virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context); - if(pos->is_inside(context.sentence_context())) { - return Predicate::True(context); - } - return Predicate::False(context); + return Predicate::evaluate(pos->is_inside(context.sentence_context()), context); } }; diff --git a/libwccl/ops/isoutside.h b/libwccl/ops/isoutside.h index cf744404fd59830976056e357a952c878c201a4c..f32591ddabeff1c4681fbcb11c762b2037e59c90 100644 --- a/libwccl/ops/isoutside.h +++ b/libwccl/ops/isoutside.h @@ -42,10 +42,7 @@ protected: */ virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context); - if(pos->is_outside(context.sentence_context())) { - return Predicate::True(context); - } - return Predicate::False(context); + return Predicate::evaluate(pos->is_outside(context.sentence_context()), context); } }; diff --git a/libwccl/ops/issubsetof.h b/libwccl/ops/issubsetof.h index a16622c1bf5373103c9333ca90fda90cb29db0a9..0fd276ffbd0248710a1e960145d6aeb63a0452bb 100644 --- a/libwccl/ops/issubsetof.h +++ b/libwccl/ops/issubsetof.h @@ -32,11 +32,10 @@ protected: */ virtual BaseRetValPtr apply_internal(const FunExecContext& context) const { boost::shared_ptr<T> possible_subset = this->set1_expr_->apply(context); - if(!possible_subset->empty()) { + if(!possible_subset->empty()) + { boost::shared_ptr<T> set_compared_to = this->set2_expr_->apply(context); - if(possible_subset->is_subset_of(*set_compared_to)) { - return Predicate::True(context); - } + return Predicate::evaluate(possible_subset->is_subset_of(*set_compared_to), context); } return Predicate::False(context); } diff --git a/libwccl/ops/predicate.cpp b/libwccl/ops/predicate.cpp index 57d5ee18049bbb8fb98b8b4ddd76877e49ff4727..e3d7b7f1be09dc2aba9f00b052de48683e1f6042 100644 --- a/libwccl/ops/predicate.cpp +++ b/libwccl/ops/predicate.cpp @@ -14,4 +14,9 @@ Predicate::RetValPtr Predicate::False(const FunExecContext& context) return false_constant.apply(context); } +Predicate::RetValPtr Predicate::evaluate(bool condition, const FunExecContext &context) +{ + return condition ? True(context) : False(context); +} + } /* end ns Wccl */ diff --git a/libwccl/ops/predicate.h b/libwccl/ops/predicate.h index e6176ffb35ee8a95bdf8d0795921a342f7f5235d..a569b4e990e0e7d3e27cba694c4d06660c1f235b 100644 --- a/libwccl/ops/predicate.h +++ b/libwccl/ops/predicate.h @@ -21,6 +21,10 @@ public: * Helper function returing False, to use by predicates when returning value */ static RetValPtr False(const FunExecContext& context); + /** + * Helper function returing True or False depending on condition + */ + static RetValPtr evaluate(bool condition, const FunExecContext& context); }; } /* end ns Wccl */