diff --git a/include/mapnik/value.hpp b/include/mapnik/value.hpp index 13c997f5b..615f63ff7 100644 --- a/include/mapnik/value.hpp +++ b/include/mapnik/value.hpp @@ -31,12 +31,10 @@ // boost #include #include - // stl #include #include #include -#include // icu #include #include @@ -66,7 +64,7 @@ inline void to_utf8(mapnik::value_unicode_string const& input, std::string & tar } } -using value_base = util::variant; +using value_base = util::variant; namespace impl { @@ -814,6 +812,88 @@ struct to_expression_string : public util::static_visitor namespace value_adl_barrier { +namespace detail { + +template +struct is_value_bool +{ + bool value = std::is_same::value; +}; + +template +struct is_value_integer +{ + bool value = std::is_integral::value && !std::is_same::value; +}; + +template +struct is_value_double +{ + bool value = std::is_floating_point::value; +}; + +template +struct is_value_unicode_string +{ + bool value = std::is_same::value; +}; + +template +struct is_value_string +{ + bool value = std::is_same::value; +}; + +template +struct is_value_null +{ + bool value = std::is_same::value; +}; + +} // namespace detail + + +template +struct mapnik_value_type +{ + using type = T; +}; + +// value_null +template +struct mapnik_value_type::value>::type> +{ + using type = mapnik::value_null; +}; + +// value_bool +template +struct mapnik_value_type::value>::type> +{ + using type = mapnik::value_bool; +}; + +// value_integer +template +struct mapnik_value_type::value>::type> +{ + using type = mapnik::value_integer; +}; + +// value_double +template +struct mapnik_value_type::value>::type> +{ + using type = mapnik::value_double; +}; + +// value_unicode_string +template +struct mapnik_value_type::value>::type> +{ + using type = mapnik::value_unicode_string; +}; + class value { value_base base_; @@ -827,20 +907,9 @@ public: value () noexcept //-- comment out for VC++11 : base_(value_null()) {} - value(value_integer val) - : base_(val) {} - - value(value_double val) - : base_(val) {} - - value(value_bool val) - : base_(val) {} - - value(value_null val) - : base_(val) {} - - value(value_unicode_string const& val) - : base_(val) {} + template + value ( T const& val) + : base_(typename mapnik_value_type::type(val)) {} value (value const& other) : base_(other.base_) {} @@ -974,20 +1043,14 @@ operator << (std::basic_ostream& out, return out; } -inline std::size_t hash_value(value const& val) -{ - std::cerr << "hash_value" << std::endl; - return 123; // FIXME hash_value(val.base()); -} - } // namespace value_adl_barrier using value_adl_barrier::value; using value_adl_barrier::operator<<; -namespace impl { +namespace detail { -struct is_null : public util::static_visitor +struct is_null_visitor : public util::static_visitor { bool operator() (value const& val) const { @@ -1004,25 +1067,15 @@ struct is_null : public util::static_visitor bool operator() (T const& val) const { boost::ignore_unused_variable_warning(val); - std::cerr << "is_null" << std::endl; return false; } - - //template - //bool operator() (boost::variant const& val) const - //{ - // return util::apply_visitor(*this, val); - //} }; -} // namespace impl - -// constant visitor instance substitutes overloaded function -impl::is_null const is_null = impl::is_null(); +} // namespace detail inline bool value::is_null() const { - return util::apply_visitor(impl::is_null(), base_); + return util::apply_visitor(mapnik::detail::is_null_visitor(), base_); } } // namespace mapnik