Compare commits

...

3 commits

Author SHA1 Message Date
Dane Springmeyer
ba9fd556e0 expicit constructors for geometry_empty 2016-07-25 17:26:49 +02:00
Dane Springmeyer
28370753ba add static_visitor 2016-07-25 17:26:13 +02:00
Dane Springmeyer
4cab287ade build against boost::variant 2016-07-25 14:54:43 +02:00
33 changed files with 117 additions and 46 deletions

View file

@ -51,7 +51,7 @@
namespace mapnik {
template <typename Container>
struct expression_attributes
struct expression_attributes : public util::static_visitor<void>
{
explicit expression_attributes(Container& names)
: names_(names) {}

View file

@ -39,7 +39,7 @@ namespace mapnik {
namespace {
template <typename T, typename Attributes>
struct evaluate_expression
struct evaluate_expression : public util::static_visitor<T>
{
using value_type = T;
@ -133,7 +133,7 @@ struct evaluate_expression
};
template <typename T>
struct evaluate_expression<T, boost::none_t>
struct evaluate_expression<T, boost::none_t> : public util::static_visitor<T>
{
using value_type = T;

View file

@ -35,7 +35,7 @@ namespace mapnik
{
template <typename T0, typename T1, typename T2>
struct evaluate
struct evaluate : public util::static_visitor<T1>
{
using feature_type = T0;
using value_type = T1;

View file

@ -145,14 +145,14 @@ template <typename T>
struct geometry : geometry_base<T>
{
using coord_type = T;
// FIXMED
geometry(geometry_empty const&)
: geometry_base<T>() {} // empty
geometry()
: geometry_base<T>() {} // empty
template <typename G>
geometry(G && geom)
: geometry_base<T>(std::forward<G>(geom)) {}
};
template <typename T>

View file

@ -34,7 +34,7 @@ namespace mapnik { namespace geometry {
namespace detail {
template <typename T>
struct geometry_centroid
struct geometry_centroid : public util::static_visitor<bool>
{
using result_type = bool;

View file

@ -38,7 +38,7 @@ namespace mapnik { namespace geometry {
namespace detail {
struct geometry_correct
struct geometry_correct : public util::static_visitor<void>
{
using result_type = void;

View file

@ -29,7 +29,7 @@ namespace mapnik { namespace geometry {
namespace detail {
template <typename T>
struct geometry_envelope
struct geometry_envelope : public util::static_visitor<void>
{
using coord_type = T;
using bbox_type = box2d<coord_type>;

View file

@ -29,7 +29,7 @@ namespace mapnik { namespace geometry {
namespace detail {
struct geometry_is_empty
struct geometry_is_empty : public util::static_visitor<bool>
{
bool operator() (mapnik::geometry::geometry<double> const& geom) const
{

View file

@ -36,7 +36,7 @@ namespace mapnik { namespace geometry {
namespace detail {
struct geometry_is_simple
struct geometry_is_simple : public util::static_visitor<bool>
{
using result_type = bool;

View file

@ -37,7 +37,7 @@ namespace mapnik { namespace geometry {
namespace detail {
struct geometry_is_valid
struct geometry_is_valid : public util::static_visitor<bool>
{
using result_type = bool;

View file

@ -171,7 +171,7 @@ geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj
}
template <typename T>
struct geom_reproj_copy_visitor
struct geom_reproj_copy_visitor : public util::static_visitor<geometry<T>>
{
geom_reproj_copy_visitor(proj_transform const & proj_trans, unsigned int & n_err)
@ -278,7 +278,8 @@ T reproject_copy(T const& geom, projection const& source, projection const& dest
namespace detail {
struct geom_reproj_visitor {
struct geom_reproj_visitor : public util::static_visitor<bool>
{
geom_reproj_visitor(proj_transform const & proj_trans)
: proj_trans_(proj_trans) {}

View file

@ -29,7 +29,7 @@
namespace mapnik { namespace geometry { namespace detail {
//template <typename Transformer>
struct geometry_to_path
struct geometry_to_path : public util::static_visitor<void>
{
geometry_to_path(path_type & p)
: p_(p) {}

View file

@ -96,7 +96,7 @@ inline multi_polygon<V> transform_geometry(multi_polygon<T> const& geom, Transfo
}
template <typename Transformer, typename V>
struct geometry_transform
struct geometry_transform : public util::static_visitor<geometry<V>>
{
geometry_transform(Transformer const& transformer)
: transformer_(transformer) {}

View file

@ -29,7 +29,7 @@
namespace mapnik { namespace geometry { namespace detail {
struct geometry_type
struct geometry_type : public util::static_visitor<mapnik::geometry::geometry_types>
{
template <typename T>
mapnik::geometry::geometry_types operator () (T const& geom) const

View file

@ -42,7 +42,7 @@ inline bool pip(double x0,
return ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1));
}
struct hit_test_visitor
struct hit_test_visitor : public util::static_visitor<bool>
{
hit_test_visitor(double x, double y, double tol)
: x_(x),

View file

@ -914,7 +914,7 @@ void apply_filter(Src & src, invert const& /*op*/)
}
template <typename Src>
struct filter_visitor
struct filter_visitor : public util::static_visitor<void>
{
filter_visitor(Src & src)
: src_(src) {}
@ -928,7 +928,7 @@ struct filter_visitor
Src & src_;
};
struct filter_radius_visitor
struct filter_radius_visitor : public util::static_visitor<void>
{
int & radius_;
filter_radius_visitor(int & radius)

View file

@ -302,7 +302,7 @@ inline std::ostream& operator<< (std::ostream& os, colorize_alpha const& filter)
template <typename Out>
struct to_string_visitor
struct to_string_visitor : public util::static_visitor<void>
{
to_string_visitor(Out & out)
: out_(out) {}

View file

@ -31,7 +31,7 @@
namespace mapnik { namespace json {
struct attribute_value_visitor
struct attribute_value_visitor : public util::static_visitor<mapnik::value>
{
public:
attribute_value_visitor(mapnik::transcoder const& tr)

View file

@ -175,7 +175,7 @@ boost::optional<T> param_cast(value_bool const& source)
} // end namespace detail
template <typename T>
struct value_extractor_visitor
struct value_extractor_visitor : public util::static_visitor<void>
{
value_extractor_visitor(boost::optional<T> & var)

View file

@ -98,7 +98,7 @@ enum class property_types : std::uint8_t
};
template <typename T>
struct evaluate_path_wrapper
struct evaluate_path_wrapper : public util::static_visitor<T>
{
using result_type = T;
template <typename T1, typename T2>
@ -110,7 +110,7 @@ struct evaluate_path_wrapper
};
template <>
struct evaluate_path_wrapper<std::string>
struct evaluate_path_wrapper<std::string> : public util::static_visitor<std::string>
{
template <typename T1, typename T2>
std::string operator() (T1 const& expr, T2 const& feature) const
@ -339,7 +339,7 @@ struct evaluate_expression_wrapper<mapnik::font_feature_settings>
};
template <typename T>
struct extract_value
struct extract_value : public util::static_visitor<T>
{
using result_type = T;

View file

@ -33,7 +33,7 @@
namespace mapnik {
struct property_value_hash_visitor
struct property_value_hash_visitor : public util::static_visitor<std::size_t>
{
std::size_t operator() (color const& val) const
{

View file

@ -129,7 +129,7 @@ struct symbolizer_traits<dot_symbolizer>
// symbolizer name impl
namespace detail {
struct symbolizer_name_impl
struct symbolizer_name_impl : public util::static_visitor<std::string>
{
public:
template <typename Symbolizer>

View file

@ -191,7 +191,7 @@ inline void clear(transform_node& val)
namespace {
struct is_null_transform_node
struct is_null_transform_node : public util::static_visitor<bool>
{
bool operator() (value const& val) const
{

View file

@ -52,7 +52,7 @@ struct transform_processor
using transform_type = agg::trans_affine;
template <typename Container>
struct attribute_collector
struct attribute_collector : public util::static_visitor<void>
{
expression_attributes<Container> collect_;
@ -103,7 +103,7 @@ struct transform_processor
}
};
struct node_evaluator
struct node_evaluator : public util::static_visitor<void>
{
node_evaluator(transform_type& tr,
feature_type const& feat,

View file

@ -40,7 +40,7 @@ namespace mapnik { namespace util {
namespace detail {
struct datasource_geometry_type
struct datasource_geometry_type: public util::static_visitor<mapnik::datasource_geometry_t>
{
mapnik::datasource_geometry_t operator () (mapnik::geometry::geometry_empty const&) const
{

View file

@ -225,9 +225,8 @@ wkb_buffer_ptr multi_point_wkb( geometry::multi_point<double> const& multi_pt, w
template <typename MultiGeometry>
wkb_buffer_ptr multi_geom_wkb(MultiGeometry const& multi_geom, wkbByteOrder byte_order);
struct geometry_to_wkb
struct geometry_to_wkb: public util::static_visitor<wkb_buffer_ptr>
{
using result_type = wkb_buffer_ptr;
geometry_to_wkb(wkbByteOrder byte_order)

View file

@ -24,7 +24,15 @@
#define MAPNIK_UTIL_VARIANT_HPP
#include <mapnik/config.hpp>
#define USE_BOOST
#ifdef USE_BOOST
#include <boost/variant.hpp>
#define VARIANT_INLINE inline
#else
#include <mapbox/variant.hpp>
#endif
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
@ -33,9 +41,67 @@
namespace mapnik { namespace util {
#ifdef USE_BOOST
template <typename T>
using recursive_wrapper = typename boost::recursive_wrapper<T>;
template<typename... Types>
using variant = boost::variant<Types...>;
template <typename T>
using static_visitor = boost::static_visitor<T>;
// unary visitor interface
// const
template <typename F, typename V>
auto VARIANT_INLINE static apply_visitor(F && f, V const& v) -> decltype(boost::apply_visitor(std::forward<F>(f),v))
{
return boost::apply_visitor(std::forward<F>(f),v);
}
// non-const
template <typename F, typename V>
auto VARIANT_INLINE static apply_visitor(F && f, V & v) -> decltype(boost::apply_visitor(std::forward<F>(f),v))
{
return boost::apply_visitor(std::forward<F>(f),v);
}
// binary visitor interface
// const
template <typename F, typename V>
auto VARIANT_INLINE static apply_visitor(F && f, V const& v0, V const& v1) -> decltype(boost::apply_visitor(std::forward<F>(f), v0, v1))
{
return boost::apply_visitor(std::forward<F>(f), v0, v1);
}
// non-const
template <typename F, typename V>
auto VARIANT_INLINE static apply_visitor(F && f, V & v0, V & v1) -> decltype(boost::apply_visitor(std::forward<F>(f), v0, v1))
{
return boost::apply_visitor(std::forward<F>(f), v0, v1);
}
// getter interface
template <typename ResultType, typename T>
auto get(T & var)->decltype(boost::get<ResultType>(var))
{
return boost::get<ResultType>(var);
}
template <typename ResultType, typename T>
auto get(T const& var)->decltype(boost::get<ResultType>(var))
{
return boost::get<ResultType>(var);
}
#else
template <typename T>
using recursive_wrapper = typename mapbox::util::recursive_wrapper<T>;
template <typename T>
using static_visitor = mapbox::util::static_visitor<T>;
template<typename... Types>
class variant : public mapbox::util::variant<Types...>
@ -79,17 +145,22 @@ auto VARIANT_INLINE static apply_visitor(F && f, V & v0, V & v1) -> decltype(V::
// getter interface
template <typename ResultType, typename T>
ResultType & get(T & var)
auto get(T& var)->decltype(var.template get<ResultType>())
{
return var.template get<ResultType>();
}
template <typename ResultType, typename T>
ResultType const& get(T const& var)
auto get(T const& var)->decltype(var.template get<ResultType>())
{
return var.template get<ResultType>();
}
#endif
}}
#endif // MAPNIK_UTIL_VARIANT_HPP

View file

@ -123,7 +123,7 @@ inline std::size_t hash_value(value const& val)
using value = value_adl_barrier::value;
namespace detail {
struct is_null_visitor
struct is_null_visitor: public util::static_visitor<bool>
{
bool operator()(value const& val) const
{

View file

@ -42,7 +42,7 @@ inline void hash_combine(std::size_t & seed, std::size_t val)
seed ^= val + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
struct value_hasher
struct value_hasher: public util::static_visitor<std::size_t>
{
std::size_t operator() (value_null val) const
{

View file

@ -28,7 +28,7 @@
namespace mapnik { namespace geometry {
template <typename T>
struct vertex_processor
struct vertex_processor : public util::static_visitor<void>
{
using processor_type = T;
vertex_processor(processor_type& proc)

View file

@ -177,7 +177,7 @@ MAPNIK_DECL void composite(image_gray32f & dst, image_gray32f const& src, compos
namespace detail {
struct composite_visitor
struct composite_visitor : public util::static_visitor<void>
{
composite_visitor(image_any const& src,
composite_mode_e mode,

View file

@ -33,7 +33,7 @@ namespace detail
{
template <typename T0>
struct visitor_image_copy
struct visitor_image_copy : public util::static_visitor<T0>
{
using dst_type = typename T0::pixel_type;
@ -63,7 +63,7 @@ struct visitor_image_copy
};
template <typename T0>
struct visitor_image_copy_so
struct visitor_image_copy_so : public util::static_visitor<T0>
{
using dst_type = typename T0::pixel_type;

View file

@ -166,7 +166,7 @@ MAPNIK_DECL void warp_image (T & target, T const& source, proj_transform const&
namespace detail {
struct warp_image_visitor
struct warp_image_visitor : public util::static_visitor<void>
{
warp_image_visitor (raster & target_raster, proj_transform const& prj_trans, box2d<double> const& source_ext,
double offset_x, double offset_y, unsigned mesh_size,