From f21152a6a96563420da4ba82328f2639c4333252 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 11 Dec 2013 17:08:33 -0500 Subject: [PATCH] register target type for symbolizer properties --- include/mapnik/symbolizer.hpp | 26 +++++++- src/symbolizer_keys.cpp | 122 +++++++++++++++++----------------- 2 files changed, 86 insertions(+), 62 deletions(-) diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index 9bc8dba49..0a00b223a 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -100,6 +100,30 @@ struct MAPNIK_DECL symbolizer_base cont_type properties; }; +// symbolizer properties target types +enum class property_types : std::uint8_t +{ + target_bool = 1, + target_double, + target_integer, + target_color, + target_comp_op, + target_line_cap, + target_line_join, + target_line_rasterizer, + target_halo_rasterizer, + target_point_placement, + target_pattern_alignment, + target_debug_symbolizer_mode, + target_marker_placement, + target_marker_multi_policy, + target_string, + target_transform, + target_placement, + target_dash_array, + target_colorizer +}; + inline bool operator==(symbolizer_base const& lhs, symbolizer_base const& rhs) { return lhs.properties.size() == rhs.properties.size() && @@ -376,7 +400,7 @@ constexpr auto to_integral(Enum e) -> typename std::underlying_type::type return static_cast::type>(e); } -typedef std::tuple > property_meta_type; +typedef std::tuple, property_types> property_meta_type; property_meta_type const& get_meta(mapnik::keys key); mapnik::keys get_key(std::string const& name); diff --git a/src/symbolizer_keys.cpp b/src/symbolizer_keys.cpp index ec15d3efd..c7a41cd53 100644 --- a/src/symbolizer_keys.cpp +++ b/src/symbolizer_keys.cpp @@ -30,66 +30,66 @@ namespace mapnik { -// tuple -> name, default value, enumeration to string converter lambda -static const property_meta_type key_meta[static_cast(keys::MAX_SYMBOLIZER_KEY)] = +// tuple -> name, default value, enumeration to string converter lambda, target property type +static const property_meta_type key_meta[to_integral(keys::MAX_SYMBOLIZER_KEY)] = { - property_meta_type{ "gamma", 1.0, nullptr}, - property_meta_type{ "gamma-method", static_cast(GAMMA_POWER), nullptr}, - property_meta_type{ "opacity", 1.0, nullptr}, + property_meta_type{ "gamma", 1.0, nullptr, property_types::target_double}, + property_meta_type{ "gamma-method", static_cast(GAMMA_POWER), nullptr, property_types::target_integer}, + property_meta_type{ "opacity", 1.0, nullptr, property_types::target_double}, property_meta_type{ "alignment", enumeration_wrapper(LOCAL_ALIGNMENT), - [](enumeration_wrapper e) { return enumeration(pattern_alignment_enum(e.value)).as_string();}}, - property_meta_type{ "offset", 0.0, nullptr}, + [](enumeration_wrapper e) { return enumeration(pattern_alignment_enum(e.value)).as_string();}, property_types::target_pattern_alignment}, + property_meta_type{ "offset", 0.0, nullptr, property_types::target_double}, property_meta_type{ "comp-op", enumeration_wrapper(src_over), - [](enumeration_wrapper e) { return *comp_op_to_string(composite_mode_e(e.value)); }}, - property_meta_type{ "clip", false, nullptr}, - property_meta_type{ "fill", mapnik::color("gray"), nullptr}, - property_meta_type{ "fill-opacity", 1.0 , nullptr}, - property_meta_type{ "stroke", mapnik::color("black"), nullptr}, - property_meta_type{ "stroke-width", 1.0 , nullptr}, - property_meta_type{ "stroke-opacity", 1.0, nullptr}, + [](enumeration_wrapper e) { return *comp_op_to_string(composite_mode_e(e.value)); }, property_types::target_comp_op}, + property_meta_type{ "clip", false, nullptr, property_types::target_bool}, + property_meta_type{ "fill", mapnik::color("gray"), nullptr, property_types::target_color}, + property_meta_type{ "fill-opacity", 1.0 , nullptr, property_types::target_double}, + property_meta_type{ "stroke", mapnik::color("black"), nullptr, property_types::target_color}, + property_meta_type{ "stroke-width", 1.0 , nullptr, property_types::target_double}, + property_meta_type{ "stroke-opacity", 1.0, nullptr, property_types::target_double}, property_meta_type{ "stroke-linejoin", enumeration_wrapper(MITER_JOIN), - [](enumeration_wrapper e) { return enumeration(line_join_enum(e.value)).as_string();}}, + [](enumeration_wrapper e) { return enumeration(line_join_enum(e.value)).as_string();}, property_types::target_double }, property_meta_type{ "stroke-linecap", enumeration_wrapper(BUTT_CAP), - [](enumeration_wrapper e) { return enumeration(line_cap_enum(e.value)).as_string();}}, - property_meta_type{ "stroke-gamma", 1.0, nullptr}, - property_meta_type{ "stroke-gamma-method",static_cast(GAMMA_POWER), nullptr}, - property_meta_type{ "stroke-dashoffset", static_cast(0), nullptr}, - property_meta_type{ "stroke-dasharray", false, nullptr}, - property_meta_type{ "stroke-miterlimit", 4.0, nullptr}, - property_meta_type{ "geometry-transform", false, nullptr}, + [](enumeration_wrapper e) { return enumeration(line_cap_enum(e.value)).as_string();}, property_types::target_double }, + property_meta_type{ "stroke-gamma", 1.0, nullptr, property_types::target_double }, + property_meta_type{ "stroke-gamma-method",static_cast(GAMMA_POWER), nullptr, property_types::target_double }, + property_meta_type{ "stroke-dashoffset", static_cast(0), nullptr, property_types::target_double }, + property_meta_type{ "stroke-dasharray", false, nullptr, property_types::target_double }, + property_meta_type{ "stroke-miterlimit", 4.0, nullptr, property_types::target_double }, + property_meta_type{ "geometry-transform", false, nullptr, property_types::target_transform }, property_meta_type{ "line-rasterizer", enumeration_wrapper(RASTERIZER_FULL), - [](enumeration_wrapper e) { return enumeration(line_rasterizer_enum(e.value)).as_string();}}, - property_meta_type{ "transform", false, nullptr}, - property_meta_type{ "spacing", 0.0, nullptr}, - property_meta_type{ "max-error", 0.0, nullptr}, - property_meta_type{ "allow-overlap",false, nullptr}, - property_meta_type{ "ignore-placement", false, nullptr}, - property_meta_type{ "width",static_cast(0), nullptr}, - property_meta_type{ "height",static_cast(0), nullptr}, - property_meta_type{ "file", "", nullptr}, - property_meta_type{ "shield-dx", 0.0, nullptr}, - property_meta_type{ "shield-dy", 0.0, nullptr}, - property_meta_type{ "unlock-image",false, nullptr}, - property_meta_type{ "text-opacity", 1.0, nullptr}, - property_meta_type{ "mode",false, nullptr}, - property_meta_type{ "scaling", 1.0, nullptr}, - property_meta_type{ "filter-factor", 1.0, nullptr}, - property_meta_type{ "mesh-size", static_cast(0), nullptr}, - property_meta_type{ "premultiplied", false, nullptr}, - property_meta_type{ "smooth", false, nullptr}, + [](enumeration_wrapper e) { return enumeration(line_rasterizer_enum(e.value)).as_string();}, property_types::target_double }, + property_meta_type{ "transform", false, nullptr, property_types::target_transform }, + property_meta_type{ "spacing", 0.0, nullptr, property_types::target_double }, + property_meta_type{ "max-error", 0.0, nullptr, property_types::target_double }, + property_meta_type{ "allow-overlap",false, nullptr, property_types::target_bool }, + property_meta_type{ "ignore-placement", false, nullptr, property_types::target_bool }, + property_meta_type{ "width",static_cast(0), nullptr, property_types::target_double }, + property_meta_type{ "height",static_cast(0), nullptr, property_types::target_double }, + property_meta_type{ "file", "", nullptr, property_types::target_string }, + property_meta_type{ "shield-dx", 0.0, nullptr, property_types::target_double }, + property_meta_type{ "shield-dy", 0.0, nullptr, property_types::target_double }, + property_meta_type{ "unlock-image",false, nullptr, property_types::target_bool }, + property_meta_type{ "text-opacity", 1.0, nullptr, property_types::target_double }, + property_meta_type{ "mode",false, nullptr, property_types::target_double }, + property_meta_type{ "scaling", 1.0, nullptr, property_types::target_double }, + property_meta_type{ "filter-factor", 1.0, nullptr, property_types::target_double }, + property_meta_type{ "mesh-size", static_cast(0), nullptr, property_types::target_double }, + property_meta_type{ "premultiplied", false, nullptr, property_types::target_bool }, + property_meta_type{ "smooth", false, nullptr, property_types::target_double }, property_meta_type{ "simplify-algorithm", enumeration_wrapper(radial_distance), - [](enumeration_wrapper e) { return *simplify_algorithm_to_string(simplify_algorithm_e(e.value));}}, - property_meta_type{ "simplify-tolerance", 0.0, nullptr}, + [](enumeration_wrapper e) { return *simplify_algorithm_to_string(simplify_algorithm_e(e.value));}, property_types::target_double }, + property_meta_type{ "simplify-tolerance", 0.0, nullptr, property_types::target_double }, property_meta_type{ "halo-rasterizer", enumeration_wrapper(HALO_RASTERIZER_FULL), - [](enumeration_wrapper e) { return enumeration(halo_rasterizer_enum(e.value)).as_string();}}, - property_meta_type{ "text-placements", false, nullptr}, + [](enumeration_wrapper e) { return enumeration(halo_rasterizer_enum(e.value)).as_string();}, property_types::target_double }, + property_meta_type{ "text-placements", false, nullptr, property_types::target_double }, property_meta_type{ "placement", enumeration_wrapper(MARKER_POINT_PLACEMENT), - [](enumeration_wrapper e) { return enumeration(marker_placement_enum(e.value)).as_string();}}, // FIXME - rename to "markers-placement-type" + [](enumeration_wrapper e) { return enumeration(marker_placement_enum(e.value)).as_string();}, property_types::target_double }, // FIXME - rename to "markers-placement-type" property_meta_type{ "multi-policy", enumeration_wrapper(MARKER_EACH_MULTI), - [](enumeration_wrapper e) { return enumeration(marker_multi_policy_enum(e.value)).as_string();}}, // FIXME - better naming ^^ + [](enumeration_wrapper e) { return enumeration(marker_multi_policy_enum(e.value)).as_string();}, property_types::target_double }, // FIXME - better naming ^^ property_meta_type{ "placement", enumeration_wrapper(CENTROID_POINT_PLACEMENT), - [](enumeration_wrapper e) { return enumeration(point_placement_enum(e.value)).as_string();}}, - property_meta_type{ "raster-colorizer", nullptr, nullptr } + [](enumeration_wrapper e) { return enumeration(point_placement_enum(e.value)).as_string();}, property_types::target_double }, + property_meta_type{ "raster-colorizer", nullptr, nullptr, property_types::target_colorizer} }; property_meta_type const& get_meta(mapnik::keys key) @@ -99,18 +99,18 @@ property_meta_type const& get_meta(mapnik::keys key) mapnik::keys get_key(std::string const& name) { - std::string name_copy(name); - boost::algorithm::replace_all(name_copy,"_","-"); - for (unsigned i=0; i< to_integral(keys::MAX_SYMBOLIZER_KEY) ; ++i) - { - property_meta_type const& item = key_meta[i]; - if (name_copy == std::get<0>(item)) - { - return static_cast(i); - } - } - throw std::runtime_error("no key found for '" + name + "'"); - return static_cast(0); + std::string name_copy(name); + boost::algorithm::replace_all(name_copy,"_","-"); + for (unsigned i=0; i< to_integral(keys::MAX_SYMBOLIZER_KEY) ; ++i) + { + property_meta_type const& item = key_meta[i]; + if (name_copy == std::get<0>(item)) + { + return static_cast(i); + } + } + throw std::runtime_error("no key found for '" + name + "'"); + return static_cast(0); } }