From 11b0816d2afc11869466eae51d7879528ecf4819 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Jul 2014 12:08:16 -0700 Subject: [PATCH 1/6] sqlite plugin: use mapnik::geometry_container alias --- plugins/input/sqlite/sqlite_datasource.cpp | 2 +- plugins/input/sqlite/sqlite_utils.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index f8d910040..a8e74dfb6 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -444,7 +444,7 @@ boost::optional sqlite_datasource::get_geometry_ const char* data = (const char*) rs->column_blob(0, size); if (data) { - boost::ptr_vector paths; + mapnik::geometry_container paths; if (mapnik::geometry_utils::from_wkb(paths, data, size, format_)) { mapnik::util::to_ds_type(paths,result); diff --git a/plugins/input/sqlite/sqlite_utils.hpp b/plugins/input/sqlite/sqlite_utils.hpp index e19e164b3..643e2915b 100644 --- a/plugins/input/sqlite/sqlite_utils.hpp +++ b/plugins/input/sqlite/sqlite_utils.hpp @@ -191,7 +191,7 @@ public: const char* data = static_cast(rs->column_blob(0, size)); if (data) { - boost::ptr_vector paths; + mapnik::geometry_container paths; if (mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto)) { for (unsigned i=0; icolumn_blob(0, size); if (data) { - boost::ptr_vector paths; + mapnik::geometry_container paths; mapnik::box2d bbox; if (mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto)) { @@ -365,7 +365,7 @@ public: const char* data = static_cast(rs->column_blob(0, size)); if (data) { - boost::ptr_vector paths; + mapnik::geometry_container paths; if (mapnik::geometry_utils::from_wkb(paths, data, size, mapnik::wkbAuto)) { for (unsigned i=0; i Date: Thu, 24 Jul 2014 14:31:59 -0700 Subject: [PATCH 2/6] refactor spirit grammars --- benchmark/test_polygon_clipping.cpp | 1 + bindings/python/mapnik_feature.cpp | 17 +- bindings/python/mapnik_geometry.cpp | 108 +++---- bindings/python/mapnik_python.cpp | 2 - bindings/python/mapnik_wkt_reader.cpp | 56 ---- include/mapnik/css_color_grammar.hpp | 153 +++++++++- include/mapnik/feature.hpp | 9 +- .../mapnik/image_filter_grammar_impl.hpp | 2 - .../json/feature_collection_grammar.hpp | 6 +- .../mapnik/json/feature_collection_parser.hpp | 55 ---- .../mapnik/json/feature_generator.hpp | 23 +- .../mapnik/json/feature_generator_grammar.hpp | 88 +----- .../json/feature_generator_grammar_impl.hpp | 105 +++++++ include/mapnik/json/feature_grammar.hpp | 6 +- .../mapnik/json/feature_grammar_impl.hpp | 7 +- include/mapnik/json/feature_parser.hpp | 39 +-- include/mapnik/json/geojson_generator.hpp | 63 ---- .../json/geometry_generator_grammar.hpp | 143 +-------- .../json/geometry_generator_grammar_impl.hpp | 141 +++++++++ include/mapnik/json/geometry_grammar.hpp | 20 +- .../mapnik/json/geometry_grammar_impl.hpp | 3 - include/mapnik/json/geometry_parser.hpp | 34 +-- include/mapnik/json/symbolizer_grammar.hpp | 6 +- .../mapnik/path_expression_grammar_impl.hpp | 2 - .../{util => svg}/geometry_svg_generator.hpp | 50 +--- .../svg/geometry_svg_generator_impl.hpp | 71 +++++ include/mapnik/svg/output/svg_generator.hpp | 21 +- include/mapnik/transform_expression.hpp | 6 +- .../mapnik/transform_expression_grammar.hpp | 1 + .../transform_expression_grammar_impl.hpp | 3 +- include/mapnik/transform_processor.hpp | 1 - include/mapnik/util/container_adapter.hpp | 4 + .../mapnik/util/geometry_to_geojson.hpp | 43 ++- include/mapnik/util/geometry_to_svg.hpp | 6 +- include/mapnik/util/geometry_to_wkt.hpp | 19 +- include/mapnik/wkb.hpp | 2 +- include/mapnik/wkt/wkt_factory.hpp | 25 +- .../wkt_generator_grammar.hpp} | 15 +- .../mapnik/wkt/wkt_generator_grammar_impl.hpp | 26 +- include/mapnik/wkt/wkt_grammar.hpp | 279 +++++------------- include/mapnik/wkt/wkt_grammar_impl.hpp | 149 ++++++++++ plugins/input/csv/csv_datasource.cpp | 2 + plugins/input/geojson/geojson_datasource.cpp | 17 +- plugins/input/geojson/geojson_datasource.hpp | 1 - plugins/input/topojson/build.py | 1 - .../input/topojson/topojson_datasource.cpp | 1 + plugins/input/topojson/topojson_grammar.cpp | 35 --- src/build.py | 12 - src/css_color_grammar.cpp | 166 +---------- src/expression.cpp | 1 + src/image_filter_types.cpp | 3 +- src/json/feature_collection_parser.cpp | 56 ---- src/json/feature_parser.cpp | 50 ---- src/json/geometry_parser.cpp | 65 ---- src/parse_path.cpp | 2 +- src/parse_transform.cpp | 2 +- src/svg/output/process_symbolizers.cpp | 20 +- src/svg/output/svg_generator.cpp | 7 +- src/transform_expression.cpp | 3 - src/wkt/wkt_factory.cpp | 59 ---- tests/cpp_tests/geometry_converters_test.cpp | 37 ++- tests/python_tests/geometry_io_test.py | 20 +- 62 files changed, 976 insertions(+), 1394 deletions(-) delete mode 100644 bindings/python/mapnik_wkt_reader.cpp rename src/image_filter_grammar.cpp => include/mapnik/image_filter_grammar_impl.hpp (97%) delete mode 100644 include/mapnik/json/feature_collection_parser.hpp rename src/expression_grammar.cpp => include/mapnik/json/feature_generator.hpp (62%) create mode 100644 include/mapnik/json/feature_generator_grammar_impl.hpp rename src/json/feature_grammar.cpp => include/mapnik/json/feature_grammar_impl.hpp (91%) delete mode 100644 include/mapnik/json/geojson_generator.hpp create mode 100644 include/mapnik/json/geometry_generator_grammar_impl.hpp rename src/json/geometry_grammar.cpp => include/mapnik/json/geometry_grammar_impl.hpp (96%) rename src/path_expression_grammar.cpp => include/mapnik/path_expression_grammar_impl.hpp (95%) rename include/mapnik/{util => svg}/geometry_svg_generator.hpp (74%) create mode 100644 include/mapnik/svg/geometry_svg_generator_impl.hpp rename src/transform_expression_grammar.cpp => include/mapnik/transform_expression_grammar_impl.hpp (98%) rename src/json/geojson_generator.cpp => include/mapnik/util/geometry_to_geojson.hpp (53%) rename include/mapnik/{util/geometry_wkt_generator.hpp => wkt/wkt_generator_grammar.hpp} (96%) rename src/wkt/wkt_generator.cpp => include/mapnik/wkt/wkt_generator_grammar_impl.hpp (82%) create mode 100644 include/mapnik/wkt/wkt_grammar_impl.hpp delete mode 100644 plugins/input/topojson/topojson_grammar.cpp delete mode 100644 src/json/feature_collection_parser.cpp delete mode 100644 src/json/feature_parser.cpp delete mode 100644 src/json/geometry_parser.cpp delete mode 100644 src/wkt/wkt_factory.cpp diff --git a/benchmark/test_polygon_clipping.cpp b/benchmark/test_polygon_clipping.cpp index e81fc4771..cde27fbe4 100644 --- a/benchmark/test_polygon_clipping.cpp +++ b/benchmark/test_polygon_clipping.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/bindings/python/mapnik_feature.cpp b/bindings/python/mapnik_feature.cpp index 157ecda25..939f16dc7 100644 --- a/bindings/python/mapnik_feature.cpp +++ b/bindings/python/mapnik_feature.cpp @@ -30,7 +30,6 @@ #include #include - // mapnik #include #include @@ -40,8 +39,7 @@ #include #include #include -#include -#include +#include // stl #include @@ -49,7 +47,6 @@ namespace { using mapnik::geometry_utils; -using mapnik::from_wkt; using mapnik::context_type; using mapnik::context_ptr; using mapnik::feature_kv_iterator; @@ -57,13 +54,13 @@ using mapnik::feature_kv_iterator; mapnik::geometry_type const& (mapnik::feature_impl::*get_geometry_by_const_ref)(std::size_t) const = &mapnik::feature_impl::get_geometry; boost::ptr_vector const& (mapnik::feature_impl::*get_paths_by_const_ref)() const = &mapnik::feature_impl::paths; -void feature_add_geometries_from_wkb(mapnik::feature_impl &feature, std::string wkb) +void feature_add_geometries_from_wkb(mapnik::feature_impl & feature, std::string wkb) { bool result = geometry_utils::from_wkb(feature.paths(), wkb.c_str(), wkb.size()); if (!result) throw std::runtime_error("Failed to parse WKB"); } -void feature_add_geometries_from_wkt(mapnik::feature_impl &feature, std::string wkt) +void feature_add_geometries_from_wkt(mapnik::feature_impl & feature, std::string const& wkt) { bool result = mapnik::from_wkt(wkt, feature.paths()); if (!result) throw std::runtime_error("Failed to parse WKT"); @@ -71,11 +68,8 @@ void feature_add_geometries_from_wkt(mapnik::feature_impl &feature, std::string mapnik::feature_ptr from_geojson_impl(std::string const& json, mapnik::context_ptr const& ctx) { - mapnik::transcoder tr("utf8"); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); - mapnik::json::generic_json json_base; - mapnik::json::feature_parser parser(json_base, tr); - if (!parser.parse(json.begin(), json.end(), *feature)) + if (!mapnik::json::from_geojson(json,*feature)) { throw std::runtime_error("Failed to parse geojson feature"); } @@ -85,8 +79,7 @@ mapnik::feature_ptr from_geojson_impl(std::string const& json, mapnik::context_p std::string feature_to_geojson(mapnik::feature_impl const& feature) { std::string json; - mapnik::json::feature_generator g; - if (!g.generate(json,feature)) + if (!mapnik::json::to_geojson(json,feature)) { throw std::runtime_error("Failed to generate GeoJSON"); } diff --git a/bindings/python/mapnik_geometry.cpp b/bindings/python/mapnik_geometry.cpp index f1ad158f5..b04636098 100644 --- a/bindings/python/mapnik_geometry.cpp +++ b/bindings/python/mapnik_geometry.cpp @@ -28,31 +28,24 @@ #include #include #include - +#include // mapnik #include -#include -#include -#include -#include - -#include -#include +#include // from_wkt #include +#include // from_geojson +#include #include +#include +#include // stl #include namespace { -using mapnik::from_wkt; -using mapnik::geometry_type; - -using path_type = boost::ptr_vector; - -geometry_type const& getitem_impl(path_type & p, int key) +mapnik::geometry_type const& getitem_impl(mapnik::geometry_container & p, int key) { if (key >=0 && key < static_cast(p.size())) return p[key]; @@ -60,49 +53,49 @@ geometry_type const& getitem_impl(path_type & p, int key) throw boost::python::error_already_set(); } -void add_wkt_impl(path_type& p, std::string const& wkt) +void add_wkt_impl(mapnik::geometry_container& p, std::string const& wkt) { if (!mapnik::from_wkt(wkt , p)) throw std::runtime_error("Failed to parse WKT"); } -void add_wkb_impl(path_type& p, std::string const& wkb) +void add_wkb_impl(mapnik::geometry_container& p, std::string const& wkb) { if (!mapnik::geometry_utils::from_wkb(p, wkb.c_str(), wkb.size())) throw std::runtime_error("Failed to parse WKB"); } -void add_geojson_impl(path_type& p, std::string const& json) +void add_geojson_impl(mapnik::geometry_container& paths, std::string const& json) { - if (!mapnik::json::from_geojson(json, p)) + if (!mapnik::json::from_geojson(json, paths)) throw std::runtime_error("Failed to parse geojson geometry"); } -std::shared_ptr from_wkt_impl(std::string const& wkt) +std::shared_ptr from_wkt_impl(std::string const& wkt) { - std::shared_ptr paths = std::make_shared(); + std::shared_ptr paths = std::make_shared(); if (!mapnik::from_wkt(wkt, *paths)) throw std::runtime_error("Failed to parse WKT"); return paths; } -std::shared_ptr from_wkb_impl(std::string const& wkb) +std::shared_ptr from_wkb_impl(std::string const& wkb) { - std::shared_ptr paths = std::make_shared(); + std::shared_ptr paths = std::make_shared(); if (!mapnik::geometry_utils::from_wkb(*paths, wkb.c_str(), wkb.size())) throw std::runtime_error("Failed to parse WKB"); return paths; } -std::shared_ptr from_geojson_impl(std::string const& json) +std::shared_ptr from_geojson_impl(std::string const& json) { - std::shared_ptr paths = std::make_shared(); - if (! mapnik::json::from_geojson(json, *paths)) + std::shared_ptr paths = std::make_shared(); + if (!mapnik::json::from_geojson(json, *paths)) throw std::runtime_error("Failed to parse geojson geometry"); return paths; } -mapnik::box2d envelope_impl(path_type & p) +mapnik::box2d envelope_impl(mapnik::geometry_container & p) { mapnik::box2d b; bool first = true; @@ -130,7 +123,7 @@ inline std::string boost_version() return s.str(); } -PyObject* to_wkb( geometry_type const& geom, mapnik::util::wkbByteOrder byte_order) +PyObject* to_wkb(mapnik::geometry_type const& geom, mapnik::util::wkbByteOrder byte_order) { mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,byte_order); if (wkb) @@ -149,7 +142,7 @@ PyObject* to_wkb( geometry_type const& geom, mapnik::util::wkbByteOrder byte_ord } } -PyObject* to_wkb2( path_type const& p, mapnik::util::wkbByteOrder byte_order) +PyObject* to_wkb2( mapnik::geometry_container const& p, mapnik::util::wkbByteOrder byte_order) { mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(p,byte_order); if (wkb) @@ -168,44 +161,50 @@ PyObject* to_wkb2( path_type const& p, mapnik::util::wkbByteOrder byte_order) } } -std::string to_wkt( geometry_type const& geom) +std::string to_wkt(mapnik::geometry_type const& geom) { - std::string wkt; // Use Python String directly ? - bool result = mapnik::util::to_wkt(wkt,geom); - if (!result) + std::string wkt; + if (!mapnik::util::to_wkt(wkt,geom)) { throw std::runtime_error("Generate WKT failed"); } return wkt; } -std::string to_wkt2( path_type const& geom) +std::string to_wkt2(mapnik::geometry_container const& geom) { - std::string wkt; // Use Python String directly ? - bool result = mapnik::util::to_wkt(wkt,geom); - if (!result) + std::string wkt; + if (!mapnik::util::to_wkt(wkt,geom)) { throw std::runtime_error("Generate WKT failed"); } return wkt; } -std::string to_geojson( path_type const& geom) +std::string to_geojson(mapnik::geometry_type const& geom) { - std::string json; - mapnik::json::geometry_generator g; - if (!g.generate(json,geom)) + std::string wkt; + if (!mapnik::util::to_geojson(wkt,geom)) { - throw std::runtime_error("Failed to generate GeoJSON"); + throw std::runtime_error("Generate JSON failed"); } - return json; + return wkt; } -std::string to_svg( geometry_type const& geom) +std::string to_geojson2(mapnik::geometry_container const& geom) { - std::string svg; // Use Python String directly ? - bool result = mapnik::util::to_svg(svg,geom); - if (!result) + std::string wkt; + if (!mapnik::util::to_geojson(wkt,geom)) + { + throw std::runtime_error("Generate JSON failed"); + } + return wkt; +} + +std::string to_svg(mapnik::geometry_type const& geom) +{ + std::string svg; + if (!mapnik::util::to_svg(svg,geom)) { throw std::runtime_error("Generate SVG failed"); } @@ -214,7 +213,7 @@ std::string to_svg( geometry_type const& geom) /* // https://github.com/mapnik/mapnik/issues/1437 -std::string to_svg2( path_type const& geom) +std::string to_svg2( mapnik::geometry_container const& geom) { std::string svg; // Use Python String directly ? bool result = mapnik::util::to_svg(svg,geom); @@ -242,19 +241,20 @@ void export_geometry() ; using mapnik::geometry_type; - class_, boost::noncopyable>("Geometry2d",no_init) - .def("envelope",&geometry_type::envelope) - // .def("__str__",&geometry_type::to_string) - .def("type",&geometry_type::type) + class_, boost::noncopyable>("Geometry2d",no_init) + .def("envelope",&mapnik::geometry_type::envelope) + // .def("__str__",&mapnik::geometry_type::to_string) + .def("type",&mapnik::geometry_type::type) .def("to_wkb",&to_wkb) .def("to_wkt",&to_wkt) + .def("to_geojson",&to_geojson) .def("to_svg",&to_svg) // TODO add other geometry_type methods ; - class_, boost::noncopyable>("Path") + class_, boost::noncopyable>("Path") .def("__getitem__", getitem_impl,return_value_policy()) - .def("__len__", &path_type::size) + .def("__len__", &mapnik::geometry_container::size) .def("envelope",envelope_impl) .def("add_wkt",add_wkt_impl) .def("add_wkb",add_wkb_impl) @@ -265,7 +265,7 @@ void export_geometry() .def("from_wkt",from_wkt_impl) .def("from_wkb",from_wkb_impl) .def("from_geojson",from_geojson_impl) - .def("to_geojson",to_geojson) + .def("to_geojson",&to_geojson2) .staticmethod("from_wkt") .staticmethod("from_wkb") .staticmethod("from_geojson") diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index e4c895cba..11abd698f 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -84,7 +84,6 @@ void export_view_transform(); void export_raster_colorizer(); void export_label_collision_detector(); void export_logger(); -void export_wkt_reader(); #include #include @@ -601,7 +600,6 @@ BOOST_PYTHON_MODULE(_mapnik) export_raster_colorizer(); export_label_collision_detector(); export_logger(); - export_wkt_reader(); def("clear_cache", &clear_cache, "\n" diff --git a/bindings/python/mapnik_wkt_reader.cpp b/bindings/python/mapnik_wkt_reader.cpp deleted file mode 100644 index 318eccc07..000000000 --- a/bindings/python/mapnik_wkt_reader.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2013 Artem Pavlenko, Jean-Francois Doyon - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#include "boost_std_shared_shim.hpp" - -// boost -#include -#include -#include -#include -// mapnik -#include -#include - -namespace impl { - -using path_type = boost::ptr_vector; - -std::shared_ptr from_wkt(mapnik::wkt_parser & p, std::string const& wkt) -{ - std::shared_ptr paths = std::make_shared(); - if (!p.parse(wkt, *paths)) - throw std::runtime_error("Failed to parse WKT"); - return paths; -} - -} - -void export_wkt_reader() -{ - using mapnik::wkt_parser; - using namespace boost::python; - - class_("WKTReader",init<>()) - .def("read",&impl::from_wkt) - ; -} diff --git a/include/mapnik/css_color_grammar.hpp b/include/mapnik/css_color_grammar.hpp index 2b6a24e4e..222b8ce05 100644 --- a/include/mapnik/css_color_grammar.hpp +++ b/include/mapnik/css_color_grammar.hpp @@ -62,7 +62,158 @@ using ascii_space_type = boost::spirit::ascii::space_type; struct named_colors_ : qi::symbols { - named_colors_(); + named_colors_() + { + add + ("aliceblue", color(240, 248, 255)) + ("antiquewhite", color(250, 235, 215)) + ("aqua", color(0, 255, 255)) + ("aquamarine", color(127, 255, 212)) + ("azure", color(240, 255, 255)) + ("beige", color(245, 245, 220)) + ("bisque", color(255, 228, 196)) + ("black", color(0, 0, 0)) + ("blanchedalmond", color(255,235,205)) + ("blue", color(0, 0, 255)) + ("blueviolet", color(138, 43, 226)) + ("brown", color(165, 42, 42)) + ("burlywood", color(222, 184, 135)) + ("cadetblue", color(95, 158, 160)) + ("chartreuse", color(127, 255, 0)) + ("chocolate", color(210, 105, 30)) + ("coral", color(255, 127, 80)) + ("cornflowerblue", color(100, 149, 237)) + ("cornsilk", color(255, 248, 220)) + ("crimson", color(220, 20, 60)) + ("cyan", color(0, 255, 255)) + ("darkblue", color(0, 0, 139)) + ("darkcyan", color(0, 139, 139)) + ("darkgoldenrod", color(184, 134, 11)) + ("darkgray", color(169, 169, 169)) + ("darkgreen", color(0, 100, 0)) + ("darkgrey", color(169, 169, 169)) + ("darkkhaki", color(189, 183, 107)) + ("darkmagenta", color(139, 0, 139)) + ("darkolivegreen", color(85, 107, 47)) + ("darkorange", color(255, 140, 0)) + ("darkorchid", color(153, 50, 204)) + ("darkred", color(139, 0, 0)) + ("darksalmon", color(233, 150, 122)) + ("darkseagreen", color(143, 188, 143)) + ("darkslateblue", color(72, 61, 139)) + ("darkslategrey", color(47, 79, 79)) + ("darkturquoise", color(0, 206, 209)) + ("darkviolet", color(148, 0, 211)) + ("deeppink", color(255, 20, 147)) + ("deepskyblue", color(0, 191, 255)) + ("dimgray", color(105, 105, 105)) + ("dimgrey", color(105, 105, 105)) + ("dodgerblue", color(30, 144, 255)) + ("firebrick", color(178, 34, 34)) + ("floralwhite", color(255, 250, 240)) + ("forestgreen", color(34, 139, 34)) + ("fuchsia", color(255, 0, 255)) + ("gainsboro", color(220, 220, 220)) + ("ghostwhite", color(248, 248, 255)) + ("gold", color(255, 215, 0)) + ("goldenrod", color(218, 165, 32)) + ("gray", color(128, 128, 128)) + ("grey", color(128, 128, 128)) + ("green", color(0, 128, 0)) + ("greenyellow", color(173, 255, 47)) + ("honeydew", color(240, 255, 240)) + ("hotpink", color(255, 105, 180)) + ("indianred", color(205, 92, 92)) + ("indigo", color(75, 0, 130)) + ("ivory", color(255, 255, 240)) + ("khaki", color(240, 230, 140)) + ("lavender", color(230, 230, 250)) + ("lavenderblush", color(255, 240, 245)) + ("lawngreen", color(124, 252, 0)) + ("lemonchiffon", color(255, 250, 205)) + ("lightblue", color(173, 216, 230)) + ("lightcoral", color(240, 128, 128)) + ("lightcyan", color(224, 255, 255)) + ("lightgoldenrodyellow", color(250, 250, 210)) + ("lightgray", color(211, 211, 211)) + ("lightgreen", color(144, 238, 144)) + ("lightgrey", color(211, 211, 211)) + ("lightpink", color(255, 182, 193)) + ("lightsalmon", color(255, 160, 122)) + ("lightseagreen", color(32, 178, 170)) + ("lightskyblue", color(135, 206, 250)) + ("lightslategray", color(119, 136, 153)) + ("lightslategrey", color(119, 136, 153)) + ("lightsteelblue", color(176, 196, 222)) + ("lightyellow", color(255, 255, 224)) + ("lime", color(0, 255, 0)) + ("limegreen", color(50, 205, 50)) + ("linen", color(250, 240, 230)) + ("magenta", color(255, 0, 255)) + ("maroon", color(128, 0, 0)) + ("mediumaquamarine", color(102, 205, 170)) + ("mediumblue", color(0, 0, 205)) + ("mediumorchid", color(186, 85, 211)) + ("mediumpurple", color(147, 112, 219)) + ("mediumseagreen", color(60, 179, 113)) + ("mediumslateblue", color(123, 104, 238)) + ("mediumspringgreen", color(0, 250, 154)) + ("mediumturquoise", color(72, 209, 204)) + ("mediumvioletred", color(199, 21, 133)) + ("midnightblue", color(25, 25, 112)) + ("mintcream", color(245, 255, 250)) + ("mistyrose", color(255, 228, 225)) + ("moccasin", color(255, 228, 181)) + ("navajowhite", color(255, 222, 173)) + ("navy", color(0, 0, 128)) + ("oldlace", color(253, 245, 230)) + ("olive", color(128, 128, 0)) + ("olivedrab", color(107, 142, 35)) + ("orange", color(255, 165, 0)) + ("orangered", color(255, 69, 0)) + ("orchid", color(218, 112, 214)) + ("palegoldenrod", color(238, 232, 170)) + ("palegreen", color(152, 251, 152)) + ("paleturquoise", color(175, 238, 238)) + ("palevioletred", color(219, 112, 147)) + ("papayawhip", color(255, 239, 213)) + ("peachpuff", color(255, 218, 185)) + ("peru", color(205, 133, 63)) + ("pink", color(255, 192, 203)) + ("plum", color(221, 160, 221)) + ("powderblue", color(176, 224, 230)) + ("purple", color(128, 0, 128)) + ("red", color(255, 0, 0)) + ("rosybrown", color(188, 143, 143)) + ("royalblue", color(65, 105, 225)) + ("saddlebrown", color(139, 69, 19)) + ("salmon", color(250, 128, 114)) + ("sandybrown", color(244, 164, 96)) + ("seagreen", color(46, 139, 87)) + ("seashell", color(255, 245, 238)) + ("sienna", color(160, 82, 45)) + ("silver", color(192, 192, 192)) + ("skyblue", color(135, 206, 235)) + ("slateblue", color(106, 90, 205)) + ("slategray", color(112, 128, 144)) + ("slategrey", color(112, 128, 144)) + ("snow", color(255, 250, 250)) + ("springgreen", color(0, 255, 127)) + ("steelblue", color(70, 130, 180)) + ("tan", color(210, 180, 140)) + ("teal", color(0, 128, 128)) + ("thistle", color(216, 191, 216)) + ("tomato", color(255, 99, 71)) + ("turquoise", color(64, 224, 208)) + ("violet", color(238, 130, 238)) + ("wheat", color(245, 222, 179)) + ("white", color(255, 255, 255)) + ("whitesmoke", color(245, 245, 245)) + ("yellow", color(255, 255, 0)) + ("yellowgreen", color(154, 205, 50)) + ("transparent", color(0, 0, 0, 0)) + ; + } } ; // clipper helper diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 1b54ca7ac..10be7d64f 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -32,9 +32,6 @@ #include #include -// boost -#include - // stl #include #include @@ -196,12 +193,12 @@ public: return ctx_; } - inline boost::ptr_vector const& paths() const + inline geometry_container const& paths() const { return geom_cont_; } - inline boost::ptr_vector & paths() + inline geometry_container & paths() { return geom_cont_; } @@ -294,7 +291,7 @@ private: mapnik::value_integer id_; context_ptr ctx_; cont_type data_; - boost::ptr_vector geom_cont_; + geometry_container geom_cont_; raster_ptr raster_; }; diff --git a/src/image_filter_grammar.cpp b/include/mapnik/image_filter_grammar_impl.hpp similarity index 97% rename from src/image_filter_grammar.cpp rename to include/mapnik/image_filter_grammar_impl.hpp index ab15906be..38fbcc1f4 100644 --- a/src/image_filter_grammar.cpp +++ b/include/mapnik/image_filter_grammar_impl.hpp @@ -126,6 +126,4 @@ image_filter_grammar::image_filter_grammar() no_args = -(lit('(') >> lit(')')); } -template struct mapnik::image_filter_grammar >; - } diff --git a/include/mapnik/json/feature_collection_grammar.hpp b/include/mapnik/json/feature_collection_grammar.hpp index 7d08144c9..378353977 100644 --- a/include/mapnik/json/feature_collection_grammar.hpp +++ b/include/mapnik/json/feature_collection_grammar.hpp @@ -59,9 +59,9 @@ template struct feature_collection_grammar : qi::grammar(), space_type> { - feature_collection_grammar( generic_json & json, context_ptr const& ctx, mapnik::transcoder const& tr) + feature_collection_grammar(context_ptr const& ctx, mapnik::transcoder const& tr) : feature_collection_grammar::base_type(start,"start"), - feature_g(json,tr), + feature_g(tr), ctx_(ctx), generate_id_(1) { @@ -81,7 +81,7 @@ struct feature_collection_grammar : start = feature_collection | feature_from_geometry(_val) | feature(_val) ; - feature_collection = lit('{') >> (type | features | json.key_value) % lit(',') >> lit('}') + feature_collection = lit('{') >> (type | features | feature_g.json_.key_value) % lit(',') >> lit('}') ; type = lit("\"type\"") >> lit(':') >> lit("\"FeatureCollection\"") diff --git a/include/mapnik/json/feature_collection_parser.hpp b/include/mapnik/json/feature_collection_parser.hpp deleted file mode 100644 index 327433388..000000000 --- a/include/mapnik/json/feature_collection_parser.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2012 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef MAPNIK_FEATURE_COLLECTION_PARSER_HPP -#define MAPNIK_FEATURE_COLLECTION_PARSER_HPP - -// mapnik -#include -#include -#include -#include - -// stl -#include - -namespace mapnik { namespace json { - -template struct feature_collection_grammar; -template struct generic_json; - -template -class MAPNIK_DECL feature_collection_parser : private mapnik::noncopyable -{ - using iterator_type = Iterator; - using feature_type = mapnik::feature_impl; -public: - feature_collection_parser(generic_json & json, mapnik::context_ptr const& ctx, mapnik::transcoder const& tr); - ~feature_collection_parser(); - bool parse(iterator_type first, iterator_type last, std::vector & features); -private: - const std::unique_ptr > grammar_; -}; - -}} - -#endif //MAPNIK_FEATURE_COLLECTION_PARSER_HPP diff --git a/src/expression_grammar.cpp b/include/mapnik/json/feature_generator.hpp similarity index 62% rename from src/expression_grammar.cpp rename to include/mapnik/json/feature_generator.hpp index 875bd6f5a..bf5a2e5ac 100644 --- a/src/expression_grammar.cpp +++ b/include/mapnik/json/feature_generator.hpp @@ -20,13 +20,26 @@ * *****************************************************************************/ +#ifndef MAPNIK_JSON_FEATURE_GENERATOR_HPP +#define MAPNIK_JSON_FEATURE_GENERATOR_HPP + // mapnik -#include -// stl -#include +#include +#include -namespace mapnik { +// boost +#include -template struct mapnik::expression_grammar; +namespace mapnik { namespace json { +inline bool to_geojson(std::string & json, mapnik::feature_impl const& feature) +{ + using sink_type = std::back_insert_iterator; + static const mapnik::json::feature_generator_grammar grammar; + sink_type sink(json); + return boost::spirit::karma::generate(sink, grammar, feature); } + +}} + +#endif // MAPNIK_JSON_FEATURE_GENERATOR_HPP diff --git a/include/mapnik/json/feature_generator_grammar.hpp b/include/mapnik/json/feature_generator_grammar.hpp index 4a2bc31c9..5f207bbdb 100644 --- a/include/mapnik/json/feature_generator_grammar.hpp +++ b/include/mapnik/json/feature_generator_grammar.hpp @@ -24,7 +24,6 @@ #define MAPNIK_JSON_FEATURE_GENERATOR_GRAMMAR_HPP // mapnik -#include #include #include #include @@ -34,10 +33,10 @@ // boost #include #include +#include +#include #include #include -#include -#include #include #include #include @@ -89,7 +88,6 @@ struct transform_attribute @@ -144,36 +141,9 @@ template struct escaped_string : karma::grammar { - escaped_string() - : escaped_string::base_type(esc_str) - { - karma::lit_type lit; - karma::_r1_type _r1; - karma::hex_type hex; - karma::right_align_type right_align; - karma::print_type kprint; - - esc_char.add - ('"', "\\\"") - ('\\', "\\\\") - ('\b', "\\b") - ('\f', "\\f") - ('\n', "\\n") - ('\r', "\\r") - ('\t', "\\t") - ; - - esc_str = lit(_r1) - << *(esc_char - | kprint - | "\\u" << right_align(4,lit('0'))[hex]) - << lit(_r1) - ; - } - + escaped_string(); karma::rule esc_str; karma::symbols esc_char; - }; template @@ -183,50 +153,7 @@ struct feature_generator_grammar: using pair_type = std::tuple; using range_type = make_properties_range::properties_range_type; - feature_generator_grammar() - : feature_generator_grammar::base_type(feature) - , quote_("\"") - - { - boost::spirit::karma::lit_type lit; - boost::spirit::karma::uint_type uint_; - boost::spirit::karma::bool_type bool_; - boost::spirit::karma::double_type double_; - boost::spirit::karma::_val_type _val; - boost::spirit::karma::_1_type _1; - boost::spirit::karma::_r1_type _r1; - boost::spirit::karma::string_type kstring; - boost::spirit::karma::eps_type eps; - - feature = lit("{\"type\":\"Feature\",\"id\":") - << uint_[_1 = id_(_val)] - << lit(",\"geometry\":") << geometry - << lit(",\"properties\":") << properties - << lit('}') - ; - - properties = lit('{') - << -(pair % lit(',')) - << lit('}') - ; - - pair = lit('"') - << kstring[_1 = phoenix::at_c<0>(_val)] << lit('"') - << lit(':') - << value(phoenix::at_c<1>(_val)) - ; - - value = (value_null_| bool_ | int__ | double_ | ustring)[_1 = value_base_(_r1)] - ; - - value_null_ = kstring[_1 = "null"] - ; - - ustring = escaped_string_(quote_.c_str())[_1 = utf8_(_val)] - ; - } - - // rules + feature_generator_grammar(); karma::rule feature; multi_geometry_generator_grammar geometry; escaped_string escaped_string_; @@ -236,10 +163,9 @@ struct feature_generator_grammar: karma::rule value_null_; karma::rule ustring; typename karma::int_generator int__; - // phoenix functions - phoenix::function id_; - phoenix::function value_base_; - phoenix::function utf8_; + boost::phoenix::function id_; + boost::phoenix::function value_base_; + boost::phoenix::function utf8_; std::string quote_; }; diff --git a/include/mapnik/json/feature_generator_grammar_impl.hpp b/include/mapnik/json/feature_generator_grammar_impl.hpp new file mode 100644 index 000000000..bb340d4d3 --- /dev/null +++ b/include/mapnik/json/feature_generator_grammar_impl.hpp @@ -0,0 +1,105 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include + +#include +#include +#include +#include + +namespace mapnik { namespace json { + +namespace karma = boost::spirit::karma; + +template +escaped_string::escaped_string() + : escaped_string::base_type(esc_str) +{ + karma::lit_type lit; + karma::_r1_type _r1; + karma::hex_type hex; + karma::right_align_type right_align; + karma::print_type kprint; + + esc_char.add + ('"', "\\\"") + ('\\', "\\\\") + ('\b', "\\b") + ('\f', "\\f") + ('\n', "\\n") + ('\r', "\\r") + ('\t', "\\t") + ; + + esc_str = lit(_r1) + << *(esc_char + | kprint + | "\\u" << right_align(4,lit('0'))[hex]) + << lit(_r1) + ; +} + +template +feature_generator_grammar::feature_generator_grammar() + : feature_generator_grammar::base_type(feature), + quote_("\"") +{ + boost::spirit::karma::lit_type lit; + boost::spirit::karma::uint_type uint_; + boost::spirit::karma::bool_type bool_; + boost::spirit::karma::double_type double_; + boost::spirit::karma::_val_type _val; + boost::spirit::karma::_1_type _1; + boost::spirit::karma::_r1_type _r1; + boost::spirit::karma::string_type kstring; + boost::spirit::karma::eps_type eps; + + feature = lit("{\"type\":\"Feature\",\"id\":") + << uint_[_1 = id_(_val)] + << lit(",\"geometry\":") << geometry + << lit(",\"properties\":") << properties + << lit('}') + ; + + properties = lit('{') + << -(pair % lit(',')) + << lit('}') + ; + + pair = lit('"') + << kstring[_1 = boost::phoenix::at_c<0>(_val)] << lit('"') + << lit(':') + << value(boost::phoenix::at_c<1>(_val)) + ; + + value = (value_null_| bool_ | int__ | double_ | ustring)[_1 = value_base_(_r1)] + ; + + value_null_ = kstring[_1 = "null"] + ; + + ustring = escaped_string_(quote_.c_str())[_1 = utf8_(_val)] + ; +} + +}} diff --git a/include/mapnik/json/feature_grammar.hpp b/include/mapnik/json/feature_grammar.hpp index f90d5f2a2..cfc05db08 100644 --- a/include/mapnik/json/feature_grammar.hpp +++ b/include/mapnik/json/feature_grammar.hpp @@ -82,7 +82,7 @@ struct put_property struct extract_geometry { - using result_type = boost::ptr_vector&; + using result_type = mapnik::geometry_container&; template result_type operator() (T & feature) const { @@ -95,11 +95,11 @@ struct feature_grammar : qi::grammar { - feature_grammar(generic_json & json, mapnik::transcoder const& tr); + feature_grammar(mapnik::transcoder const& tr); // start // generic JSON - generic_json & json_; + generic_json json_; // geoJSON qi::rule feature; // START diff --git a/src/json/feature_grammar.cpp b/include/mapnik/json/feature_grammar_impl.hpp similarity index 91% rename from src/json/feature_grammar.cpp rename to include/mapnik/json/feature_grammar_impl.hpp index 5dbe2f1e0..658ad897a 100644 --- a/src/json/feature_grammar.cpp +++ b/include/mapnik/json/feature_grammar_impl.hpp @@ -30,9 +30,9 @@ namespace mapnik { namespace json { template -feature_grammar::feature_grammar(generic_json & json, mapnik::transcoder const& tr) +feature_grammar::feature_grammar(mapnik::transcoder const& tr) : feature_grammar::base_type(feature,"feature"), - json_(json), + json_(), put_property_(put_property(tr)) { qi::lit_type lit; @@ -134,7 +134,4 @@ feature_grammar::feature_grammar(generic_json & } -template struct mapnik::json::feature_grammar; -template struct mapnik::json::feature_grammar >,mapnik::feature_impl>; - }} diff --git a/include/mapnik/json/feature_parser.hpp b/include/mapnik/json/feature_parser.hpp index 8ed15aa80..2df190bf1 100644 --- a/include/mapnik/json/feature_parser.hpp +++ b/include/mapnik/json/feature_parser.hpp @@ -20,39 +20,30 @@ * *****************************************************************************/ -#ifndef MAPNIK_FEATURE_PARSER_HPP -#define MAPNIK_FEATURE_PARSER_HPP +#ifndef MAPNIK_JSON_FEATURE_PARSER_HPP +#define MAPNIK_JSON_FEATURE_PARSER_HPP // mapnik -#include #include -#include -#include +#include // boost - - -// stl -#include +#include +#include +#include namespace mapnik { namespace json { -template struct feature_grammar; -template struct generic_json; - -template -class MAPNIK_DECL feature_parser : private mapnik::noncopyable +inline bool from_geojson(std::string const& json, mapnik::feature_impl & feature) { - using iterator_type = Iterator; - using feature_type = mapnik::feature_impl; -public: - feature_parser(generic_json & json, mapnik::transcoder const& tr); - ~feature_parser(); - bool parse(iterator_type first, iterator_type last, mapnik::feature_impl & f); -private: - const std::unique_ptr > grammar_; -}; + static const mapnik::transcoder tr("utf8"); + using iterator_type = std::string::const_iterator; + static const mapnik::json::feature_grammar g(tr); + using namespace boost::spirit; + standard_wide::space_type space; + return qi::phrase_parse(json.begin(), json.end(), (g)(boost::phoenix::ref(feature)), space); +} }} -#endif //MAPNIK_FEATURE_PARSER_HPP +#endif // MAPNIK_JSON_FEATURE_PARSER_HPP diff --git a/include/mapnik/json/geojson_generator.hpp b/include/mapnik/json/geojson_generator.hpp deleted file mode 100644 index a799c32f9..000000000 --- a/include/mapnik/json/geojson_generator.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2012 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef MAPNIK_GEOJSON_GENERATOR_HPP -#define MAPNIK_GEOJSON_GENERATOR_HPP - -#include -#include -#include - - -#include -#include - -namespace mapnik { namespace json { - -template struct feature_generator_grammar; -template struct multi_geometry_generator_grammar; - -class MAPNIK_DECL feature_generator : private mapnik::noncopyable -{ - using sink_type = std::back_insert_iterator; -public: - feature_generator(); - ~feature_generator(); - bool generate(std::string & geojson, mapnik::feature_impl const& f); -private: - const std::unique_ptr > grammar_; -}; - -class MAPNIK_DECL geometry_generator : private mapnik::noncopyable -{ - using sink_type = std::back_insert_iterator; -public: - geometry_generator(); - ~geometry_generator(); - bool generate(std::string & geojson, mapnik::geometry_container const& g); -private: - const std::unique_ptr > grammar_; -}; - -}} - -#endif // MAPNIK_GEOJSON_GENERATOR_HPP diff --git a/include/mapnik/json/geometry_generator_grammar.hpp b/include/mapnik/json/geometry_generator_grammar.hpp index 1d4b1392b..6c034d882 100644 --- a/include/mapnik/json/geometry_generator_grammar.hpp +++ b/include/mapnik/json/geometry_generator_grammar.hpp @@ -32,31 +32,16 @@ // boost #include -#include -#include -#include #include -#include #include -#include // for vc++ and android whose c++11 libs lack std::trunct +#include // for vc++ and android whose c++11 libs lack std::trunc //stl #include -namespace boost { namespace spirit { namespace traits { - -// make gcc and darwin toolsets happy. -template <> -struct is_container - : mpl::false_ -{}; - -}}} - namespace mapnik { namespace json { namespace karma = boost::spirit::karma; -namespace phoenix = boost::phoenix; namespace { @@ -149,61 +134,7 @@ template struct geometry_generator_grammar : karma::grammar { - - geometry_generator_grammar() - : geometry_generator_grammar::base_type(coordinates) - { - boost::spirit::karma::uint_type uint_; - boost::spirit::bool_type bool_; - boost::spirit::karma::_val_type _val; - boost::spirit::karma::_1_type _1; - boost::spirit::karma::lit_type lit; - boost::spirit::karma::_a_type _a; - boost::spirit::karma::_r1_type _r1; - boost::spirit::karma::eps_type eps; - boost::spirit::karma::string_type kstring; - - coordinates = point | linestring | polygon - ; - - point = &uint_(mapnik::geometry_type::types::Point)[_1 = _type(_val)] - << point_coord [_1 = _first(_val)] - ; - - linestring = &uint_(mapnik::geometry_type::types::LineString)[_1 = _type(_val)] - << lit('[') - << coords - << lit(']') - ; - - polygon = &uint_(mapnik::geometry_type::types::Polygon)[_1 = _type(_val)] - << lit('[') - << coords2 - << lit("]]") - ; - - point_coord = &uint_ - << lit('[') - << coord_type << lit(',') << coord_type - << lit(']') - ; - - polygon_coord %= ( &uint_(mapnik::SEG_MOVETO) << eps[_r1 += 1] - << kstring[ if_ (_r1 > 1) [_1 = "],["] - .else_[_1 = '[' ]] - | - &uint_(mapnik::SEG_LINETO) - << lit(',')) << lit('[') << coord_type << lit(',') << coord_type << lit(']') - ; - - coords2 %= *polygon_coord(_a) - ; - - coords = point_coord % lit(',') - ; - - } - // rules + geometry_generator_grammar(); karma::rule coordinates; karma::rule point; karma::rule linestring; @@ -212,13 +143,9 @@ struct geometry_generator_grammar : karma::rule, geometry_type const& ()> coords2; karma::rule point_coord; karma::rule polygon_coord; - - // phoenix functions - phoenix::function _type; - phoenix::function _first; - // + boost::phoenix::function _type; + boost::phoenix::function _first; karma::real_generator > coord_type; - }; @@ -227,59 +154,7 @@ struct multi_geometry_generator_grammar : karma::grammar >, geometry_container const& ()> { - - multi_geometry_generator_grammar() - : multi_geometry_generator_grammar::base_type(start) - { - boost::spirit::karma::uint_type uint_; - boost::spirit::bool_type bool_; - boost::spirit::karma::_val_type _val; - boost::spirit::karma::_1_type _1; - boost::spirit::karma::lit_type lit; - boost::spirit::karma::_a_type _a; - boost::spirit::karma::eps_type eps; - boost::spirit::karma::string_type kstring; - - geometry_types.add - (mapnik::geometry_type::types::Point,"\"Point\"") - (mapnik::geometry_type::types::LineString,"\"LineString\"") - (mapnik::geometry_type::types::Polygon,"\"Polygon\"") - (mapnik::geometry_type::types::Point + 3,"\"MultiPoint\"") - (mapnik::geometry_type::types::LineString + 3,"\"MultiLineString\"") - (mapnik::geometry_type::types::Polygon + 3,"\"MultiPolygon\"") - ; - - start %= ( eps(phoenix::at_c<1>(_a))[_a = multi_type_(_val)] - << lit("{\"type\":\"GeometryCollection\",\"geometries\":[") - << geometry_collection << lit("]}") - | - geometry) - ; - - geometry_collection = -(geometry2 % lit(',')) - ; - - geometry = ( &bool_(true)[_1 = not_empty_(_val)] << lit("{\"type\":") - << geometry_types[_1 = phoenix::at_c<0>(_a)][_a = multi_type_(_val)] - << lit(",\"coordinates\":") - << kstring[ phoenix::if_ (phoenix::at_c<0>(_a) > 3) [_1 = '['].else_[_1 = ""]] - << coordinates - << kstring[ phoenix::if_ (phoenix::at_c<0>(_a) > 3) [_1 = ']'].else_[_1 = ""]] - << lit('}')) | lit("null") - ; - - geometry2 = lit("{\"type\":") - << geometry_types[_1 = _a][_a = type_(_val)] - << lit(",\"coordinates\":") - << path - << lit('}') - ; - - coordinates %= path % lit(',') - ; - - } - // rules + multi_geometry_generator_grammar(); karma::rule >, geometry_container const&()> start; karma::rule >, @@ -290,11 +165,9 @@ struct multi_geometry_generator_grammar : geometry_type const&()> geometry2; karma::rule coordinates; geometry_generator_grammar path; - // phoenix - phoenix::function multi_type_; - phoenix::function type_; - phoenix::function not_empty_; - // symbols table + boost::phoenix::function multi_type_; + boost::phoenix::function type_; + boost::phoenix::function not_empty_; karma::symbols geometry_types; }; diff --git a/include/mapnik/json/geometry_generator_grammar_impl.hpp b/include/mapnik/json/geometry_generator_grammar_impl.hpp new file mode 100644 index 000000000..37d2e3da0 --- /dev/null +++ b/include/mapnik/json/geometry_generator_grammar_impl.hpp @@ -0,0 +1,141 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +// mapnik +#include + +// boost +#include +#include +#include + +namespace mapnik { namespace json { + +namespace karma = boost::spirit::karma; + +template +geometry_generator_grammar::geometry_generator_grammar() + : geometry_generator_grammar::base_type(coordinates) +{ + boost::spirit::karma::uint_type uint_; + boost::spirit::bool_type bool_; + boost::spirit::karma::_val_type _val; + boost::spirit::karma::_1_type _1; + boost::spirit::karma::lit_type lit; + boost::spirit::karma::_a_type _a; + boost::spirit::karma::_r1_type _r1; + boost::spirit::karma::eps_type eps; + boost::spirit::karma::string_type kstring; + + coordinates = point | linestring | polygon + ; + + point = &uint_(mapnik::geometry_type::types::Point)[_1 = _type(_val)] + << point_coord [_1 = _first(_val)] + ; + + linestring = &uint_(mapnik::geometry_type::types::LineString)[_1 = _type(_val)] + << lit('[') + << coords + << lit(']') + ; + + polygon = &uint_(mapnik::geometry_type::types::Polygon)[_1 = _type(_val)] + << lit('[') + << coords2 + << lit("]]") + ; + + point_coord = &uint_ + << lit('[') + << coord_type << lit(',') << coord_type + << lit(']') + ; + + polygon_coord %= ( &uint_(mapnik::SEG_MOVETO) << eps[_r1 += 1] + << kstring[ if_ (_r1 > 1) [_1 = "],["] + .else_[_1 = '[' ]] + | + &uint_(mapnik::SEG_LINETO) + << lit(',')) << lit('[') << coord_type << lit(',') << coord_type << lit(']') + ; + + coords2 %= *polygon_coord(_a) + ; + + coords = point_coord % lit(',') + ; +} + +template +multi_geometry_generator_grammar::multi_geometry_generator_grammar() + : multi_geometry_generator_grammar::base_type(start) +{ + boost::spirit::karma::uint_type uint_; + boost::spirit::bool_type bool_; + boost::spirit::karma::_val_type _val; + boost::spirit::karma::_1_type _1; + boost::spirit::karma::lit_type lit; + boost::spirit::karma::_a_type _a; + boost::spirit::karma::eps_type eps; + boost::spirit::karma::string_type kstring; + + geometry_types.add + (mapnik::geometry_type::types::Point,"\"Point\"") + (mapnik::geometry_type::types::LineString,"\"LineString\"") + (mapnik::geometry_type::types::Polygon,"\"Polygon\"") + (mapnik::geometry_type::types::Point + 3,"\"MultiPoint\"") + (mapnik::geometry_type::types::LineString + 3,"\"MultiLineString\"") + (mapnik::geometry_type::types::Polygon + 3,"\"MultiPolygon\"") + ; + + start %= ( eps(boost::phoenix::at_c<1>(_a))[_a = multi_type_(_val)] + << lit("{\"type\":\"GeometryCollection\",\"geometries\":[") + << geometry_collection << lit("]}") + | + geometry) + ; + + geometry_collection = -(geometry2 % lit(',')) + ; + + geometry = ( &bool_(true)[_1 = not_empty_(_val)] << lit("{\"type\":") + << geometry_types[_1 = boost::phoenix::at_c<0>(_a)][_a = multi_type_(_val)] + << lit(",\"coordinates\":") + << kstring[ boost::phoenix::if_ (boost::phoenix::at_c<0>(_a) > 3) [_1 = '['].else_[_1 = ""]] + << coordinates + << kstring[ boost::phoenix::if_ (boost::phoenix::at_c<0>(_a) > 3) [_1 = ']'].else_[_1 = ""]] + << lit('}')) | lit("null") + ; + + geometry2 = lit("{\"type\":") + << geometry_types[_1 = _a][_a = type_(_val)] + << lit(",\"coordinates\":") + << path + << lit('}') + ; + + coordinates %= path % lit(',') + ; +} + +}} diff --git a/include/mapnik/json/geometry_grammar.hpp b/include/mapnik/json/geometry_grammar.hpp index 2c9c41aa8..d6ce09796 100644 --- a/include/mapnik/json/geometry_grammar.hpp +++ b/include/mapnik/json/geometry_grammar.hpp @@ -90,28 +90,28 @@ struct where_message template struct geometry_grammar : - qi::grammar, void(boost::ptr_vector& ) + qi::grammar, void(mapnik::geometry_container& ) , space_type> { geometry_grammar(); - qi::rule, void(boost::ptr_vector& ),space_type> geometry; + qi::rule, void(mapnik::geometry_container& ),space_type> geometry; qi::symbols geometry_dispatch; qi::rule point; qi::rule,void(geometry_type*),space_type> points; - qi::rule&,int),space_type> coordinates; + qi::rule coordinates; // qi::rule, - void(boost::ptr_vector& ),space_type> point_coordinates; + void(mapnik::geometry_container& ),space_type> point_coordinates; qi::rule, - void(boost::ptr_vector& ),space_type> linestring_coordinates; + void(mapnik::geometry_container& ),space_type> linestring_coordinates; qi::rule, - void(boost::ptr_vector& ),space_type> polygon_coordinates; + void(mapnik::geometry_container& ),space_type> polygon_coordinates; - qi::rule& ),space_type> multipoint_coordinates; - qi::rule& ),space_type> multilinestring_coordinates; - qi::rule& ),space_type> multipolygon_coordinates; - qi::rule& ),space_type> geometry_collection; + qi::rule multipoint_coordinates; + qi::rule multilinestring_coordinates; + qi::rule multipolygon_coordinates; + qi::rule geometry_collection; // Nabialek trick ////////////////////////////////////// //using dispatch_rule = typename qi::rule; diff --git a/src/json/geometry_grammar.cpp b/include/mapnik/json/geometry_grammar_impl.hpp similarity index 96% rename from src/json/geometry_grammar.cpp rename to include/mapnik/json/geometry_grammar_impl.hpp index 614858bee..3e704a6dc 100644 --- a/src/json/geometry_grammar.cpp +++ b/include/mapnik/json/geometry_grammar_impl.hpp @@ -158,7 +158,4 @@ geometry_grammar::geometry_grammar() ); } -template struct mapnik::json::geometry_grammar; -template struct mapnik::json::geometry_grammar > >; - }} diff --git a/include/mapnik/json/geometry_parser.hpp b/include/mapnik/json/geometry_parser.hpp index 1d1a9e646..692cd3b01 100644 --- a/include/mapnik/json/geometry_parser.hpp +++ b/include/mapnik/json/geometry_parser.hpp @@ -24,34 +24,26 @@ #define MAPNIK_JSON_GEOMETRY_PARSER_HPP // mapnik -#include #include -#include +#include // boost - - -// stl -//#include +#include +#include +#include namespace mapnik { namespace json { -template struct geometry_grammar; - -MAPNIK_DECL bool from_geojson(std::string const& json, boost::ptr_vector & paths); - -template -class MAPNIK_DECL geometry_parser : private mapnik::noncopyable +inline bool from_geojson(std::string const& json, boost::ptr_vector & paths) { - using iterator_type = Iterator; -public: - geometry_parser(); - ~geometry_parser(); - bool parse(iterator_type first, iterator_type last, boost::ptr_vector&); -private: - const std::unique_ptr > grammar_; -}; + using namespace boost::spirit; + static const geometry_grammar g; + standard_wide::space_type space; + std::string::const_iterator start = json.begin(); + std::string::const_iterator end = json.end(); + return qi::phrase_parse(start, end, (g)(boost::phoenix::ref(paths)), space); +} }} -#endif //MAPNIK_FEATURE_COLLECTION_PARSER_HPP +#endif // MAPNIK_JSON_GEOMETRY_PARSER_HPP diff --git a/include/mapnik/json/symbolizer_grammar.hpp b/include/mapnik/json/symbolizer_grammar.hpp index 5f71a8d6b..76a495775 100644 --- a/include/mapnik/json/symbolizer_grammar.hpp +++ b/include/mapnik/json/symbolizer_grammar.hpp @@ -116,9 +116,9 @@ template struct symbolizer_grammar : qi::grammar { using json_value_type = boost::variant; - symbolizer_grammar(generic_json & json) + symbolizer_grammar() : symbolizer_grammar::base_type(sym, "symbolizer"), - json_(json) + json_() { using qi::lit; using qi::double_; @@ -201,7 +201,7 @@ struct symbolizer_grammar : qi::grammar } // generic JSON - generic_json & json_; + generic_json json_; // symbolizer qi::rule sym; qi::rule, void(mapnik::symbolizer&),space_type> property; diff --git a/src/path_expression_grammar.cpp b/include/mapnik/path_expression_grammar_impl.hpp similarity index 95% rename from src/path_expression_grammar.cpp rename to include/mapnik/path_expression_grammar_impl.hpp index 0a3d92a2d..6b764ed92 100644 --- a/src/path_expression_grammar.cpp +++ b/include/mapnik/path_expression_grammar_impl.hpp @@ -56,6 +56,4 @@ path_expression_grammar::path_expression_grammar() str %= lexeme[+(char_ -'[')]; } -template struct mapnik::path_expression_grammar; - } diff --git a/include/mapnik/util/geometry_svg_generator.hpp b/include/mapnik/svg/geometry_svg_generator.hpp similarity index 74% rename from include/mapnik/util/geometry_svg_generator.hpp rename to include/mapnik/svg/geometry_svg_generator.hpp index ead767e75..6c9800cc6 100644 --- a/include/mapnik/util/geometry_svg_generator.hpp +++ b/include/mapnik/svg/geometry_svg_generator.hpp @@ -20,8 +20,8 @@ * *****************************************************************************/ -#ifndef MAPNIK_GEOMETRY_SVG_GENERATOR_HPP -#define MAPNIK_GEOMETRY_SVG_GENERATOR_HPP +#ifndef MAPNIK_GEOMETRY_SVG_PATH_GENERATOR_HPP +#define MAPNIK_GEOMETRY_SVG_PATH_GENERATOR_HPP // mapnik @@ -83,7 +83,7 @@ struct end_container }}} -namespace mapnik { namespace util { +namespace mapnik { namespace svg { namespace karma = boost::spirit::karma; namespace phoenix = boost::phoenix; @@ -124,52 +124,14 @@ namespace mapnik { namespace util { } template - struct svg_generator : + struct svg_path_generator : karma::grammar { using geometry_type = Geometry; using coord_type = typename boost::remove_pointer::type; - svg_generator() - : svg_generator::base_type(svg) - { - boost::spirit::karma::uint_type uint_; - boost::spirit::karma::_val_type _val; - boost::spirit::karma::_1_type _1; - boost::spirit::karma::lit_type lit; - boost::spirit::karma::_a_type _a; - boost::spirit::karma::string_type kstring; - - svg = point | linestring | polygon - ; - - point = &uint_(mapnik::geometry_type::types::Point)[_1 = _type(_val)] - << svg_point [_1 = _first(_val)] - ; - - svg_point = &uint_ - << lit("cx=\"") << coordinate - << lit("\" cy=\"") << coordinate - << lit('\"') - ; - - linestring = &uint_(mapnik::geometry_type::types::LineString)[_1 = _type(_val)] - << lit("d=\"") << svg_path << lit("\"") - ; - - polygon = &uint_(mapnik::geometry_type::types::Polygon)[_1 = _type(_val)] - << lit("d=\"") << svg_path << lit("\"") - ; - - svg_path %= ((&uint_(mapnik::SEG_MOVETO) << lit('M') - | &uint_(mapnik::SEG_LINETO) [_a +=1] << kstring [if_(_a == 1) [_1 = "L" ].else_[_1 =""]]) - << lit(' ') << coordinate << lit(' ') << coordinate) % lit(' ') - ; - - - - } + svg_path_generator(); // rules karma::rule svg; karma::rule point; @@ -189,4 +151,4 @@ namespace mapnik { namespace util { }} -#endif // MAPNIK_GEOMETRY_SVG_GENERATOR_HPP +#endif // MAPNIK_GEOMETRY_SVG_PATH_GENERATOR_HPP diff --git a/include/mapnik/svg/geometry_svg_generator_impl.hpp b/include/mapnik/svg/geometry_svg_generator_impl.hpp new file mode 100644 index 000000000..a448514c6 --- /dev/null +++ b/include/mapnik/svg/geometry_svg_generator_impl.hpp @@ -0,0 +1,71 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2011 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +// mapnik + +#include + +namespace mapnik { namespace svg { + + namespace karma = boost::spirit::karma; + namespace phoenix = boost::phoenix; + + template + svg_path_generator::svg_path_generator() + : svg_path_generator::base_type(svg) + { + boost::spirit::karma::uint_type uint_; + boost::spirit::karma::_val_type _val; + boost::spirit::karma::_1_type _1; + boost::spirit::karma::lit_type lit; + boost::spirit::karma::_a_type _a; + boost::spirit::karma::string_type kstring; + + svg = point | linestring | polygon + ; + + point = &uint_(mapnik::geometry_type::types::Point)[_1 = _type(_val)] + << svg_point [_1 = _first(_val)] + ; + + svg_point = &uint_ + << lit("cx=\"") << coordinate + << lit("\" cy=\"") << coordinate + << lit('\"') + ; + + linestring = &uint_(mapnik::geometry_type::types::LineString)[_1 = _type(_val)] + << lit("d=\"") << svg_path << lit("\"") + ; + + polygon = &uint_(mapnik::geometry_type::types::Polygon)[_1 = _type(_val)] + << lit("d=\"") << svg_path << lit("\"") + ; + + svg_path %= ((&uint_(mapnik::SEG_MOVETO) << lit('M') + | &uint_(mapnik::SEG_LINETO) [_a +=1] << kstring [if_(_a == 1) [_1 = "L" ].else_[_1 =""]]) + << lit(' ') << coordinate << lit(' ') << coordinate) % lit(' ') + ; + + } + +}} diff --git a/include/mapnik/svg/output/svg_generator.hpp b/include/mapnik/svg/output/svg_generator.hpp index 94b7d1601..ede85f36a 100644 --- a/include/mapnik/svg/output/svg_generator.hpp +++ b/include/mapnik/svg/output/svg_generator.hpp @@ -35,8 +35,7 @@ boost/spirit/repository/home/karma/directive/confix.hpp:49:23: error: no member #include #include #include -#include -#include +#include #include #include #include @@ -53,11 +52,6 @@ namespace mapnik { namespace svg { template class svg_generator : private mapnik::noncopyable { - using root_attributes_grammar = svg::svg_root_attributes_grammar; - using rect_attributes_grammar = svg::svg_rect_attributes_grammar; - using path_attributes_grammar = svg::svg_path_attributes_grammar; - using path_dash_array_grammar = svg::svg_path_dash_array_grammar; - public: explicit svg_generator(OutputIterator& output_iterator); ~svg_generator(); @@ -69,19 +63,6 @@ namespace mapnik { namespace svg { void generate_opening_group(mapnik::value_integer val); void generate_opening_group(std::string const& val); void generate_closing_group(); - template - void generate_path(PathType const& path, path_output_attributes const& path_attributes) - { - karma::lit_type lit; - util::svg_generator svg_path_grammer; - karma::generate(output_iterator_, lit("\n"), path_attributes); - } - - private: OutputIterator& output_iterator_; }; }} diff --git a/include/mapnik/transform_expression.hpp b/include/mapnik/transform_expression.hpp index e67efc380..b94005b20 100644 --- a/include/mapnik/transform_expression.hpp +++ b/include/mapnik/transform_expression.hpp @@ -24,11 +24,14 @@ #define MAPNIK_TRANSFORM_EXPRESSION_HPP // mapnik +#include +#include +#include +#include #include // boost #include -#include #include // fusion @@ -37,6 +40,7 @@ // stl #include +#include namespace mapnik { diff --git a/include/mapnik/transform_expression_grammar.hpp b/include/mapnik/transform_expression_grammar.hpp index ea958b723..220d5126f 100644 --- a/include/mapnik/transform_expression_grammar.hpp +++ b/include/mapnik/transform_expression_grammar.hpp @@ -25,6 +25,7 @@ // mapnik #include +#include #include // spirit diff --git a/src/transform_expression_grammar.cpp b/include/mapnik/transform_expression_grammar_impl.hpp similarity index 98% rename from src/transform_expression_grammar.cpp rename to include/mapnik/transform_expression_grammar_impl.hpp index 97b26aa81..bdf9f174c 100644 --- a/src/transform_expression_grammar.cpp +++ b/include/mapnik/transform_expression_grammar_impl.hpp @@ -22,6 +22,7 @@ // mapnik #include +#include // boost #include @@ -127,6 +128,4 @@ transform_expression_grammar::transform_expression_grammar() expr = g_.expr.alias(); } -template struct mapnik::transform_expression_grammar; - } diff --git a/include/mapnik/transform_processor.hpp b/include/mapnik/transform_processor.hpp index 48ca61a31..a37abacc4 100644 --- a/include/mapnik/transform_processor.hpp +++ b/include/mapnik/transform_processor.hpp @@ -33,7 +33,6 @@ #include // boost - #include #include #include diff --git a/include/mapnik/util/container_adapter.hpp b/include/mapnik/util/container_adapter.hpp index 454efe565..f8c7d901c 100644 --- a/include/mapnik/util/container_adapter.hpp +++ b/include/mapnik/util/container_adapter.hpp @@ -35,6 +35,10 @@ namespace boost { namespace spirit { namespace traits { template <> struct is_container : mpl::true_ {} ; +// make gcc and darwin toolsets happy. +template <> +struct is_container : mpl::false_ {} ; + template <> struct container_iterator { diff --git a/src/json/geojson_generator.cpp b/include/mapnik/util/geometry_to_geojson.hpp similarity index 53% rename from src/json/geojson_generator.cpp rename to include/mapnik/util/geometry_to_geojson.hpp index d1bd97dce..cbdce3d08 100644 --- a/src/json/geojson_generator.cpp +++ b/include/mapnik/util/geometry_to_geojson.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2012 Artem Pavlenko + * Copyright (C) 2011 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,36 +20,31 @@ * *****************************************************************************/ -// boost -#include -#include -#include +#ifndef MAPNIK_GEOMETRY_TO_GEOJSON_HPP +#define MAPNIK_GEOMETRY_TO_GEOJSON_HPP + +// mapnik +#include #include -#include +namespace mapnik { namespace util { -namespace mapnik { namespace json { - -feature_generator::feature_generator() - : grammar_(new feature_generator_grammar()) {} - -feature_generator::~feature_generator() {} - -bool feature_generator::generate(std::string & geojson, mapnik::feature_impl const& f) +inline bool to_geojson(std::string & json, mapnik::geometry_type const& geom) { - sink_type sink(geojson); - return karma::generate(sink, *grammar_,f); + using sink_type = std::back_insert_iterator; + static const mapnik::json::geometry_generator_grammar grammar; + sink_type sink(json); + return boost::spirit::karma::generate(sink, grammar, geom); } -geometry_generator::geometry_generator() - : grammar_(new multi_geometry_generator_grammar()) {} - -geometry_generator::~geometry_generator() {} - -bool geometry_generator::generate(std::string & geojson, mapnik::geometry_container const& g) +inline bool to_geojson(std::string & json, mapnik::geometry_container const& geom) { - sink_type sink(geojson); - return karma::generate(sink, *grammar_,g); + using sink_type = std::back_insert_iterator; + static const mapnik::json::multi_geometry_generator_grammar grammar; + sink_type sink(json); + return boost::spirit::karma::generate(sink, grammar, geom); } }} + +#endif // MAPNIK_GEOMETRY_TO_GEOJSON_HPP diff --git a/include/mapnik/util/geometry_to_svg.hpp b/include/mapnik/util/geometry_to_svg.hpp index 53c6d7f45..e18bc2ce7 100644 --- a/include/mapnik/util/geometry_to_svg.hpp +++ b/include/mapnik/util/geometry_to_svg.hpp @@ -26,7 +26,7 @@ // mapnik #include #include -#include +#include // boost #include @@ -35,11 +35,11 @@ namespace mapnik { namespace util { namespace karma = boost::spirit::karma; -bool to_svg(std::string & svg, mapnik::geometry_type const& geom) +inline bool to_svg(std::string & svg, mapnik::geometry_type const& geom) { using sink_type = std::back_insert_iterator; sink_type sink(svg); - svg_generator generator; + static const svg::svg_path_generator generator; bool result = karma::generate(sink, generator, geom); return result; } diff --git a/include/mapnik/util/geometry_to_wkt.hpp b/include/mapnik/util/geometry_to_wkt.hpp index 5f6ca4bc6..b861c1a33 100644 --- a/include/mapnik/util/geometry_to_wkt.hpp +++ b/include/mapnik/util/geometry_to_wkt.hpp @@ -24,16 +24,27 @@ #define MAPNIK_GEOMETRY_TO_WKT_HPP // mapnik -#include #include +#include namespace mapnik { namespace util { -MAPNIK_DECL bool to_wkt(std::string & wkt, mapnik::geometry_type const& geom); +inline bool to_wkt(std::string & wkt, mapnik::geometry_type const& geom) +{ + using sink_type = std::back_insert_iterator; + sink_type sink(wkt); + static const mapnik::wkt::wkt_generator generator(true); + return boost::spirit::karma::generate(sink, generator, geom); +} -MAPNIK_DECL bool to_wkt(std::string & wkt, mapnik::geometry_container const& geom); +inline bool to_wkt(std::string & wkt, mapnik::geometry_container const& geom) +{ + using sink_type = std::back_insert_iterator; + sink_type sink(wkt); + static const mapnik::wkt::wkt_multi_generator generator; + return boost::spirit::karma::generate(sink, generator, geom); +} }} - #endif // MAPNIK_GEOMETRY_TO_WKT_HPP diff --git a/include/mapnik/wkb.hpp b/include/mapnik/wkb.hpp index 0f440aa57..7474a0182 100644 --- a/include/mapnik/wkb.hpp +++ b/include/mapnik/wkb.hpp @@ -52,7 +52,7 @@ class MAPNIK_DECL geometry_utils : private mapnik::noncopyable { public: - static bool from_wkb (boost::ptr_vector& paths, + static bool from_wkb(mapnik::geometry_container& paths, const char* wkb, unsigned size, wkbFormat format = wkbGeneric); diff --git a/include/mapnik/wkt/wkt_factory.hpp b/include/mapnik/wkt/wkt_factory.hpp index ff88c275e..7fbbaf28d 100644 --- a/include/mapnik/wkt/wkt_factory.hpp +++ b/include/mapnik/wkt/wkt_factory.hpp @@ -24,33 +24,24 @@ #define MAPNIK_WKT_FACTORY_HPP // mapnik -#include #include #include -#include - -// boost -#include // stl #include -#include namespace mapnik { -MAPNIK_DECL bool from_wkt(std::string const& wkt, boost::ptr_vector & paths); - -class MAPNIK_DECL wkt_parser : mapnik::noncopyable +inline bool from_wkt(std::string const& wkt, mapnik::geometry_container & paths) { - using iterator_type = std::string::const_iterator; -public: - wkt_parser(); - bool parse(std::string const& wkt, boost::ptr_vector & paths); -private: - const std::unique_ptr > grammar_; -}; + using namespace boost::spirit; + static const mapnik::wkt::wkt_collection_grammar g; + ascii::space_type space; + std::string::const_iterator first = wkt.begin(); + std::string::const_iterator last = wkt.end(); + return qi::phrase_parse(first, last, g, space, paths); +} } - #endif // MAPNIK_WKT_FACTORY_HPP diff --git a/include/mapnik/util/geometry_wkt_generator.hpp b/include/mapnik/wkt/wkt_generator_grammar.hpp similarity index 96% rename from include/mapnik/util/geometry_wkt_generator.hpp rename to include/mapnik/wkt/wkt_generator_grammar.hpp index afb55935a..9fd285b7f 100644 --- a/include/mapnik/util/geometry_wkt_generator.hpp +++ b/include/mapnik/wkt/wkt_generator_grammar.hpp @@ -27,6 +27,7 @@ #include #include #include // for CommandType::SEG_MOVETO +#include // boost #include @@ -37,22 +38,12 @@ #include #include #include -#include // for vc++ and android whose c++11 libs lack std::trunct +#include // for vc++ and android whose c++11 libs lack std::trunc // stl #include -namespace boost { namespace spirit { namespace traits { - -// make gcc and darwin toolsets happy. -template <> -struct is_container - : mpl::false_ -{}; - -}}} - -namespace mapnik { namespace util { +namespace mapnik { namespace wkt { namespace karma = boost::spirit::karma; namespace phoenix = boost::phoenix; diff --git a/src/wkt/wkt_generator.cpp b/include/mapnik/wkt/wkt_generator_grammar_impl.hpp similarity index 82% rename from src/wkt/wkt_generator.cpp rename to include/mapnik/wkt/wkt_generator_grammar_impl.hpp index ab863f53e..fccdecb60 100644 --- a/src/wkt/wkt_generator.cpp +++ b/include/mapnik/wkt/wkt_generator_grammar_impl.hpp @@ -21,12 +21,11 @@ *****************************************************************************/ #include -#include -#include +#include #include #include -namespace mapnik { namespace util { +namespace mapnik { namespace wkt { template std::tuple detail::multi_geometry_type::operator() (T const& geom) const @@ -145,25 +144,4 @@ wkt_multi_generator::wkt_multi_generator() } -template struct mapnik::util::wkt_generator, mapnik::geometry_type>; -template struct mapnik::util::wkt_multi_generator, mapnik::geometry_container >; - -bool to_wkt(std::string & wkt, mapnik::geometry_type const& geom) -{ - using sink_type = std::back_insert_iterator; - sink_type sink(wkt); - wkt_generator generator(true); - bool result = karma::generate(sink, generator, geom); - return result; -} - -bool to_wkt(std::string & wkt, mapnik::geometry_container const& geom) -{ - using sink_type = std::back_insert_iterator; - sink_type sink(wkt); - wkt_multi_generator generator; - bool result = karma::generate(sink, generator, geom); - return result; -} - }} diff --git a/include/mapnik/wkt/wkt_grammar.hpp b/include/mapnik/wkt/wkt_grammar.hpp index 788fdd2c4..370b83c78 100644 --- a/include/mapnik/wkt/wkt_grammar.hpp +++ b/include/mapnik/wkt/wkt_grammar.hpp @@ -24,16 +24,8 @@ #define MAPNIK_WKT_GRAMMAR_HPP #include -#include -// spirit::qi #include -// spirit::phoenix #include -#include -#include -#include -#include -#include // mapnik #include @@ -41,215 +33,86 @@ namespace mapnik { namespace wkt { - using namespace boost::spirit; - using namespace boost::phoenix; +using namespace boost::spirit; - struct push_vertex - { - template - struct result - { - using type = void; - }; - - template - void operator() (T0 c, T1 path, T2 x, T3 y) const - { - BOOST_ASSERT( path!=0 ); - path->push_vertex(x,y,c); - } - }; - - struct close_path - { - template - struct result - { - using type = void; - }; - - template - void operator() (T path) const - { - BOOST_ASSERT( path!=0 ); - path->close_path(); - } - }; - - struct cleanup - { - template - struct result - { - using type = void; - }; - - template - void operator() (T0 & path) const - { - if (path) delete path,path=0; - } - }; - - template - struct wkt_grammar : qi::grammar() , ascii::space_type> - { - wkt_grammar() - : wkt_grammar::base_type(geometry_tagged_text) - { - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::_pass_type _pass; - qi::eps_type eps; - qi::_val_type _val; - qi::lit_type lit; - qi::no_case_type no_case; - qi::double_type double_; - qi::_1_type _1; - qi::_2_type _2; - qi::_a_type _a; - using boost::phoenix::push_back; - - geometry_tagged_text = point_tagged_text - | linestring_tagged_text - | polygon_tagged_text - | multipoint_tagged_text - | multilinestring_tagged_text - | multipolygon_tagged_text - ; - - // ::= point - point_tagged_text = no_case[lit("POINT")] [ _a = new_(geometry_type::types::Point) ] - >> ( point_text(_a) [push_back(_val,_a)] - | eps[cleanup_(_a)][_pass = false]) - ; - - // ::= | - point_text = (lit("(") >> point(SEG_MOVETO,_r1) >> lit(')')) - | empty_set - ; - - // ::= linestring - linestring_tagged_text = no_case[lit("LINESTRING")] [ _a = new_(geometry_type::types::LineString) ] - >> (linestring_text(_a)[push_back(_val,_a)] - | eps[cleanup_(_a)][_pass = false]) - ; - - // ::= | { }* - linestring_text = points(_r1) | empty_set - ; - - // ::= polygon - polygon_tagged_text = no_case[lit("POLYGON")] [ _a = new_(geometry_type::types::Polygon) ] - >> ( polygon_text(_a)[push_back(_val,_a)] - | eps[cleanup_(_a)][_pass = false]) - ; - - // ::= | { }* - polygon_text = (lit('(') >> linestring_text(_r1)[close_path_(_r1)] % lit(',') >> lit(')')) | empty_set; - - - // ::= multipoint - multipoint_tagged_text = no_case[lit("MULTIPOINT")] - >> multipoint_text - ; - - // ::= | { }* - multipoint_text = (lit('(') - >> ((eps[_a = new_(geometry_type::types::Point)] - >> (point_text(_a) | empty_set) [push_back(_val,_a)] - | eps[cleanup_(_a)][_pass = false]) % lit(',')) - >> lit(')')) | empty_set - ; - - // ::= multilinestring - multilinestring_tagged_text = no_case[lit("MULTILINESTRING")] - >> multilinestring_text ; - - // ::= | { }* - multilinestring_text = (lit('(') - >> ((eps[_a = new_(geometry_type::types::LineString)] - >> ( points(_a)[push_back(_val,_a)] - | eps[cleanup_(_a)][_pass = false])) - % lit(',')) - >> lit(')')) | empty_set; - - // ::= multipolygon - multipolygon_tagged_text = no_case[lit("MULTIPOLYGON")] - >> multipolygon_text ; - - // ::= | { }* - - multipolygon_text = (lit('(') - >> ((eps[_a = new_(geometry_type::types::Polygon)] - >> ( polygon_text(_a)[push_back(_val,_a)] - | eps[cleanup_(_a)][_pass = false])) - % lit(',')) - >> lit(')')) | empty_set; - - // points - points = lit('(')[_a = SEG_MOVETO] >> point (_a,_r1) % lit(',') [_a = SEG_LINETO] >> lit(')'); - // point - point = (double_ >> double_) [push_vertex_(_r1,_r2,_1,_2)]; - - // - empty_set = no_case[lit("EMPTY")]; - - } - - // start - qi::rule(),ascii::space_type> geometry_tagged_text; - - qi::rule,boost::ptr_vector(),ascii::space_type> point_tagged_text; - qi::rule,boost::ptr_vector(),ascii::space_type> linestring_tagged_text; - qi::rule,boost::ptr_vector(),ascii::space_type> polygon_tagged_text; - qi::rule(),ascii::space_type> multipoint_tagged_text; - qi::rule(),ascii::space_type> multilinestring_tagged_text; - qi::rule(),ascii::space_type> multipolygon_tagged_text; - // - qi::rule point_text; - qi::rule linestring_text; - qi::rule polygon_text; - qi::rule, boost::ptr_vector(),ascii::space_type> multipoint_text; - qi::rule, boost::ptr_vector(),ascii::space_type> multilinestring_text; - qi::rule, boost::ptr_vector(),ascii::space_type> multipolygon_text; - // - qi::rule point; - qi::rule,void(geometry_type*),ascii::space_type> points; - qi::rule empty_set; - boost::phoenix::function push_vertex_; - boost::phoenix::function close_path_; - boost::phoenix::function cleanup_; - }; - - -template -struct wkt_collection_grammar : qi::grammar(), ascii::space_type> +struct push_vertex { - wkt_collection_grammar() - : wkt_collection_grammar::base_type(start) + template + struct result { - qi::lit_type lit; - qi::no_case_type no_case; - start = wkt | no_case[lit("GEOMETRYCOLLECTION")] - >> (lit("(") >> wkt % lit(",") >> lit(")")); - } + using type = void; + }; - qi::rule(),ascii::space_type> start; - wkt_grammar wkt; + template + void operator() (T0 c, T1 path, T2 x, T3 y) const + { + BOOST_ASSERT( path!=0 ); + path->push_vertex(x,y,c); + } +}; + +struct close_path +{ + template + struct result + { + using type = void; + }; + + template + void operator() (T path) const + { + BOOST_ASSERT( path!=0 ); + path->close_path(); + } +}; + +struct cleanup +{ + template + struct result + { + using type = void; + }; + + template + void operator() (T0 & path) const + { + if (path) delete path,path=0; + } }; template -struct wkt_stream_grammar : qi::grammar(), ascii::space_type> +struct wkt_grammar : qi::grammar { - wkt_stream_grammar() - : wkt_stream_grammar::base_type(start) - { - start = *wkt_collection; - } + wkt_grammar(); + qi::rule geometry_tagged_text; + qi::rule,mapnik::geometry_container(),ascii::space_type> point_tagged_text; + qi::rule,mapnik::geometry_container(),ascii::space_type> linestring_tagged_text; + qi::rule,mapnik::geometry_container(),ascii::space_type> polygon_tagged_text; + qi::rule multipoint_tagged_text; + qi::rule multilinestring_tagged_text; + qi::rule multipolygon_tagged_text; + qi::rule point_text; + qi::rule linestring_text; + qi::rule polygon_text; + qi::rule, mapnik::geometry_container(),ascii::space_type> multipoint_text; + qi::rule, mapnik::geometry_container(),ascii::space_type> multilinestring_text; + qi::rule, mapnik::geometry_container(),ascii::space_type> multipolygon_text; + qi::rule point; + qi::rule,void(geometry_type*),ascii::space_type> points; + qi::rule empty_set; + boost::phoenix::function push_vertex_; + boost::phoenix::function close_path_; + boost::phoenix::function cleanup_; +}; - qi::rule(),ascii::space_type> start; - wkt_collection_grammar wkt_collection; +template +struct wkt_collection_grammar : qi::grammar +{ + wkt_collection_grammar(); + qi::rule start; + wkt_grammar wkt; }; }} diff --git a/include/mapnik/wkt/wkt_grammar_impl.hpp b/include/mapnik/wkt/wkt_grammar_impl.hpp new file mode 100644 index 000000000..1b266b814 --- /dev/null +++ b/include/mapnik/wkt/wkt_grammar_impl.hpp @@ -0,0 +1,149 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2011 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +namespace mapnik { namespace wkt { + +using namespace boost::spirit; + +template +wkt_grammar::wkt_grammar() + : wkt_grammar::base_type(geometry_tagged_text) +{ + qi::_r1_type _r1; + qi::_r2_type _r2; + qi::_pass_type _pass; + qi::eps_type eps; + qi::_val_type _val; + qi::lit_type lit; + qi::no_case_type no_case; + qi::double_type double_; + qi::_1_type _1; + qi::_2_type _2; + qi::_a_type _a; + using boost::phoenix::push_back; + using boost::phoenix::new_; + + geometry_tagged_text = point_tagged_text + | linestring_tagged_text + | polygon_tagged_text + | multipoint_tagged_text + | multilinestring_tagged_text + | multipolygon_tagged_text + ; + + // ::= point + point_tagged_text = no_case[lit("POINT")] [ _a = new_(geometry_type::types::Point) ] + >> ( point_text(_a) [push_back(_val,_a)] + | eps[cleanup_(_a)][_pass = false]) + ; + + // ::= | + point_text = (lit("(") >> point(SEG_MOVETO,_r1) >> lit(')')) + | empty_set + ; + + // ::= linestring + linestring_tagged_text = no_case[lit("LINESTRING")] [ _a = new_(geometry_type::types::LineString) ] + >> (linestring_text(_a)[push_back(_val,_a)] + | eps[cleanup_(_a)][_pass = false]) + ; + + // ::= | { }* + linestring_text = points(_r1) | empty_set + ; + + // ::= polygon + polygon_tagged_text = no_case[lit("POLYGON")] [ _a = new_(geometry_type::types::Polygon) ] + >> ( polygon_text(_a)[push_back(_val,_a)] + | eps[cleanup_(_a)][_pass = false]) + ; + + // ::= | { }* + polygon_text = (lit('(') >> linestring_text(_r1)[close_path_(_r1)] % lit(',') >> lit(')')) | empty_set; + + + // ::= multipoint + multipoint_tagged_text = no_case[lit("MULTIPOINT")] + >> multipoint_text + ; + + // ::= | { }* + multipoint_text = (lit('(') + >> ((eps[_a = new_(geometry_type::types::Point)] + >> (point_text(_a) | empty_set) [push_back(_val,_a)] + | eps[cleanup_(_a)][_pass = false]) % lit(',')) + >> lit(')')) | empty_set + ; + + // ::= multilinestring + multilinestring_tagged_text = no_case[lit("MULTILINESTRING")] + >> multilinestring_text ; + + // ::= | { }* + multilinestring_text = (lit('(') + >> ((eps[_a = new_(geometry_type::types::LineString)] + >> ( points(_a)[push_back(_val,_a)] + | eps[cleanup_(_a)][_pass = false])) + % lit(',')) + >> lit(')')) | empty_set; + + // ::= multipolygon + multipolygon_tagged_text = no_case[lit("MULTIPOLYGON")] + >> multipolygon_text ; + + // ::= | { }* + + multipolygon_text = (lit('(') + >> ((eps[_a = new_(geometry_type::types::Polygon)] + >> ( polygon_text(_a)[push_back(_val,_a)] + | eps[cleanup_(_a)][_pass = false])) + % lit(',')) + >> lit(')')) | empty_set; + + // points + points = lit('(')[_a = SEG_MOVETO] >> point (_a,_r1) % lit(',') [_a = SEG_LINETO] >> lit(')'); + // point + point = (double_ >> double_) [push_vertex_(_r1,_r2,_1,_2)]; + + // + empty_set = no_case[lit("EMPTY")]; + +} + +template +wkt_collection_grammar::wkt_collection_grammar() + : wkt_collection_grammar::base_type(start) +{ + qi::lit_type lit; + qi::no_case_type no_case; + start = wkt | no_case[lit("GEOMETRYCOLLECTION")] + >> (lit("(") >> wkt % lit(",") >> lit(")")); +} + +}} diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index f47398269..3911628c1 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -42,6 +42,8 @@ #include #include #include +#include +#include // stl #include diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index ecac3ba75..09124255e 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -47,8 +47,11 @@ #include #include #include -#include -#include +#include +#include +#include +#include +#include using mapnik::datasource; using mapnik::parameters; @@ -100,7 +103,6 @@ geojson_datasource::geojson_datasource(parameters const& params) *params.get("encoding","utf-8")), file_(*params.get("file","")), extent_(), - tr_(new mapnik::transcoder(*params.get("encoding","utf-8"))), features_(), tree_(16,1) { @@ -131,11 +133,10 @@ geojson_datasource::geojson_datasource(parameters const& params) boost::spirit::make_default_multi_pass(base_iterator_type()); mapnik::context_ptr ctx = std::make_shared(); - mapnik::json::generic_json > json; - // TODO - make it possible for this to be static const - // by avoiding ctor taking arg - https://github.com/mapnik/mapnik/pull/2231 - mapnik::json::feature_collection_parser > p(json, ctx,*tr_); - bool result = p.parse(begin,end, features_); + static const mapnik::transcoder tr("utf8"); + static const mapnik::json::feature_collection_grammar,mapnik::feature_impl> fc_grammar(ctx, tr); + boost::spirit::standard_wide::space_type space; + bool result = boost::spirit::qi::phrase_parse(begin, end, fc_grammar, space, features_); if (!result) { throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file '" + file_ + "'"); diff --git a/plugins/input/geojson/geojson_datasource.hpp b/plugins/input/geojson/geojson_datasource.hpp index 5ba23a74f..40571f2ef 100644 --- a/plugins/input/geojson/geojson_datasource.hpp +++ b/plugins/input/geojson/geojson_datasource.hpp @@ -71,7 +71,6 @@ private: mapnik::layer_descriptor desc_; std::string file_; mapnik::box2d extent_; - std::shared_ptr tr_; std::vector features_; spatial_index_type tree_; }; diff --git a/plugins/input/topojson/build.py b/plugins/input/topojson/build.py index dc34465fb..e131e1087 100644 --- a/plugins/input/topojson/build.py +++ b/plugins/input/topojson/build.py @@ -31,7 +31,6 @@ plugin_sources = Split( """ %(PLUGIN_NAME)s_datasource.cpp %(PLUGIN_NAME)s_featureset.cpp - %(PLUGIN_NAME)s_grammar.cpp """ % locals() ) diff --git a/plugins/input/topojson/topojson_datasource.cpp b/plugins/input/topojson/topojson_datasource.cpp index a387fd4a4..e38322ad8 100644 --- a/plugins/input/topojson/topojson_datasource.cpp +++ b/plugins/input/topojson/topojson_datasource.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include using mapnik::datasource; diff --git a/plugins/input/topojson/topojson_grammar.cpp b/plugins/input/topojson/topojson_grammar.cpp deleted file mode 100644 index 91655b0b9..000000000 --- a/plugins/input/topojson/topojson_grammar.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2013 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// mapnik -#include -// stl -#include -// boost -#include - -namespace mapnik { namespace topojson { - -//template struct topojson_grammar; -template struct topojson_grammar > >; - -}} diff --git a/src/build.py b/src/build.py index 94af4eecb..14d674f20 100644 --- a/src/build.py +++ b/src/build.py @@ -154,17 +154,14 @@ source = Split( css_color_grammar.cpp conversions.cpp image_compositing.cpp - image_filter_grammar.cpp image_scaling.cpp box2d.cpp datasource_cache.cpp datasource_cache_static.cpp debug.cpp expression_node.cpp - expression_grammar.cpp expression_string.cpp expression.cpp - transform_expression_grammar.cpp transform_expression.cpp feature_kv_iterator.cpp feature_style_processor.cpp @@ -183,7 +180,6 @@ source = Split( parse_path.cpp parse_transform.cpp palette.cpp - path_expression_grammar.cpp plugin.cpp rule.cpp save_map.cpp @@ -198,8 +194,6 @@ source = Split( symbolizer_enumerations.cpp unicode.cpp raster_colorizer.cpp - wkt/wkt_factory.cpp - wkt/wkt_generator.cpp mapped_memory_cache.cpp marker_cache.cpp svg/svg_parser.cpp @@ -207,12 +201,6 @@ source = Split( svg/svg_points_parser.cpp svg/svg_transform_parser.cpp warp.cpp - json/geometry_grammar.cpp - json/geometry_parser.cpp - json/feature_grammar.cpp - json/feature_parser.cpp - json/feature_collection_parser.cpp - json/geojson_generator.cpp text/vertex_cache.cpp text/layout.cpp text/text_line.cpp diff --git a/src/css_color_grammar.cpp b/src/css_color_grammar.cpp index 55234c0e3..134592ea5 100644 --- a/src/css_color_grammar.cpp +++ b/src/css_color_grammar.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 Artem Pavlenko + * Copyright (C) 2014 Artem Pavlenko, Jean-Francois Doyon * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,164 +20,12 @@ * *****************************************************************************/ +// NOTE: we define this here in a cpp because def is needed twice: +// once by src/color_factory.cpp and once by include/mapnik/image_filter_grammar.hpp +// otherwise it would make sense to simply do `#include ` +// in a single file +#include #include - -namespace mapnik -{ - -named_colors_::named_colors_() -{ - add - ("aliceblue", color(240, 248, 255)) - ("antiquewhite", color(250, 235, 215)) - ("aqua", color(0, 255, 255)) - ("aquamarine", color(127, 255, 212)) - ("azure", color(240, 255, 255)) - ("beige", color(245, 245, 220)) - ("bisque", color(255, 228, 196)) - ("black", color(0, 0, 0)) - ("blanchedalmond", color(255,235,205)) - ("blue", color(0, 0, 255)) - ("blueviolet", color(138, 43, 226)) - ("brown", color(165, 42, 42)) - ("burlywood", color(222, 184, 135)) - ("cadetblue", color(95, 158, 160)) - ("chartreuse", color(127, 255, 0)) - ("chocolate", color(210, 105, 30)) - ("coral", color(255, 127, 80)) - ("cornflowerblue", color(100, 149, 237)) - ("cornsilk", color(255, 248, 220)) - ("crimson", color(220, 20, 60)) - ("cyan", color(0, 255, 255)) - ("darkblue", color(0, 0, 139)) - ("darkcyan", color(0, 139, 139)) - ("darkgoldenrod", color(184, 134, 11)) - ("darkgray", color(169, 169, 169)) - ("darkgreen", color(0, 100, 0)) - ("darkgrey", color(169, 169, 169)) - ("darkkhaki", color(189, 183, 107)) - ("darkmagenta", color(139, 0, 139)) - ("darkolivegreen", color(85, 107, 47)) - ("darkorange", color(255, 140, 0)) - ("darkorchid", color(153, 50, 204)) - ("darkred", color(139, 0, 0)) - ("darksalmon", color(233, 150, 122)) - ("darkseagreen", color(143, 188, 143)) - ("darkslateblue", color(72, 61, 139)) - ("darkslategrey", color(47, 79, 79)) - ("darkturquoise", color(0, 206, 209)) - ("darkviolet", color(148, 0, 211)) - ("deeppink", color(255, 20, 147)) - ("deepskyblue", color(0, 191, 255)) - ("dimgray", color(105, 105, 105)) - ("dimgrey", color(105, 105, 105)) - ("dodgerblue", color(30, 144, 255)) - ("firebrick", color(178, 34, 34)) - ("floralwhite", color(255, 250, 240)) - ("forestgreen", color(34, 139, 34)) - ("fuchsia", color(255, 0, 255)) - ("gainsboro", color(220, 220, 220)) - ("ghostwhite", color(248, 248, 255)) - ("gold", color(255, 215, 0)) - ("goldenrod", color(218, 165, 32)) - ("gray", color(128, 128, 128)) - ("grey", color(128, 128, 128)) - ("green", color(0, 128, 0)) - ("greenyellow", color(173, 255, 47)) - ("honeydew", color(240, 255, 240)) - ("hotpink", color(255, 105, 180)) - ("indianred", color(205, 92, 92)) - ("indigo", color(75, 0, 130)) - ("ivory", color(255, 255, 240)) - ("khaki", color(240, 230, 140)) - ("lavender", color(230, 230, 250)) - ("lavenderblush", color(255, 240, 245)) - ("lawngreen", color(124, 252, 0)) - ("lemonchiffon", color(255, 250, 205)) - ("lightblue", color(173, 216, 230)) - ("lightcoral", color(240, 128, 128)) - ("lightcyan", color(224, 255, 255)) - ("lightgoldenrodyellow", color(250, 250, 210)) - ("lightgray", color(211, 211, 211)) - ("lightgreen", color(144, 238, 144)) - ("lightgrey", color(211, 211, 211)) - ("lightpink", color(255, 182, 193)) - ("lightsalmon", color(255, 160, 122)) - ("lightseagreen", color(32, 178, 170)) - ("lightskyblue", color(135, 206, 250)) - ("lightslategray", color(119, 136, 153)) - ("lightslategrey", color(119, 136, 153)) - ("lightsteelblue", color(176, 196, 222)) - ("lightyellow", color(255, 255, 224)) - ("lime", color(0, 255, 0)) - ("limegreen", color(50, 205, 50)) - ("linen", color(250, 240, 230)) - ("magenta", color(255, 0, 255)) - ("maroon", color(128, 0, 0)) - ("mediumaquamarine", color(102, 205, 170)) - ("mediumblue", color(0, 0, 205)) - ("mediumorchid", color(186, 85, 211)) - ("mediumpurple", color(147, 112, 219)) - ("mediumseagreen", color(60, 179, 113)) - ("mediumslateblue", color(123, 104, 238)) - ("mediumspringgreen", color(0, 250, 154)) - ("mediumturquoise", color(72, 209, 204)) - ("mediumvioletred", color(199, 21, 133)) - ("midnightblue", color(25, 25, 112)) - ("mintcream", color(245, 255, 250)) - ("mistyrose", color(255, 228, 225)) - ("moccasin", color(255, 228, 181)) - ("navajowhite", color(255, 222, 173)) - ("navy", color(0, 0, 128)) - ("oldlace", color(253, 245, 230)) - ("olive", color(128, 128, 0)) - ("olivedrab", color(107, 142, 35)) - ("orange", color(255, 165, 0)) - ("orangered", color(255, 69, 0)) - ("orchid", color(218, 112, 214)) - ("palegoldenrod", color(238, 232, 170)) - ("palegreen", color(152, 251, 152)) - ("paleturquoise", color(175, 238, 238)) - ("palevioletred", color(219, 112, 147)) - ("papayawhip", color(255, 239, 213)) - ("peachpuff", color(255, 218, 185)) - ("peru", color(205, 133, 63)) - ("pink", color(255, 192, 203)) - ("plum", color(221, 160, 221)) - ("powderblue", color(176, 224, 230)) - ("purple", color(128, 0, 128)) - ("red", color(255, 0, 0)) - ("rosybrown", color(188, 143, 143)) - ("royalblue", color(65, 105, 225)) - ("saddlebrown", color(139, 69, 19)) - ("salmon", color(250, 128, 114)) - ("sandybrown", color(244, 164, 96)) - ("seagreen", color(46, 139, 87)) - ("seashell", color(255, 245, 238)) - ("sienna", color(160, 82, 45)) - ("silver", color(192, 192, 192)) - ("skyblue", color(135, 206, 235)) - ("slateblue", color(106, 90, 205)) - ("slategray", color(112, 128, 144)) - ("slategrey", color(112, 128, 144)) - ("snow", color(255, 250, 250)) - ("springgreen", color(0, 255, 127)) - ("steelblue", color(70, 130, 180)) - ("tan", color(210, 180, 140)) - ("teal", color(0, 128, 128)) - ("thistle", color(216, 191, 216)) - ("tomato", color(255, 99, 71)) - ("turquoise", color(64, 224, 208)) - ("violet", color(238, 130, 238)) - ("wheat", color(245, 222, 179)) - ("white", color(255, 255, 255)) - ("whitesmoke", color(245, 245, 245)) - ("yellow", color(255, 255, 0)) - ("yellowgreen", color(154, 205, 50)) - ("transparent", color(0, 0, 0, 0)) - ; -} +#include template struct mapnik::css_color_grammar; - -} diff --git a/src/expression.cpp b/src/expression.cpp index d56c338c9..957e62703 100644 --- a/src/expression.cpp +++ b/src/expression.cpp @@ -26,6 +26,7 @@ #include #include #include +#include // boost #include diff --git a/src/image_filter_types.cpp b/src/image_filter_types.cpp index eb53b1661..fb841ed64 100644 --- a/src/image_filter_types.cpp +++ b/src/image_filter_types.cpp @@ -21,7 +21,8 @@ *****************************************************************************/ // mapnik #include -#include // image_filter_grammar +#include +#include // boost #include diff --git a/src/json/feature_collection_parser.cpp b/src/json/feature_collection_parser.cpp deleted file mode 100644 index c89e6b6bc..000000000 --- a/src/json/feature_collection_parser.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2012 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// mapnik -#include -#include - -// boost -#include -#include - -// stl -#include - -namespace mapnik { namespace json { - - template - feature_collection_parser::feature_collection_parser(generic_json & json, - mapnik::context_ptr const& ctx, - mapnik::transcoder const& tr) - : grammar_(new feature_collection_grammar(json, ctx,tr)) {} - - template - feature_collection_parser::~feature_collection_parser() {} - - template - bool feature_collection_parser::parse(iterator_type first, iterator_type last, std::vector & features) - { - using namespace boost::spirit; - standard_wide::space_type space; - return qi::phrase_parse(first, last, *grammar_, space, features); - } - - template class feature_collection_parser ; - template class feature_collection_parser > >; - -}} diff --git a/src/json/feature_parser.cpp b/src/json/feature_parser.cpp deleted file mode 100644 index 310b23299..000000000 --- a/src/json/feature_parser.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2013 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// mapnik -#include -#include - -// boost -#include -#include - -namespace mapnik { namespace json { - - template - feature_parser::feature_parser(generic_json & json, mapnik::transcoder const& tr) - : grammar_(new feature_grammar(json, tr)) {} - - template - feature_parser::~feature_parser() {} - - template - bool feature_parser::parse(iterator_type first, iterator_type last, mapnik::feature_impl & f) - { - using namespace boost::spirit; - standard_wide::space_type space; - return qi::phrase_parse(first, last, (*grammar_)(boost::phoenix::ref(f)), space); - } - -template class feature_parser; - -}} diff --git a/src/json/geometry_parser.cpp b/src/json/geometry_parser.cpp deleted file mode 100644 index 68ae65d8c..000000000 --- a/src/json/geometry_parser.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2012 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// mapnik -#include -#include - -// boost -#include -#include -#include - -// stl -#include - -namespace mapnik { namespace json { - -template -geometry_parser::geometry_parser() - : grammar_(new geometry_grammar()) {} - -template -geometry_parser::~geometry_parser() {} - -template -bool geometry_parser::parse(iterator_type first, iterator_type last, boost::ptr_vector& paths) -{ - using namespace boost::spirit; - standard_wide::space_type space; - return qi::phrase_parse(first, last, (*grammar_)(boost::phoenix::ref(paths)), space); -} - -bool from_geojson(std::string const& json, boost::ptr_vector & paths) -{ - using namespace boost::spirit; - static const geometry_grammar g; - standard_wide::space_type space; - std::string::const_iterator start = json.begin(); - std::string::const_iterator end = json.end(); - return qi::phrase_parse(start, end, (g)(boost::phoenix::ref(paths)), space); -} - -template class geometry_parser ; -template class geometry_parser > >; - -}} diff --git a/src/parse_path.cpp b/src/parse_path.cpp index 9e2ce39f0..f12889bb5 100644 --- a/src/parse_path.cpp +++ b/src/parse_path.cpp @@ -22,7 +22,7 @@ #include #include - +#include #include #include #include diff --git a/src/parse_transform.cpp b/src/parse_transform.cpp index df377b279..3b2247fb3 100644 --- a/src/parse_transform.cpp +++ b/src/parse_transform.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include // stl #include diff --git a/src/svg/output/process_symbolizers.cpp b/src/svg/output/process_symbolizers.cpp index c87b2d480..f6baaeabe 100644 --- a/src/svg/output/process_symbolizers.cpp +++ b/src/svg/output/process_symbolizers.cpp @@ -25,6 +25,10 @@ // mapnik #include #include +#include +#include +#include +#include namespace mapnik { @@ -50,6 +54,20 @@ bool is_path_based(symbolizer const& sym) return boost::apply_visitor(symbol_type_dispatch(), sym); } +template +void generate_path(OutputIterator & output_iterator, PathType const& path, svg::path_output_attributes const& path_attributes) +{ + using path_dash_array_grammar = svg::svg_path_dash_array_grammar; + using path_attributes_grammar = svg::svg_path_attributes_grammar; + static const path_attributes_grammar attributes_grammar; + static const path_dash_array_grammar dash_array_grammar; + static const svg::svg_path_generator svg_path_grammer; + boost::spirit::karma::lit_type lit; + boost::spirit::karma::generate(output_iterator, lit("\n"), path_attributes); +} + template bool svg_renderer::process(rule::symbolizers const& syms, mapnik::feature_impl & feature, @@ -79,7 +97,7 @@ bool svg_renderer::process(rule::symbolizers const& syms, if(geom.size() > 0) { path_type path(common_.t_, geom, prj_trans); - generator_.generate_path(path, path_attributes_); + generate_path(generator_.output_iterator_, path, path_attributes_); } } // set the previously collected values back to their defaults diff --git a/src/svg/output/svg_generator.cpp b/src/svg/output/svg_generator.cpp index f25f56a75..422a9368a 100644 --- a/src/svg/output/svg_generator.cpp +++ b/src/svg/output/svg_generator.cpp @@ -26,6 +26,7 @@ #include #include #include +#include // boost #include @@ -52,7 +53,8 @@ namespace mapnik { namespace svg { template void svg_generator::generate_opening_root(root_output_attributes const& root_attributes) { - root_attributes_grammar attributes_grammar; + using root_attributes_grammar = svg::svg_root_attributes_grammar; + static const root_attributes_grammar attributes_grammar; karma::lit_type lit; karma::generate(output_iterator_, lit("\n"), root_attributes); } @@ -67,7 +69,8 @@ namespace mapnik { namespace svg { template void svg_generator::generate_rect(rect_output_attributes const& rect_attributes) { - rect_attributes_grammar attributes_grammar; + using rect_attributes_grammar = svg::svg_rect_attributes_grammar; + static const rect_attributes_grammar attributes_grammar; karma::lit_type lit; karma::generate(output_iterator_, lit("\n"), rect_attributes); } diff --git a/src/transform_expression.cpp b/src/transform_expression.cpp index 0bf3b8ec2..f235255d4 100644 --- a/src/transform_expression.cpp +++ b/src/transform_expression.cpp @@ -24,9 +24,6 @@ #include #include -// boost - - // stl #include diff --git a/src/wkt/wkt_factory.cpp b/src/wkt/wkt_factory.cpp deleted file mode 100644 index f4963a5ec..000000000 --- a/src/wkt/wkt_factory.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2011 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// mapnik -#include -#include - -// stl -#include -#include -#include - -namespace mapnik -{ - -wkt_parser::wkt_parser() - : grammar_(new mapnik::wkt::wkt_collection_grammar) -{} - -bool wkt_parser::parse(std::string const& wkt, boost::ptr_vector & paths) -{ - using namespace boost::spirit; - ascii::space_type space; - iterator_type first = wkt.begin(); - iterator_type last = wkt.end(); - return qi::phrase_parse(first, last, *grammar_, space, paths); -} - -bool from_wkt(std::string const& wkt, boost::ptr_vector & paths) -{ - using namespace boost::spirit; - static const mapnik::wkt::wkt_collection_grammar g; - ascii::space_type space; - std::string::const_iterator first = wkt.begin(); - std::string::const_iterator last = wkt.end(); - return qi::phrase_parse(first, last, g, space, paths); -} - -} - diff --git a/tests/cpp_tests/geometry_converters_test.cpp b/tests/cpp_tests/geometry_converters_test.cpp index 03eaabdbe..7eef0f5b1 100644 --- a/tests/cpp_tests/geometry_converters_test.cpp +++ b/tests/cpp_tests/geometry_converters_test.cpp @@ -13,10 +13,10 @@ #include #include #include +#include #include -#include -#include -#include +#include +#include #include #include @@ -25,7 +25,7 @@ struct output_geometry_backend { - output_geometry_backend(boost::ptr_vector & paths, mapnik::geometry_type::types type) + output_geometry_backend(mapnik::geometry_container & paths, mapnik::geometry_type::types type) : paths_(paths), type_(type) {} @@ -43,7 +43,7 @@ struct output_geometry_backend } paths_.push_back(geom_ptr.release()); } - boost::ptr_vector & paths_; + mapnik::geometry_container & paths_; mapnik::geometry_type::types type_; }; @@ -57,7 +57,7 @@ boost::optional linestring_bbox_clipping(mapnik::box2d bbox proj_transform prj_trans(src,dst); line_symbolizer sym; CoordTransform t(bbox.width(),bbox.height(), bbox); - boost::ptr_vector output_paths; + mapnik::geometry_container output_paths; output_geometry_backend backend(output_paths, mapnik::geometry_type::types::LineString); using conv_types = boost::mpl::vector; @@ -69,7 +69,7 @@ boost::optional linestring_bbox_clipping(mapnik::box2d bbox converter.set(); - boost::ptr_vector p; + mapnik::geometry_container p; if (!mapnik::from_wkt(wkt_in , p)) { throw std::runtime_error("Failed to parse WKT"); @@ -80,12 +80,14 @@ boost::optional linestring_bbox_clipping(mapnik::box2d bbox converter.apply(geom); } - std::string wkt_out; - if (mapnik::util::to_wkt(wkt_out, output_paths)) + using sink_type = std::back_insert_iterator; + std::string wkt; // Use Python String directly ? + sink_type sink(wkt); + static const mapnik::wkt::wkt_multi_generator generator; + if (boost::spirit::karma::generate(sink, generator, output_paths)) { - return boost::optional(wkt_out); + return boost::optional(wkt); } - return boost::optional(); } @@ -99,7 +101,7 @@ boost::optional polygon_bbox_clipping(mapnik::box2d bbox, proj_transform prj_trans(src,dst); polygon_symbolizer sym; CoordTransform t(bbox.width(),bbox.height(), bbox); - boost::ptr_vector output_paths; + mapnik::geometry_container output_paths; output_geometry_backend backend(output_paths, mapnik::geometry_type::types::Polygon); using conv_types = boost::mpl::vector; @@ -111,7 +113,7 @@ boost::optional polygon_bbox_clipping(mapnik::box2d bbox, converter.set(); - boost::ptr_vector p; + mapnik::geometry_container p; if (!mapnik::from_wkt(wkt_in , p)) { throw std::runtime_error("Failed to parse WKT"); @@ -122,10 +124,13 @@ boost::optional polygon_bbox_clipping(mapnik::box2d bbox, converter.apply(geom); } - std::string wkt_out; - if (mapnik::util::to_wkt(wkt_out, output_paths)) + using sink_type = std::back_insert_iterator; + std::string wkt; // Use Python String directly ? + sink_type sink(wkt); + static const mapnik::wkt::wkt_multi_generator generator; + if (boost::spirit::karma::generate(sink, generator, output_paths)) { - return boost::optional(wkt_out); + return boost::optional(wkt); } return boost::optional(); diff --git a/tests/python_tests/geometry_io_test.py b/tests/python_tests/geometry_io_test.py index 3cecc88d4..e56b647b4 100644 --- a/tests/python_tests/geometry_io_test.py +++ b/tests/python_tests/geometry_io_test.py @@ -122,15 +122,10 @@ def test_geojson_parsing(): pass eq_(count,len(path)) -reader = mapnik.WKTReader() def compare_wkb_from_wkt(wkt,num=None): - # create a Path from geometry(s) - # easy api, but slower - #paths = mapnik.Path.from_wkt(wkt) - # fast api - paths = reader.read(wkt); + paths = mapnik.Path.from_wkt(wkt) # add geometry(s) to feature from wkt f = mapnik.Feature(mapnik.Context(),1) @@ -160,11 +155,7 @@ def compare_wkb_from_wkt(wkt,num=None): eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR)) def compare_wkt_from_wkt(wkt,num=None): - # create a Path from geometry(s) - # easy api, but slower - #paths = mapnik.Path.from_wkt(wkt) - # fast api - paths = reader.read(wkt); + paths = mapnik.Path.from_wkt(wkt) # add geometry(s) to feature from wkt f = mapnik.Feature(mapnik.Context(),1) @@ -197,7 +188,7 @@ def compare_wkt_from_wkt(wkt,num=None): eq_(f.geometries()[idx].to_wkb(mapnik.wkbByteOrder.XDR),path.to_wkb(mapnik.wkbByteOrder.XDR)) def compare_wkt_to_geojson(idx,wkt,num=None): - paths = reader.read(wkt); + paths = mapnik.Path.from_wkt(wkt) # ensure both have same result if num: eq_(len(paths),num) @@ -233,10 +224,7 @@ def test_wkt_to_geojson(): @raises(IndexError) def test_geometry_index_error(): wkt = 'Point (0 0)' - # easy api, but slower - #paths = mapnik.Path.from_wkt(wkt) - # fast api - paths = reader.read(wkt); + paths = mapnik.Path.from_wkt(wkt) paths[3] f = mapnik.Feature(mapnik.Context(),1) f.add_geometries_from_wkt(wkt) From 8dd47cd204fa602c8ca125685fcf49cc0af5972a Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Jul 2014 15:46:18 -0700 Subject: [PATCH 3/6] add missing files that instanciate grammars for python bindings --- bindings/python/mapnik_generator_grammars.cpp | 36 +++++++++++++++++++ bindings/python/mapnik_parser_grammars.cpp | 32 +++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 bindings/python/mapnik_generator_grammars.cpp create mode 100644 bindings/python/mapnik_parser_grammars.cpp diff --git a/bindings/python/mapnik_generator_grammars.cpp b/bindings/python/mapnik_generator_grammars.cpp new file mode 100644 index 000000000..e621628ac --- /dev/null +++ b/bindings/python/mapnik_generator_grammars.cpp @@ -0,0 +1,36 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 Artem Pavlenko, Jean-Francois Doyon + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +using sink_type = std::back_insert_iterator; +template struct mapnik::json::feature_generator_grammar; +template struct mapnik::json::geometry_generator_grammar; +template struct mapnik::json::multi_geometry_generator_grammar; +template struct mapnik::svg::svg_path_generator; +template struct mapnik::wkt::wkt_generator; +template struct mapnik::wkt::wkt_multi_generator; diff --git a/bindings/python/mapnik_parser_grammars.cpp b/bindings/python/mapnik_parser_grammars.cpp new file mode 100644 index 000000000..b2420f04a --- /dev/null +++ b/bindings/python/mapnik_parser_grammars.cpp @@ -0,0 +1,32 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 Artem Pavlenko, Jean-Francois Doyon + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include +#include +#include +#include +#include + +using iterator_type = std::string::const_iterator; +template struct mapnik::wkt::wkt_collection_grammar; +template struct mapnik::json::feature_grammar; +template struct mapnik::json::geometry_grammar; \ No newline at end of file From a10d69c1d8d530baa4dd2b0f50bab972d877f5d6 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Jul 2014 15:46:51 -0700 Subject: [PATCH 4/6] try 4 cores --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 83b34f6eb..a08165575 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ before_install: install: - if [[ "${CXX}" == 'g++' ]]; then export CXX="g++-4.8" && export CC="gcc-4.8"; fi; - ./configure CXX="${CXX}" CC="${CC}" DEMO=True BENCHMARK=True CPP_TESTS=True CAIRO=True FAST=True - - JOBS=2 make + - JOBS=4 make before_script: - make test From e374ac70aed7d6b01ef0ef2c5ed438344634c35e Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Jul 2014 16:09:53 -0700 Subject: [PATCH 5/6] JOBS=6 for clang++, 2 for g++ --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a08165575..54233bf4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ before_install: install: - if [[ "${CXX}" == 'g++' ]]; then export CXX="g++-4.8" && export CC="gcc-4.8"; fi; - ./configure CXX="${CXX}" CC="${CC}" DEMO=True BENCHMARK=True CPP_TESTS=True CAIRO=True FAST=True - - JOBS=4 make + - if [[ "${CXX}" == 'g++-4.8' ]]; then JOBS=2 make; else JOBS=6 make; fi; before_script: - make test From 30d8c2b68619a4a65d284d9963eb45bfb749e1b2 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Jul 2014 16:49:58 -0700 Subject: [PATCH 6/6] travis: even more aggressive JOBS --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54233bf4d..6759b8c04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: cpp compiler: - - gcc - clang + - gcc addons: postgresql: "9.3" @@ -29,7 +29,7 @@ before_install: install: - if [[ "${CXX}" == 'g++' ]]; then export CXX="g++-4.8" && export CC="gcc-4.8"; fi; - ./configure CXX="${CXX}" CC="${CC}" DEMO=True BENCHMARK=True CPP_TESTS=True CAIRO=True FAST=True - - if [[ "${CXX}" == 'g++-4.8' ]]; then JOBS=2 make; else JOBS=6 make; fi; + - if [[ "${CXX}" == 'g++-4.8' ]]; then JOBS=3 make; else JOBS=8 make; fi; before_script: - make test