re-use evaluator object

This commit is contained in:
artemp 2013-11-29 13:51:50 +00:00
parent a1c2bd0d86
commit 06592cedc3

View file

@ -38,6 +38,7 @@
namespace mapnik namespace mapnik
{ {
template <typename T0, typename T1> template <typename T0, typename T1>
struct evaluate : boost::static_visitor<T1> struct evaluate : boost::static_visitor<T1>
{ {
@ -79,7 +80,7 @@ struct evaluate : boost::static_visitor<T1>
value_type operator() (global_attribute const& attr) const value_type operator() (global_attribute const& attr) const
{ {
return value_type();// shouldn't get here ? //attr.value<value_type,feature_type>(feature_); return value_type();// shouldn't get here
} }
value_type operator() (geometry_type_attribute const& geom) const value_type operator() (geometry_type_attribute const& geom) const
@ -89,22 +90,22 @@ struct evaluate : boost::static_visitor<T1>
value_type operator() (binary_node<tags::logical_and> const & x) const value_type operator() (binary_node<tags::logical_and> const & x) const
{ {
return (boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.left).to_bool()) return (boost::apply_visitor(*this, x.left).to_bool())
&& (boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.right).to_bool()); && (boost::apply_visitor(*this, x.right).to_bool());
} }
value_type operator() (binary_node<tags::logical_or> const & x) const value_type operator() (binary_node<tags::logical_or> const & x) const
{ {
return (boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.left).to_bool()) return (boost::apply_visitor(*this,x.left).to_bool())
|| (boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.right).to_bool()); || (boost::apply_visitor(*this,x.right).to_bool());
} }
template <typename Tag> template <typename Tag>
value_type operator() (binary_node<Tag> const& x) const value_type operator() (binary_node<Tag> const& x) const
{ {
typename make_op<Tag>::type operation; typename make_op<Tag>::type operation;
return operation(boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.left), return operation(boost::apply_visitor(*this, x.left),
boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.right)); boost::apply_visitor(*this, x.right));
} }
template <typename Tag> template <typename Tag>
@ -116,12 +117,12 @@ struct evaluate : boost::static_visitor<T1>
value_type operator() (unary_node<tags::logical_not> const& x) const value_type operator() (unary_node<tags::logical_not> const& x) const
{ {
return ! (boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.expr).to_bool()); return ! (boost::apply_visitor(*this,x.expr).to_bool());
} }
value_type operator() (regex_match_node const& x) const value_type operator() (regex_match_node const& x) const
{ {
value_type v = boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.expr); value_type v = boost::apply_visitor(*this, x.expr);
#if defined(BOOST_REGEX_HAS_ICU) #if defined(BOOST_REGEX_HAS_ICU)
return boost::u32regex_match(v.to_unicode(),x.pattern); return boost::u32regex_match(v.to_unicode(),x.pattern);
#else #else
@ -132,7 +133,7 @@ struct evaluate : boost::static_visitor<T1>
value_type operator() (regex_replace_node const& x) const value_type operator() (regex_replace_node const& x) const
{ {
value_type v = boost::apply_visitor(evaluate<feature_type,value_type>(feature_),x.expr); value_type v = boost::apply_visitor(*this, x.expr);
#if defined(BOOST_REGEX_HAS_ICU) #if defined(BOOST_REGEX_HAS_ICU)
return boost::u32regex_replace(v.to_unicode(),x.pattern,x.format); return boost::u32regex_replace(v.to_unicode(),x.pattern,x.format);
#else #else