From 3f26a1f23fbaec0876c960b2feb3d07906848efb Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 30 Aug 2016 12:37:33 -0700 Subject: [PATCH 1/5] use latest visual test data --- test/data-visual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data-visual b/test/data-visual index db7989be3..61f0d314b 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit db7989be3a8b636c60c79356b9ba9ca579faa01d +Subproject commit 61f0d314b989a345df9515d5bc1472c8d5362990 From f360f50eed1679f62a83b0f55cfc50f0e01c5fd0 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 31 Aug 2016 14:36:35 +0100 Subject: [PATCH 2/5] JSON - make `generic_json` a proper spirit grammar and reduce code bloat --- .../extract_bounding_box_grammar_impl.hpp | 22 ------- include/mapnik/json/feature_grammar_impl.hpp | 25 -------- include/mapnik/json/generic_json.hpp | 5 +- include/mapnik/json/geometry_grammar_impl.hpp | 25 -------- include/mapnik/json/positions_grammar.hpp | 3 +- include/mapnik/json/topojson_grammar_impl.hpp | 24 ------- src/json/generic_json.cpp | 64 +++++++++++++++++++ 7 files changed, 69 insertions(+), 99 deletions(-) create mode 100644 src/json/generic_json.cpp diff --git a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp b/include/mapnik/json/extract_bounding_box_grammar_impl.hpp index 25ddbcd92..bdc1b98b2 100644 --- a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp +++ b/include/mapnik/json/extract_bounding_box_grammar_impl.hpp @@ -144,28 +144,6 @@ extract_bounding_box_grammar::extract_bounding_bo rings_array = lit('[') >> rings(_r1) % lit(',') > lit(']') ; - // generic json types - json.value = json.object | json.array | json.string_ | json.number - ; - - json.key_value = json.string_ >> lit(':') >> json.value - ; - - json.object = lit('{') >> json.key_value % lit(',') >> lit('}') - ; - - json.array = lit('[') - >> json.value >> *(lit(',') >> json.value) - >> lit(']') - ; - - json.number = json.strict_double - | json.int__ - | lit("true") - | lit("false") - | lit("null") - ; - coords.name("Coordinates"); pos.name("Position"); ring.name("Ring"); diff --git a/include/mapnik/json/feature_grammar_impl.hpp b/include/mapnik/json/feature_grammar_impl.hpp index 0fc4205ad..88f72ff0d 100644 --- a/include/mapnik/json/feature_grammar_impl.hpp +++ b/include/mapnik/json/feature_grammar_impl.hpp @@ -35,7 +35,6 @@ feature_grammar::feature_grammar(mapnik::tran qi::lit_type lit; qi::long_long_type long_long; qi::double_type double_; - qi::_val_type _val; qi::_1_type _1; qi::_2_type _2; qi::_3_type _3; @@ -49,30 +48,6 @@ feature_grammar::feature_grammar(mapnik::tran using phoenix::new_; using phoenix::construct; - // generic json types - json_.value = json_.object | json_.array | json_.string_ | json_.number - ; - - json_.key_value = json_.string_ > lit(':') > json_.value - ; - - json_.object = lit('{') - > -(json_.key_value % lit(',')) - > lit('}') - ; - - json_.array = lit('[') - > -(json_.value % lit(',')) - > lit(']') - ; - - json_.number = json_.strict_double[_val = json_.double_converter(_1)] - | json_.int__[_val = json_.integer_converter(_1)] - | lit("true") [_val = true] - | lit ("false") [_val = false] - | lit("null")[_val = construct()] - ; - // geojson types feature_type = lit("\"type\"") > lit(':') > lit("\"Feature\"") ; diff --git a/include/mapnik/json/generic_json.hpp b/include/mapnik/json/generic_json.hpp index 7ea1bc05f..65c04c47d 100644 --- a/include/mapnik/json/generic_json.hpp +++ b/include/mapnik/json/generic_json.hpp @@ -129,7 +129,7 @@ struct push_esc } }; -template< typename Iterator > +template< typename Iterator> unicode_string::unicode_string() : unicode_string::base_type(double_quoted) { @@ -175,8 +175,9 @@ unicode_string::unicode_string() } template -struct generic_json +struct generic_json : qi::grammar { + generic_json(); qi::rule value; qi::int_parser int__; unicode_string string_; diff --git a/include/mapnik/json/geometry_grammar_impl.hpp b/include/mapnik/json/geometry_grammar_impl.hpp index 285be2744..29ea8461c 100644 --- a/include/mapnik/json/geometry_grammar_impl.hpp +++ b/include/mapnik/json/geometry_grammar_impl.hpp @@ -52,31 +52,6 @@ geometry_grammar::geometry_grammar() using phoenix::push_back; start = geometry.alias() | lit("null"); - - // generic json types - json_.value = json_.object | json_.array | json_.string_ | json_.number - ; - - json_.key_value = json_.string_ > lit(':') > json_.value - ; - - json_.object = lit('{') - > -(json_.key_value % lit(',')) - > lit('}') - ; - - json_.array = lit('[') - > -(json_.value % lit(',')) - > lit(']') - ; - - json_.number = json_.strict_double - | json_.int__ - | lit("true") - | lit ("false") - | lit("null") - ; - geometry = lit('{')[_a = 0] > (((lit("\"type\"") > lit(':') > geometry_type_dispatch[_a = _1]) | diff --git a/include/mapnik/json/positions_grammar.hpp b/include/mapnik/json/positions_grammar.hpp index 75a6b21b6..016ecb222 100644 --- a/include/mapnik/json/positions_grammar.hpp +++ b/include/mapnik/json/positions_grammar.hpp @@ -26,7 +26,6 @@ // mapnik #include #include -#include #include #include #pragma GCC diagnostic push @@ -38,6 +37,8 @@ namespace mapnik { namespace json { namespace qi = boost::spirit::qi; +namespace standard = boost::spirit::standard; +using space_type = standard::space_type; template > struct positions_grammar : diff --git a/include/mapnik/json/topojson_grammar_impl.hpp b/include/mapnik/json/topojson_grammar_impl.hpp index f868cefc4..07b3a9756 100644 --- a/include/mapnik/json/topojson_grammar_impl.hpp +++ b/include/mapnik/json/topojson_grammar_impl.hpp @@ -94,7 +94,6 @@ topojson_grammar::topojson_grammar() using qi::fail; using qi::on_error; using phoenix::push_back; - using phoenix::construct; geometry_type_dispatch.add ("\"Point\"",1) @@ -109,29 +108,6 @@ topojson_grammar::topojson_grammar() // error handler boost::phoenix::function const error_handler; boost::phoenix::function const create_geometry; - // generic JSON types - json.value = json.object | json.array | json.string_ | json.number - ; - - json.key_value = json.string_ > lit(':') > json.value - ; - - json.object = lit('{') - > -(json.key_value % lit(',')) - > lit('}') - ; - - json.array = lit('[') - > -(json.value % lit(',')) - > lit(']') - ; - - json.number = json.strict_double[_val = json.double_converter(_1)] - | json.int__[_val = json.integer_converter(_1)] - | lit("true")[_val = true] - | lit("false")[_val = false] - | lit("null")[_val = construct()] - ; // topo json topology = lit('{') >> lit("\"type\"") >> lit(':') >> lit("\"Topology\"") diff --git a/src/json/generic_json.cpp b/src/json/generic_json.cpp new file mode 100644 index 000000000..92cd908b5 --- /dev/null +++ b/src/json/generic_json.cpp @@ -0,0 +1,64 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 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 + +namespace mapnik { namespace json { + +template +generic_json::generic_json() + : generic_json::base_type(value) +{ + qi::lit_type lit; + qi::_val_type _val; + qi::_1_type _1; + using phoenix::construct; + // generic json types + value = object | array | string_ | number + ; + + key_value = string_ > lit(':') > value + ; + + object = lit('{') + > -(key_value % lit(',')) + > lit('}') + ; + + array = lit('[') + > -(value % lit(',')) + > lit(']') + ; + + number = strict_double[_val = double_converter(_1)] + | int__[_val = integer_converter(_1)] + | lit("true") [_val = true] + | lit ("false") [_val = false] + | lit("null")[_val = construct()] + ; +} + +}} + +using iterator_type = char const*; +template struct mapnik::json::generic_json; +template struct mapnik::json::generic_json; From af099a57efffbf49bf0829f2befaa740f28f810d Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 31 Aug 2016 17:42:18 +0100 Subject: [PATCH 3/5] topojson grammar - change interface + instantiate with `Iterator = char const*` to reduce binary size --- plugins/input/topojson/topojson_datasource.cpp | 12 +++++++----- src/json/generic_json.cpp | 1 - src/json/mapnik_topojson_grammar.cpp | 2 +- test/unit/datasource/topojson.cpp | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/input/topojson/topojson_datasource.cpp b/plugins/input/topojson/topojson_datasource.cpp index 2cfad1fb8..67bae443b 100644 --- a/plugins/input/topojson/topojson_datasource.cpp +++ b/plugins/input/topojson/topojson_datasource.cpp @@ -160,7 +160,7 @@ topojson_datasource::topojson_datasource(parameters const& params) } if (!inline_string_.empty()) { - parse_topojson(inline_string_); + parse_topojson(inline_string_.c_str()); } else { @@ -172,20 +172,22 @@ topojson_datasource::topojson_datasource(parameters const& params) std::string file_buffer; file_buffer.resize(file.size()); std::fread(&file_buffer[0], file.size(), 1, file.get()); - parse_topojson(file_buffer); + parse_topojson(file_buffer.c_str()); } } namespace { -using base_iterator_type = std::string::const_iterator; -const mapnik::topojson::topojson_grammar g; +using iterator_type = const char*; +const mapnik::topojson::topojson_grammar g; } template void topojson_datasource::parse_topojson(T const& buffer) { boost::spirit::standard::space_type space; - bool result = boost::spirit::qi::phrase_parse(buffer.begin(), buffer.end(), g, space, topo_); + auto itr = buffer; + auto end = buffer + std::strlen(buffer); + bool result = boost::spirit::qi::phrase_parse(itr, end, g, space, topo_); if (!result) { throw mapnik::datasource_exception("topojson_datasource: Failed parse TopoJSON file '" + filename_ + "'"); diff --git a/src/json/generic_json.cpp b/src/json/generic_json.cpp index 92cd908b5..7fb2e9fd3 100644 --- a/src/json/generic_json.cpp +++ b/src/json/generic_json.cpp @@ -61,4 +61,3 @@ generic_json::generic_json() using iterator_type = char const*; template struct mapnik::json::generic_json; -template struct mapnik::json::generic_json; diff --git a/src/json/mapnik_topojson_grammar.cpp b/src/json/mapnik_topojson_grammar.cpp index e70f7c590..e4b9dca32 100644 --- a/src/json/mapnik_topojson_grammar.cpp +++ b/src/json/mapnik_topojson_grammar.cpp @@ -24,5 +24,5 @@ #include #include -using iterator_type = std::string::const_iterator; +using iterator_type = char const*; template struct mapnik::topojson::topojson_grammar ; diff --git a/test/unit/datasource/topojson.cpp b/test/unit/datasource/topojson.cpp index 41d9b1908..7bf155e33 100644 --- a/test/unit/datasource/topojson.cpp +++ b/test/unit/datasource/topojson.cpp @@ -31,7 +31,7 @@ namespace { -using iterator_type = std::string::const_iterator; +using iterator_type = char const*; const mapnik::topojson::topojson_grammar grammar; bool parse_topology(std::string const& filename, mapnik::topojson::topology & topo) @@ -42,8 +42,8 @@ bool parse_topology(std::string const& filename, mapnik::topojson::topology & to std::fread(&buffer[0], buffer.size(), 1, file.get()); if (!file) return false; boost::spirit::standard::space_type space; - iterator_type itr = buffer.begin(); - iterator_type end = buffer.end(); + iterator_type itr = buffer.c_str(); + iterator_type end = itr + buffer.length(); bool result = boost::spirit::qi::phrase_parse(itr, end, grammar, space, topo); return (result && (itr == end)); } From 02c2338c431c2cf1aa0ff1da90ce44b36cd4eab7 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 31 Aug 2016 11:09:11 -0700 Subject: [PATCH 4/5] mapnik-config: strip clang specific warning flags --- utils/mapnik-config/build.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utils/mapnik-config/build.py b/utils/mapnik-config/build.py index e4178ba41..35a730bf0 100644 --- a/utils/mapnik-config/build.py +++ b/utils/mapnik-config/build.py @@ -80,7 +80,15 @@ def write_config(configuration,template,config_file): os.chmod(config_file,0755) except: pass -cxxflags = ' '.join(config_env['LIBMAPNIK_CXXFLAGS']) + +cxxflags_raw = config_env['LIBMAPNIK_CXXFLAGS']; +# strip clang specific flags to avoid breaking gcc +# while it is not recommended to mix compilers, this nevertheless +# makes it easier to compile apps with gcc and mapnik-config against mapnik built with clang +to_remove = ['-Wno-unsequenced','-Wno-unknown-warning-option','-Wtautological-compare','-Wheader-hygiene'] +cxxflags_cleaned = [item for item in config_env['LIBMAPNIK_CXXFLAGS'] if item not in to_remove]; + +cxxflags = ' '.join(cxxflags_cleaned) defines = ' '.join(config_env['LIBMAPNIK_DEFINES']) From 4b06dfe9b4636baf6358e3413b8d9e2e6506fe40 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 31 Aug 2016 11:09:27 -0700 Subject: [PATCH 5/5] Avoid warnings when building the g++5 --- include/mapnik/raster_colorizer.hpp | 4 ++-- include/mapnik/value.hpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/mapnik/raster_colorizer.hpp b/include/mapnik/raster_colorizer.hpp index 86a85def2..690549746 100644 --- a/include/mapnik/raster_colorizer.hpp +++ b/include/mapnik/raster_colorizer.hpp @@ -93,7 +93,7 @@ public: //! \brief Set the stop value //! \param[in] value The stop value - inline void set_value(float value) { value_ = value; } + inline void set_value(float v) { value_ = v; } //! \brief Get the stop value //! \return The stop value @@ -205,7 +205,7 @@ public: //! //! \param[in] value Input value //! \return color associated with the value - unsigned get_color(float value) const; + unsigned get_color(float v) const; //! \brief Set the epsilon value for exact mode diff --git a/include/mapnik/value.hpp b/include/mapnik/value.hpp index 3bd59b4b7..9ee732385 100644 --- a/include/mapnik/value.hpp +++ b/include/mapnik/value.hpp @@ -149,6 +149,7 @@ namespace std { #pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wmismatched-tags" template <>