diff --git a/libwccl/ops/affix.cpp b/libwccl/ops/affix.cpp index 59562af17c1d5f4c1977d70d8f23b089770283f4..934787d8a1051003089451dde0c23f6c1718f10f 100644 --- a/libwccl/ops/affix.cpp +++ b/libwccl/ops/affix.cpp @@ -25,7 +25,7 @@ Affix::BaseRetValPtr Affix::apply_internal(const FunExecContext& context) const if(affix_length_ == 0) { return strset_expr_->apply(context); } - const boost::shared_ptr<StrSet>& set = strset_expr_->apply(context); + const boost::shared_ptr<const StrSet>& set = strset_expr_->apply(context); boost::shared_ptr<StrSet> a_set = boost::shared_ptr<StrSet>(new StrSet()); if(affix_length_ < 0) { foreach(const UnicodeString& s, set->contents()) { diff --git a/libwccl/ops/constant.h b/libwccl/ops/constant.h index c5c933f0d229a7150daa74dc53770be61861028e..c9bb5d83cb74dde62d8de1ebde72ec153cc48384 100644 --- a/libwccl/ops/constant.h +++ b/libwccl/ops/constant.h @@ -1,7 +1,6 @@ #ifndef LIBWCCL_OPS_CONSTANT_H #define LIBWCCL_OPS_CONSTANT_H -#include <boost/scoped_ptr.hpp> #include <boost/concept_check.hpp> #include <libwccl/ops/functions.h> @@ -45,12 +44,12 @@ protected : /** * Applying Constant function returns the held value of a constant */ - virtual BaseRetValPtr apply_internal(const FunExecContext&) const { - return BaseRetValPtr (new T(*value_)); + BaseRetValPtr apply_internal(const FunExecContext&) const { + return value_; } private: - const boost::scoped_ptr<const T> value_; + const boost::shared_ptr<const T> value_; }; diff --git a/libwccl/ops/functions.h b/libwccl/ops/functions.h index 34acfe01ce2757d61c23b2356e9cefcd93f14531..bda875158b4cbadd0e65ac282d3a27178077c2a5 100644 --- a/libwccl/ops/functions.h +++ b/libwccl/ops/functions.h @@ -17,9 +17,9 @@ namespace Wccl { */ class FunctionBase : public Operator { protected: - typedef boost::shared_ptr<Value> BaseRetValPtr; + typedef boost::shared_ptr<const Value> BaseRetValPtr; /** - * Applies the function, given the sentence context. + * Applies the function for the given execution context. */ virtual BaseRetValPtr apply_internal(const FunExecContext& context) const = 0; }; @@ -37,7 +37,7 @@ public: * Type returned after application of function (shared pointer to * a variable of the specified return type) */ - typedef boost::shared_ptr<T> RetValPtr; + typedef boost::shared_ptr<const T> RetValPtr; /** * Applies the function, given the sentence context, returning specific @@ -45,7 +45,7 @@ public: * be specified in derived classes. */ RetValPtr apply(const FunExecContext& context) const { - RetValPtr v = boost::dynamic_pointer_cast<T>(apply_internal(context)); + RetValPtr v = boost::dynamic_pointer_cast<const T>(apply_internal(context)); BOOST_ASSERT(v); return v; } diff --git a/libwccl/ops/regex.cpp b/libwccl/ops/regex.cpp index 0c4dca7319b83672f79da0464cbbed1efba77ee1..4759ea94f84c2b1d7db2edbc979e75caf5b2b352 100644 --- a/libwccl/ops/regex.cpp +++ b/libwccl/ops/regex.cpp @@ -73,7 +73,7 @@ std::string Regex::to_raw_string() const { } Regex::BaseRetValPtr Regex::apply_internal(const FunExecContext& context) const { - const boost::shared_ptr<StrSet>& set = strset_expr_->apply(context); + const boost::shared_ptr<const StrSet>& set = strset_expr_->apply(context); if(set->empty()) { return Predicate::False->apply(context); } diff --git a/libwccl/ops/tolower.cpp b/libwccl/ops/tolower.cpp index 52ad8c39aa2fbf912287a57be29b568d4af32846..f88ce8ac44b34def233bf41d83a9ba2be965176a 100644 --- a/libwccl/ops/tolower.cpp +++ b/libwccl/ops/tolower.cpp @@ -12,8 +12,8 @@ std::string ToLower::to_raw_string() const { return UnaryFunctionFormatter::to_raw_string(*this, *strset_expr_); } -ToLower::BaseRetValPtr ToLower::apply_internal(const FunExecContext& context) const { - const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context); +ToLower::BaseRetValPtr ToLower::apply_internal(const FunExecContext& context) const { + const boost::shared_ptr<const StrSet >& set = strset_expr_->apply(context); boost::shared_ptr<StrSet > l_set = boost::make_shared<StrSet>(); //TODO: should tolower be a method of StrSet as well? foreach(const UnicodeString& s, set->contents()) { diff --git a/libwccl/ops/toupper.cpp b/libwccl/ops/toupper.cpp index ec55211cb0aa4f253f352d3ed9393d5115771dd1..edbc3c75086732094a67ac3fcc2100ef0e70f37d 100644 --- a/libwccl/ops/toupper.cpp +++ b/libwccl/ops/toupper.cpp @@ -13,7 +13,7 @@ std::string ToUpper::to_raw_string() const { } ToUpper::BaseRetValPtr ToUpper::apply_internal(const FunExecContext& context) const { - const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context); + const boost::shared_ptr<const StrSet >& set = strset_expr_->apply(context); boost::shared_ptr<StrSet > u_set = boost::make_shared<StrSet>(); //TODO: should tolower be a method of StrSet as well? foreach(const UnicodeString& s, set->contents()) { diff --git a/tests/constant_tests.cpp b/tests/constant_tests.cpp index b4754c7a8f3749bf109dac8bb08b84299ccfb23e..08e1f0247997e806fec33a065b5ce675eaf62de0 100644 --- a/tests/constant_tests.cpp +++ b/tests/constant_tests.cpp @@ -58,14 +58,4 @@ BOOST_FIXTURE_TEST_CASE(bool_to_raw_string, BoolFix) BOOST_CHECK_EQUAL(false_value.to_raw_string(), false_constant.to_raw_string()); } -BOOST_FIXTURE_TEST_CASE(bool_value_preserved, BoolFix) -{ - boost::shared_ptr<Bool> v = true_constant.apply(cx); - v->set_value(false); - BOOST_CHECK_EQUAL(true, true_constant.apply(cx)->get_value()); - v = false_constant.apply(cx); - v->set_value(true); - BOOST_CHECK_EQUAL(false, false_constant.apply(cx)->get_value()); -} - BOOST_AUTO_TEST_SUITE_END()