From 6c1b6e301d3e8e581a2bc55283852a5437218b61 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 8 Feb 2016 15:09:15 -0800 Subject: [PATCH 1/4] gradient does not need to be a fancy enumeration --- include/mapnik/gradient.hpp | 15 ++++----------- src/gradient.cpp | 18 ------------------ 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/include/mapnik/gradient.hpp b/include/mapnik/gradient.hpp index f8eff6e7d3..f151ebe8fd 100644 --- a/include/mapnik/gradient.hpp +++ b/include/mapnik/gradient.hpp @@ -28,7 +28,6 @@ // mapnik #include -#include // stl #include @@ -39,26 +38,20 @@ namespace mapnik using stop_pair = std::pair; using stop_array = std::vector; -enum gradient_enum +enum gradient_e { NO_GRADIENT, LINEAR, - RADIAL, - gradient_enum_MAX + RADIAL }; -DEFINE_ENUM( gradient_e, gradient_enum ); - -enum gradient_unit_enum +enum gradient_unit_e { USER_SPACE_ON_USE, USER_SPACE_ON_USE_BOUNDING_BOX, // used to indicate % age values were specified. This are % of the svg image extent. - OBJECT_BOUNDING_BOX, // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding box and (1,1) is at the bottom/right of the object bounding box) - gradient_unit_enum_MAX + OBJECT_BOUNDING_BOX // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding box and (1,1) is at the bottom/right of the object bounding box) }; -DEFINE_ENUM( gradient_unit_e, gradient_unit_enum ); - class MAPNIK_DECL gradient { // transform diff --git a/src/gradient.cpp b/src/gradient.cpp index 037cf8fc79..0c9c6b8fa9 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -26,24 +26,6 @@ namespace mapnik { -static const char * gradient_strings[] = { - "no-gradient", - "linear", - "radial", - "" -}; - -IMPLEMENT_ENUM( gradient_e, gradient_strings ) - -static const char * gradient_unit_strings[] = { - "user-space-on-use", - "user-space-on-use-bounding-box", - "object-bounding-box", - "" -}; - -IMPLEMENT_ENUM( gradient_unit_e, gradient_unit_strings ) - gradient::gradient() : transform_(), x1_(0), From 8ecb42894f2d798c75b02445c9dc2ba1fe8661dc Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 9 Feb 2016 10:08:29 -0800 Subject: [PATCH 2/4] restore << operator for mapnik::enumeration + add unit test --- include/mapnik/enumeration.hpp | 10 +++++++++ test/unit/numerics/enumeration.cpp | 36 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/unit/numerics/enumeration.cpp diff --git a/include/mapnik/enumeration.hpp b/include/mapnik/enumeration.hpp index 489fc6052a..9064c2d343 100644 --- a/include/mapnik/enumeration.hpp +++ b/include/mapnik/enumeration.hpp @@ -246,6 +246,16 @@ class MAPNIK_DECL enumeration { static bool our_verified_flag_; }; +/** ostream operator for enumeration + * @relates mapnik::enumeration + */ +template +std::ostream & +operator<<(std::ostream & os, const mapnik::enumeration & e) +{ + return os << e.as_string(); +} + } // end of namespace /** Helper macro. diff --git a/test/unit/numerics/enumeration.cpp b/test/unit/numerics/enumeration.cpp new file mode 100644 index 0000000000..07813aabfb --- /dev/null +++ b/test/unit/numerics/enumeration.cpp @@ -0,0 +1,36 @@ +#include "catch.hpp" +#include +#include + +namespace mapnik { + + enum _test_enumeration_enum : std::uint8_t + { + TEST_ONE, + TEST_TWO, + _test_enumeration_enum_MAX + }; + + DEFINE_ENUM( _test_enumeration_e, _test_enumeration_enum ); + + static const char * _test_enumeration_strings[] = { + "test_one", + "test_two", + "" + }; + + IMPLEMENT_ENUM( _test_enumeration_e, _test_enumeration_strings ) + +} + +TEST_CASE("enumeration") { + + mapnik::_test_enumeration_e e(mapnik::TEST_ONE); + CHECK( e.as_string() == "test_one" ); + // test the << operator, which calls `as_string` internally + // this is not used in mapnik, but kept for back compat + std::stringstream s; + s << e; + CHECK( s.str() == "test_one" ); + +} \ No newline at end of file From 10bd37ddd7c3b8725b8e5a20487b5429d3da23e4 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 9 Feb 2016 10:09:12 -0800 Subject: [PATCH 3/4] avoid unneccesary dependence on << operator of mapnik::enumeration --- src/save_map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/save_map.cpp b/src/save_map.cpp index 6b9ea1f8bd..f3d89153c8 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -104,7 +104,7 @@ void serialize_raster_colorizer(ptree & sym_node, raster_colorizer dfl; if (colorizer->get_default_mode() != dfl.get_default_mode() || explicit_defaults) { - set_attr(col_node, "default-mode", colorizer->get_default_mode()); + set_attr(col_node, "default-mode", colorizer->get_default_mode().as_string()); } if (colorizer->get_default_color() != dfl.get_default_color() || explicit_defaults) { @@ -403,7 +403,7 @@ void serialize_style( ptree & map_node, std::string const& name, feature_type_st filter_mode_e filter_mode = style.get_filter_mode(); if (filter_mode != dfl.get_filter_mode() || explicit_defaults) { - set_attr(style_node, "filter-mode", filter_mode); + set_attr(style_node, "filter-mode", filter_mode.as_string()); } double opacity = style.get_opacity(); From fa6376d9a1e489d556a880bd73430b37201df65b Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 11 Feb 2016 10:18:16 +0100 Subject: [PATCH 4/4] update variant submodule --- deps/mapbox/variant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/mapbox/variant b/deps/mapbox/variant index c9a662a3b5..0bd70f39a1 160000 --- a/deps/mapbox/variant +++ b/deps/mapbox/variant @@ -1 +1 @@ -Subproject commit c9a662a3b531d8a21055be4e0b4c71dc25fc0d00 +Subproject commit 0bd70f39a1d12dd8caea055f5ba970d404f4b825