diff --git a/libwccl/ops/and.cpp b/libwccl/ops/and.cpp index 0e119a7c9192b2b510a913a25f7ab0dc19c9b1f6..7cf39ec821457440d75c2771b39dd648b6a7d945 100644 --- a/libwccl/ops/and.cpp +++ b/libwccl/ops/and.cpp @@ -9,10 +9,10 @@ And::BaseRetValPtr And::apply_internal(const FunExecContext& context) const { foreach(boost::shared_ptr< Function<Bool> > expression, *expressions_) { if(!(expression->apply(context)->get_value())) { - return Predicate::False->apply(context); + return Predicate::False(context); } } - return Predicate::True->apply(context); + return Predicate::True(context); } const std::string And::raw_operator_name() const { diff --git a/libwccl/ops/equals.h b/libwccl/ops/equals.h index 0b1b6d48d106f89824237d0aace0709cb7b0bc88..c646208d18648d943739ae7ea5c8e99a61dc83eb 100644 --- a/libwccl/ops/equals.h +++ b/libwccl/ops/equals.h @@ -47,9 +47,9 @@ protected: boost::shared_ptr<T> arg1 = this->arg1_expr_->apply(context); boost::shared_ptr<T> arg2 = this->arg2_expr_->apply(context); if(arg1->equals(*arg2)) { - return Predicate::True->apply(context); + return Predicate::True(context); } - return Predicate::False->apply(context); + return Predicate::False(context); } }; @@ -94,17 +94,17 @@ protected: boost::shared_ptr<Position> arg1 = this->arg1_expr_->apply(context); boost::shared_ptr<Position> arg2 = this->arg2_expr_->apply(context); if(arg1->equals(*arg2)) { - return Predicate::True->apply(context); + return Predicate::True(context); } else { //in the given context both positions can still point nowhere //even if they have different underlying value int abs_pos1 = context.get_abs_position(*arg1); int abs_pos2 = context.get_abs_position(*arg2); if(!context.is_inside(abs_pos1) && !context.is_inside(abs_pos2)) { - return Predicate::True->apply(context); + return Predicate::True(context); } } - return Predicate::False->apply(context); + return Predicate::False(context); } }; diff --git a/libwccl/ops/intersects.h b/libwccl/ops/intersects.h index 9a3a160e6f78ae69a24151b71ac4421f64eba839..ad4716d26dfdac548aa50f18291134c56badec28 100644 --- a/libwccl/ops/intersects.h +++ b/libwccl/ops/intersects.h @@ -30,9 +30,9 @@ protected: 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->apply(context); + return Predicate::True(context); } - return Predicate::False->apply(context); + return Predicate::False(context); } }; diff --git a/libwccl/ops/issubsetof.h b/libwccl/ops/issubsetof.h index 685e8332a6ee2c5642dead2b9b08b5d98409bb5a..a16622c1bf5373103c9333ca90fda90cb29db0a9 100644 --- a/libwccl/ops/issubsetof.h +++ b/libwccl/ops/issubsetof.h @@ -35,10 +35,10 @@ protected: 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->apply(context); + return Predicate::True(context); } } - return Predicate::False->apply(context); + return Predicate::False(context); } }; diff --git a/libwccl/ops/nor.cpp b/libwccl/ops/nor.cpp index 4798819f4c94b09201c0f40de504b598181e1baf..50a8a4c82c4c04dd6d85fc13185ab8aa01cf7943 100644 --- a/libwccl/ops/nor.cpp +++ b/libwccl/ops/nor.cpp @@ -8,10 +8,10 @@ Nor::BaseRetValPtr Nor::apply_internal(const FunExecContext& context) const { foreach(BoolFunctionPtr expression, *expressions_) { if(expression->apply(context)->get_value()) { - return Predicate::False->apply(context); + return Predicate::False(context); } } - return Predicate::True->apply(context); + return Predicate::True(context); } const std::string Nor::raw_operator_name() const { diff --git a/libwccl/ops/or.cpp b/libwccl/ops/or.cpp index bdce8c62131ed1ecbb7dff9d64cec0b60a09f05d..af3d03e22e1679d9875540d171496f5ead2da836 100644 --- a/libwccl/ops/or.cpp +++ b/libwccl/ops/or.cpp @@ -8,10 +8,10 @@ Or::BaseRetValPtr Or::apply_internal(const FunExecContext& context) const { foreach(BoolFunctionPtr expression, *expressions_) { if(expression->apply(context)->get_value()) { - return Predicate::True->apply(context); + return Predicate::True(context); } } - return Predicate::False->apply(context); + return Predicate::False(context); } const std::string Or::raw_operator_name() const { diff --git a/libwccl/ops/predicate.cpp b/libwccl/ops/predicate.cpp index 66b0fb2452c85964208da2546cd1862a8369b6e3..57d5ee18049bbb8fb98b8b4ddd76877e49ff4727 100644 --- a/libwccl/ops/predicate.cpp +++ b/libwccl/ops/predicate.cpp @@ -2,8 +2,16 @@ namespace Wccl { -const boost::scoped_ptr< Constant<Bool> > Predicate::True(new Constant<Bool>(Bool(true))); +Predicate::RetValPtr Predicate::True(const FunExecContext& context) +{ + static Constant<Bool> true_constant(Bool(true)); + return true_constant.apply(context); +} -const boost::scoped_ptr< Constant<Bool> > Predicate::False(new Constant<Bool>(Bool(false))); +Predicate::RetValPtr Predicate::False(const FunExecContext& context) +{ + static Constant<Bool> false_constant(Bool(false)); + return false_constant.apply(context); +} } /* end ns Wccl */ diff --git a/libwccl/ops/predicate.h b/libwccl/ops/predicate.h index f064bee6d765f0dc5ce1f5cb6a5626af3a97a239..e6176ffb35ee8a95bdf8d0795921a342f7f5235d 100644 --- a/libwccl/ops/predicate.h +++ b/libwccl/ops/predicate.h @@ -14,13 +14,13 @@ namespace Wccl { class Predicate : public Function<Bool> { public: /** - * Constant<Bool> holding true value, to use by predicates when returning value + * Helper function returing True, to use by predicates when returning value */ - static const boost::scoped_ptr< Constant<Bool> > True; + static RetValPtr True(const FunExecContext& context); /** - * Constant<Bool> holding false value, to use by predicates when returning value + * Helper function returing False, to use by predicates when returning value */ - static const boost::scoped_ptr< Constant<Bool> > False; + static RetValPtr False(const FunExecContext& context); }; } /* end ns Wccl */ diff --git a/libwccl/ops/regex.cpp b/libwccl/ops/regex.cpp index 4759ea94f84c2b1d7db2edbc979e75caf5b2b352..c059324c40964ca801cb849aab2f54bdeac6d456 100644 --- a/libwccl/ops/regex.cpp +++ b/libwccl/ops/regex.cpp @@ -75,25 +75,25 @@ std::string Regex::to_raw_string() const { Regex::BaseRetValPtr Regex::apply_internal(const FunExecContext& context) const { const boost::shared_ptr<const StrSet>& set = strset_expr_->apply(context); if(set->empty()) { - return Predicate::False->apply(context); + return Predicate::False(context); } foreach(const UnicodeString& s, set->contents()) { UErrorCode status = U_ZERO_ERROR; boost::scoped_ptr<RegexMatcher> matcher(pattern_->matcher(s, status)); if(status != U_ZERO_ERROR) { BOOST_ASSERT(status == U_ZERO_ERROR); - return Predicate::False->apply(context); + return Predicate::False(context); } bool matched = matcher->matches(status); if(status != U_ZERO_ERROR) { BOOST_ASSERT(status == U_ZERO_ERROR); - return Predicate::False->apply(context); + return Predicate::False(context); } if(!matched) { - return Predicate::False->apply(context); + return Predicate::False(context); } } - return Predicate::True->apply(context); + return Predicate::True(context); } } /* end ns Wccl */ diff --git a/tests/logicalpredicates.cpp b/tests/logicalpredicates.cpp index 0de82f5923f552cdd608f71b25edfc3b1a653a03..b400bc894117a2cea5635966c510c1afc991fbde 100644 --- a/tests/logicalpredicates.cpp +++ b/tests/logicalpredicates.cpp @@ -40,8 +40,8 @@ struct PredFix BOOST_FIXTURE_TEST_CASE(predicate_constants, PredFix) { - BOOST_CHECK_EQUAL(true, Predicate::True->apply(cx)->get_value()); - BOOST_CHECK_EQUAL(false, Predicate::False->apply(cx)->get_value()); + BOOST_CHECK_EQUAL(true, Predicate::True(cx)->get_value()); + BOOST_CHECK_EQUAL(false, Predicate::False(cx)->get_value()); } BOOST_FIXTURE_TEST_CASE(and_1arg, PredFix)