From 941a025682a4054b31f1207f388588934cab871e Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 29 Nov 2016 10:46:23 +0100 Subject: [PATCH] remove spirit::qi usage from (Geo)JSON --- .../json/extract_bounding_box_grammar.hpp | 64 ----- .../extract_bounding_box_grammar_impl.hpp | 157 ----------- .../json/feature_collection_grammar.hpp | 103 -------- .../json/feature_collection_grammar_impl.hpp | 122 --------- include/mapnik/json/feature_grammar.hpp | 91 ------- include/mapnik/json/feature_grammar_impl.hpp | 87 ------- include/mapnik/json/geometry_grammar.hpp | 65 ----- include/mapnik/json/geometry_grammar_impl.hpp | 94 ------- include/mapnik/json/geometry_util.hpp | 244 ------------------ include/mapnik/json/positions.hpp | 40 --- include/mapnik/json/positions_grammar.hpp | 55 ---- .../mapnik/json/positions_grammar_impl.hpp | 97 ------- ...mapnik_json_feature_collection_grammar.cpp | 29 --- src/json/mapnik_json_feature_grammar.cpp | 28 -- src/json/mapnik_json_geometry_grammar.cpp | 27 -- src/json/mapnik_json_geometry_parser.cpp | 43 --- src/json/mapnik_json_positions_grammar.cpp | 27 -- 17 files changed, 1373 deletions(-) delete mode 100644 include/mapnik/json/extract_bounding_box_grammar.hpp delete mode 100644 include/mapnik/json/extract_bounding_box_grammar_impl.hpp delete mode 100644 include/mapnik/json/feature_collection_grammar.hpp delete mode 100644 include/mapnik/json/feature_collection_grammar_impl.hpp delete mode 100644 include/mapnik/json/feature_grammar.hpp delete mode 100644 include/mapnik/json/feature_grammar_impl.hpp delete mode 100644 include/mapnik/json/geometry_grammar.hpp delete mode 100644 include/mapnik/json/geometry_grammar_impl.hpp delete mode 100644 include/mapnik/json/geometry_util.hpp delete mode 100644 include/mapnik/json/positions.hpp delete mode 100644 include/mapnik/json/positions_grammar.hpp delete mode 100644 include/mapnik/json/positions_grammar_impl.hpp delete mode 100644 src/json/mapnik_json_feature_collection_grammar.cpp delete mode 100644 src/json/mapnik_json_feature_grammar.cpp delete mode 100644 src/json/mapnik_json_geometry_grammar.cpp delete mode 100644 src/json/mapnik_json_geometry_parser.cpp delete mode 100644 src/json/mapnik_json_positions_grammar.cpp diff --git a/include/mapnik/json/extract_bounding_box_grammar.hpp b/include/mapnik/json/extract_bounding_box_grammar.hpp deleted file mode 100644 index 906e7126d..000000000 --- a/include/mapnik/json/extract_bounding_box_grammar.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP -#define MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP - -// mapnik -#include -#include -#include -#include - -#pragma GCC diagnostic push -#include -#include -#pragma GCC diagnostic pop - -namespace mapnik { namespace json { - -namespace qi = boost::spirit::qi; - -template > -struct extract_bounding_box_grammar : - qi::grammar -{ - using position_type = mapnik::geometry::point; - using boxes_type = Boxes; - using box_type = typename Boxes::value_type::first_type; - extract_bounding_box_grammar(); - // rules - qi::rule start; - qi::rule, void(boxes_type&), space_type> features; - qi::rule, void(boxes_type&, Iterator const&), space_type> feature; - qi::rule, box_type(), space_type> coords; - qi::rule(), space_type> pos; - qi::rule ring; - qi::rule rings; - qi::rule rings_array; - // generic JSON support - json::generic_json json; -}; - -}} - -#endif // MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP diff --git a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp b/include/mapnik/json/extract_bounding_box_grammar_impl.hpp deleted file mode 100644 index fb9868322..000000000 --- a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp +++ /dev/null @@ -1,157 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -// mapnik -#include -#include -// boost -#include -#include -#include -#include -#include -#include -// stl -#include -#include - -namespace mapnik { namespace json { - -struct calculate_bounding_box_impl -{ - using result_type = void; - template - result_type operator() (T0 & bbox, T1 const& pos) const - { - if (pos) - { - typename T0::value_type x = pos->x; - typename T0::value_type y = pos->y; - if (!bbox.valid()) - { - bbox.init(x, y); - } - else - { - bbox.expand_to_include(x, y); - } - } - } -}; - -struct push_box_impl -{ - using result_type = void; - template - void operator() (T0 & boxes, T1 const& begin, T2 const& box, T3 const& range) const - { - if (box.valid()) boxes.emplace_back(box, - std::make_pair(std::distance(begin, - range.begin()), - std::distance(range.begin(), range.end()))); - } -}; - -namespace repo = boost::spirit::repository; - -template -extract_bounding_box_grammar::extract_bounding_box_grammar() - : extract_bounding_box_grammar::base_type(start, "GeoJSON bounding boxes") -{ - qi::lit_type lit; - qi::double_type double_; - qi::_val_type _val; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::omit_type omit; - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::_a_type _a; - qi::_b_type _b; - qi::eps_type eps; - qi::raw_type raw; - qi::char_type char_; - qi::no_skip_type no_skip; - boost::spirit::repository::qi::iter_pos_type iter_pos; - using qi::fail; - using qi::on_error; - - // phoenix functions - boost::phoenix::function push_box; - boost::phoenix::function calculate_bounding_box; - // error handler - boost::phoenix::function const error_handler; - - start = features(_r1) - ; - - features = no_skip[iter_pos[_a = _1]] >> -(lit('{') - >> *((json.key_value - lit("\"features\"")) >> lit(',')) - >> lit("\"features\"") - >> lit(':')) - >> lit('[') >> -(feature(_r1,_a) % lit(',')) >> lit(']') - ; - - feature = raw[lit('{')[_a = 1] - >> *(eps(_a > 0) >> ( - lit("\"FeatureCollection\"") > eps(false) // fail if nested FeatureCollection - | - lit('{')[_a += 1] - | - lit('}')[_a -= 1] - | - coords[_b = _1] - | - json.string_ - | - char_))][push_box(_r1, _r2, _b, _1)] - ; - - coords = lit("\"coordinates\"") - >> lit(':') >> (rings_array(_a) | rings (_a) | ring(_a) | pos[calculate_bounding_box(_a,_1)])[_val = _a] - ; - - pos = lit('[') > -(double_ > lit(',') > double_) > omit[*(lit(',') > double_)] > lit(']') - ; - - ring = lit('[') >> pos[calculate_bounding_box(_r1,_1)] % lit(',') > lit(']') - ; - - rings = lit('[') >> ring(_r1) % lit(',') > lit(']') - ; - - rings_array = lit('[') >> rings(_r1) % lit(',') > lit(']') - ; - - coords.name("Coordinates"); - pos.name("Position"); - ring.name("Ring"); - rings.name("Rings"); - rings_array.name("Rings array"); - - // error handler - on_error(coords, error_handler(_1, _2, _3, _4)); -} - -}} diff --git a/include/mapnik/json/feature_collection_grammar.hpp b/include/mapnik/json/feature_collection_grammar.hpp deleted file mode 100644 index c71801c3f..000000000 --- a/include/mapnik/json/feature_collection_grammar.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_FEATURE_COLLECTION_GRAMMAR_HPP -#define MAPNIK_FEATURE_COLLECTION_GRAMMAR_HPP - -// mapnik -#include -#include -#include -#include - -// spirit::qi -#include -#include - -namespace mapnik { namespace json { - -namespace qi = boost::spirit::qi; -namespace phoenix = boost::phoenix; - -struct default_feature_callback -{ - default_feature_callback(std::vector & features) - : features_(features) {} - void operator() (feature_ptr const& feature) - { - features_.push_back(feature); - } - std::vector & features_; -}; - -struct apply_feature_callback -{ - using result_type = void; - template - void operator() (Callback & callback, Feature const& feature) const - { - callback(feature); - } -}; - -template > -struct feature_collection_grammar : - qi::grammar -{ - feature_collection_grammar(mapnik::transcoder const& tr); - // grammars - feature_grammar feature_g; - // rules - qi::rule start; // START - qi::rule feature_collection; - qi::rule type; - qi::rule features; - qi::rule, void(context_ptr const& ctx, std::size_t, FeatureCallback&), space_type> feature; - // phoenix functions - phoenix::function on_feature; - // error handler - boost::phoenix::function const error_handler; -}; - -template > -struct feature_grammar_callback : - qi::grammar -{ - feature_grammar_callback(mapnik::transcoder const& tr); - // grammars - feature_grammar feature_g; - geometry_grammar geometry_g; - // rules - qi::rule start; // START - qi::rule, void(context_ptr const& ctx, std::size_t, FeatureCallback&), space_type> feature; - qi::rule, void(context_ptr const& ctx, std::size_t, FeatureCallback&), space_type> feature_from_geometry; - // phoenix functions - phoenix::function set_geometry; - phoenix::function on_feature; - // error handler - boost::phoenix::function const error_handler; -}; - - -}} - -#endif // MAPNIK_FEATURE_COLLECTION_GRAMMAR_HPP diff --git a/include/mapnik/json/feature_collection_grammar_impl.hpp b/include/mapnik/json/feature_collection_grammar_impl.hpp deleted file mode 100644 index b2836af37..000000000 --- a/include/mapnik/json/feature_collection_grammar_impl.hpp +++ /dev/null @@ -1,122 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - - -// mapnik -#include -#include - -// spirit::qi -#include -#include - -namespace mapnik { namespace json { - -template -feature_collection_grammar::feature_collection_grammar(mapnik::transcoder const& tr) - : feature_collection_grammar::base_type(start,"start"), - feature_g(tr) -{ - qi::lit_type lit; - qi::eps_type eps; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::_a_type _a; - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::_r3_type _r3; - using phoenix::construct; - using phoenix::new_; - using phoenix::val; - using qi::on_error; - using qi::fail; - start = feature_collection(_r1, _r2, _r3) - ; - - feature_collection = lit('{') > (type | features(_r1, _r2, _r3) | feature_g.json_.key_value) % lit(',') > lit('}') - ; - - type = lit("\"type\"") > lit(':') > lit("\"FeatureCollection\"") - ; - - features = lit("\"features\"") - > lit(':') > lit('[') > - ( lit(']') | ((feature(_r1, _r2, _r3) [_r2 +=1] % lit(',')) > lit(']'))) - ; - - feature = eps[_a = phoenix::construct(new_(_r1, _r2))] - > feature_g(*_a)[on_feature(_r3,_a)] - ; - - start.name("start"); - feature_collection.name("FeatureCollection"); - type.name("type"); - features.name("features"); - feature.name("feature"); - feature_g.name("feature-grammar"); - on_error(feature_collection, error_handler(_1, _2, _3, _4)); -} - - -template -feature_grammar_callback::feature_grammar_callback(mapnik::transcoder const& tr) - : feature_grammar_callback::base_type(start,"start"), - feature_g(tr) -{ - qi::lit_type lit; - qi::eps_type eps; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::_a_type _a; - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::_r3_type _r3; - using phoenix::construct; - using phoenix::new_; - using phoenix::val; - using qi::on_error; - using qi::fail; - start = feature_from_geometry(_r1, _r2, _r3) | feature(_r1, _r2, _r3) - ; - - feature = eps[_a = phoenix::construct(new_(_r1, _r2))] - >> feature_g(*_a)[on_feature(_r3,_a)] - ; - - feature_from_geometry = - eps[_a = phoenix::construct(new_(_r1, _r2))] - >> geometry_g[set_geometry(*_a, _1)] [on_feature(_r3, _a)] - ; - - start.name("start"); - feature.name("feature"); - feature_from_geometry.name("feature-from-geometry"); - feature_g.name("feature-grammar"); - geometry_g.name("geometry-grammar"); - on_error(feature, error_handler(_1, _2, _3, _4)); -} - -}} diff --git a/include/mapnik/json/feature_grammar.hpp b/include/mapnik/json/feature_grammar.hpp deleted file mode 100644 index fae8ed58a..000000000 --- a/include/mapnik/json/feature_grammar.hpp +++ /dev/null @@ -1,91 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_FEATURE_GRAMMAR_HPP -#define MAPNIK_FEATURE_GRAMMAR_HPP - -// mapnik -#include -#include -#include -#include -#pragma GCC diagnostic push -#include -#include -#include -#include -#pragma GCC diagnostic pop - -namespace mapnik { namespace json { - -namespace qi = boost::spirit::qi; -namespace phoenix = boost::phoenix; -namespace fusion = boost::fusion; - -struct put_property -{ - using result_type = void; - explicit put_property(mapnik::transcoder const& tr) - : tr_(tr) {} - template - result_type operator() (T0 & feature, T1 const& key, T2 && val) const - { - feature.put_new(key, mapnik::util::apply_visitor(attribute_value_visitor(tr_),val)); - } - mapnik::transcoder const& tr_; -}; - -struct set_geometry_impl -{ - using result_type = void; - template - result_type operator() (T0 & feature, T1 && geom) const - { - return feature.set_geometry(std::move(geom)); - } -}; - -template > -struct feature_grammar : qi::grammar -{ - explicit feature_grammar(mapnik::transcoder const& tr); - // generic JSON - generic_json json_; - // geoJSON - qi::rule start; - qi::rule, void(FeatureType&), space_type> feature; - qi::rule feature_part; - qi::rule feature_type; - qi::rule properties; - qi::rule, void(FeatureType &),space_type> attributes; - // functions - phoenix::function put_property_; - phoenix::function set_geometry; - // error handler - boost::phoenix::function const error_handler; - // geometry - geometry_grammar geometry_grammar_; -}; - -}} - -#endif // MAPNIK_FEATURE_GRAMMAR_HPP diff --git a/include/mapnik/json/feature_grammar_impl.hpp b/include/mapnik/json/feature_grammar_impl.hpp deleted file mode 100644 index bdda650cc..000000000 --- a/include/mapnik/json/feature_grammar_impl.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -// mapnik -#include -#include - -namespace mapnik { namespace json { - -template -feature_grammar::feature_grammar(mapnik::transcoder const& tr) - : feature_grammar::base_type(start,"feature"), - json_(), - put_property_(put_property(tr)) -{ - qi::lit_type lit; - qi::long_long_type long_long; - qi::double_type double_; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::_a_type _a; - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::eps_type eps; - qi::char_type char_; - using qi::fail; - using qi::on_error; - using phoenix::new_; - using phoenix::construct; - - // geojson types - feature_type = lit("\"type\"") > lit(':') > lit("\"Feature\"") - ; - - start = feature(_r1); - - feature = eps[_a = false] > lit('{') > - feature_part(_r1, _a) % lit(',') - > eps(_a) > lit('}') - ; - - feature_part = feature_type[_r2 = true] - | - (lit("\"geometry\"") > lit(':') > geometry_grammar_[set_geometry(_r1, _1)]) - | - properties(_r1) - | - json_.key_value - ; - - properties = lit("\"properties\"") - > lit(':') > ((lit('{') > -attributes(_r1) > lit('}')) | lit("null")) - ; - - attributes = (json_.string_ [_a = _1] > lit(':') > json_.value [put_property_(_r1,_a,_1)]) % lit(',') - ; - - feature.name("Feature"); - feature_type.name("type"); - properties.name("properties"); - attributes.name("Attributes"); - on_error(feature, error_handler(_1, _2, _3, _4)); - -} - -}} diff --git a/include/mapnik/json/geometry_grammar.hpp b/include/mapnik/json/geometry_grammar.hpp deleted file mode 100644 index e4b60fd4f..000000000 --- a/include/mapnik/json/geometry_grammar.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_GEOMETRY_GRAMMAR_HPP -#define MAPNIK_GEOMETRY_GRAMMAR_HPP - -// mapnik -#include // for geometry_type -#include -#include -#include -#include - -#pragma GCC diagnostic push -#include -#include -#include -#pragma GCC diagnostic pop - -#include - -namespace mapnik { namespace json { - -namespace qi = boost::spirit::qi; - -template > -struct geometry_grammar : - qi::grammar() ,space_type> -{ - geometry_grammar(); - qi::rule(), space_type> start; - qi::rule, mapnik::geometry::geometry(), space_type> geometry; - qi::rule&), space_type> geometry_part; - qi::rule(), space_type> geometry_collection; - qi::symbols geometry_type_dispatch; - positions_grammar coordinates; - boost::phoenix::function create_geometry; - // generic JSON - generic_json json_; - // error handler - ErrorHandler error_handler; -}; - -}} - -#endif // MAPNIK_GEOMETRY_GRAMMAR_HPP diff --git a/include/mapnik/json/geometry_grammar_impl.hpp b/include/mapnik/json/geometry_grammar_impl.hpp deleted file mode 100644 index 219d3689f..000000000 --- a/include/mapnik/json/geometry_grammar_impl.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -// mapnik -#include -#include -#include -#include -// boost -#include -#include - -namespace mapnik { namespace json { - -template -geometry_grammar::geometry_grammar() - : geometry_grammar::base_type(start,"geometry"), - coordinates(error_handler) -{ - qi::lit_type lit; - qi::int_type int_; - qi::double_type double_; - qi::_val_type _val; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::_a_type _a; - qi::_b_type _b; - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::_r3_type _r3; - qi::eps_type eps; - using qi::fail; - using qi::on_error; - using phoenix::push_back; - - start = geometry.alias() | lit("null"); - - geometry = lit('{')[_a = 0] - > (geometry_part(_a, _b, _val) % lit(','))[create_geometry(_val, _a, _b)] - > lit('}'); - - geometry_part = ((lit("\"type\"") > lit(':') > geometry_type_dispatch[_r1 = _1]) - | - (lit("\"coordinates\"") > lit(':') > coordinates[_r2 = _1]) - | - (lit("\"geometries\"") > lit(':') > lit('[') > geometry_collection[_r3 = _1] > lit(']')) - | - json_.key_value) - ; - - geometry_collection = geometry[push_back(_val, _1)] % lit(',') - ; - geometry_type_dispatch.add - ("\"Point\"",1) - ("\"LineString\"",2) - ("\"Polygon\"",3) - ("\"MultiPoint\"",4) - ("\"MultiLineString\"",5) - ("\"MultiPolygon\"",6) - ("\"GeometryCollection\"",7) - ; - - // give some rules names - geometry.name("Geometry"); - geometry_collection.name("GeometryCollection"); - geometry_type_dispatch.name("type: (Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon|GeometryCollection)"); - coordinates.name("coordinates"); - // error handler - auto error_handler_function = boost::phoenix::function(error_handler); - on_error(start, error_handler_function(_1, _2, _3, _4)); -} - -}} diff --git a/include/mapnik/json/geometry_util.hpp b/include/mapnik/json/geometry_util.hpp deleted file mode 100644 index d26720e48..000000000 --- a/include/mapnik/json/geometry_util.hpp +++ /dev/null @@ -1,244 +0,0 @@ - /***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_JSON_GEOMETRY_UTIL_HPP -#define MAPNIK_JSON_GEOMETRY_UTIL_HPP - -#include -#include -#include - -namespace mapnik { namespace json { - -// geometries -template -struct create_point -{ - explicit create_point(Geometry & geom) - : geom_(geom) {} - - void operator() (position const& pos) const - { - mapnik::geometry::point point(pos.x, pos.y); - geom_ = std::move(point); - } - - template - void operator()(T const&) const {} // no-op - shouldn't get here - Geometry & geom_; -}; - -template -struct create_linestring -{ - explicit create_linestring(Geometry & geom) - : geom_(geom) {} - - void operator() (positions const& ring) const - { - std::size_t size = ring.size(); - if (size > 1) - { - mapnik::geometry::line_string line; - line.reserve(size); - for (auto && pt : ring) - { - line.emplace_back(std::move(pt)); - } - geom_ = std::move(line); - } - } - - template - void operator()(T const&) const {} // no-op - shouldn't get here - - Geometry & geom_; -}; - -template -struct create_polygon -{ - explicit create_polygon(Geometry & geom) - : geom_(geom) {} - - void operator() (std::vector const& rings) const - { - mapnik::geometry::polygon poly; - std::size_t num_rings = rings.size(); - if (num_rings > 1) - { - poly.interior_rings.reserve(num_rings - 1); - } - - for ( std::size_t i = 0; i < num_rings; ++i) - { - std::size_t size = rings[i].size(); - mapnik::geometry::linear_ring ring; - ring.reserve(size); - for ( auto && pt : rings[i]) - { - ring.emplace_back(std::move(pt)); - } - if (i == 0) poly.set_exterior_ring(std::move(ring)); - else poly.add_hole(std::move(ring)); - } - geom_ = std::move(poly); - mapnik::geometry::correct(geom_); - } - - template - void operator()(T const&) const {} // no-op - shouldn't get here - - Geometry & geom_; -}; - -// multi-geometries -template -struct create_multipoint -{ - explicit create_multipoint(Geometry & geom) - : geom_(geom) {} - - void operator() (positions const& points) const - { - mapnik::geometry::multi_point multi_point; - multi_point.reserve(points.size()); - for (auto && pos : points) - { - multi_point.emplace_back(std::move(pos)); - } - geom_ = std::move(multi_point); - } - - template - void operator()(T const&) const {} // no-op - shouldn't get here - - Geometry & geom_; -}; - -template -struct create_multilinestring -{ - explicit create_multilinestring(Geometry & geom) - : geom_(geom) {} - - void operator() (std::vector const& rings) const - { - mapnik::geometry::multi_line_string multi_line; - multi_line.reserve(rings.size()); - - for (auto const& ring : rings) - { - mapnik::geometry::line_string line; - line.reserve(ring.size()); - for (auto && pt : ring) - { - line.emplace_back(std::move(pt)); - } - multi_line.emplace_back(std::move(line)); - } - geom_ = std::move(multi_line); - } - - template - void operator()(T const&) const {} // no-op - shouldn't get here - - Geometry & geom_; -}; - -template -struct create_multipolygon -{ - explicit create_multipolygon(Geometry & geom) - : geom_(geom) {} - - void operator()(std::vector > const& rings_array) const - { - mapnik::geometry::multi_polygon multi_poly; - multi_poly.reserve(rings_array.size()); - for (auto const& rings : rings_array) - { - mapnik::geometry::polygon poly; - std::size_t num_rings = rings.size(); - if ( num_rings > 1) - poly.interior_rings.reserve(num_rings - 1); - - for ( std::size_t i = 0; i < num_rings; ++i) - { - std::size_t size = rings[i].size(); - mapnik::geometry::linear_ring ring; - ring.reserve(size); - for ( auto && pt : rings[i]) - { - ring.emplace_back(std::move(pt)); - } - if (i == 0) poly.set_exterior_ring(std::move(ring)); - else poly.add_hole(std::move(ring)); - } - multi_poly.emplace_back(std::move(poly)); - } - geom_ = std::move(multi_poly); - mapnik::geometry::correct(geom_); - } - - template - void operator()(T const&) const {} // no-op - shouldn't get here - - Geometry & geom_; -}; - -struct create_geometry_impl -{ - using result_type = void; - template - void operator() (Geometry & geom, int type, mapnik::json::coordinates const& coords) const - { - switch (type) - { - case 1 ://Point - util::apply_visitor(create_point(geom), coords); - break; - case 2 ://LineString - util::apply_visitor(create_linestring(geom), coords); - break; - case 3 ://Polygon - util::apply_visitor(create_polygon(geom), coords); - break; - case 4 ://MultiPoint - util::apply_visitor(create_multipoint(geom), coords); - break; - case 5 ://MultiLineString - util::apply_visitor(create_multilinestring(geom), coords); - break; - case 6 ://MultiPolygon - util::apply_visitor(create_multipolygon(geom), coords); - break; - default: - break; - } - - } -}; - -}} - -#endif // MAPNIK_JSON_GEOMETRY_UTIL_HPP diff --git a/include/mapnik/json/positions.hpp b/include/mapnik/json/positions.hpp deleted file mode 100644 index 9ad10f99a..000000000 --- a/include/mapnik/json/positions.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_JSON_POSITIONS_HPP -#define MAPNIK_JSON_POSITIONS_HPP - -// mapnik -#include -#include - -namespace mapnik { namespace json { - -struct empty {}; - -using position = mapnik::geometry::point; -using positions = std::vector; -using coordinates = util::variant, std::vector > > ; - -}} - -#endif // MAPNIK_JSON_POSITIONS_HPP diff --git a/include/mapnik/json/positions_grammar.hpp b/include/mapnik/json/positions_grammar.hpp deleted file mode 100644 index 6984300f9..000000000 --- a/include/mapnik/json/positions_grammar.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -#ifndef MAPNIK_JSON_POSITIONS_GRAMMAR_HPP -#define MAPNIK_JSON_POSITIONS_GRAMMAR_HPP - -// mapnik -#include -#include -#pragma GCC diagnostic push -#include -#include -#pragma GCC diagnostic pop - - -namespace mapnik { namespace json { - -namespace qi = boost::spirit::qi; -namespace standard = boost::spirit::standard; -using space_type = standard::space_type; - -template > -struct positions_grammar : - qi::grammar -{ - positions_grammar(ErrorHandler & error_handler); - qi::rule coords; - qi::rule(), space_type> pos; - qi::rule ring; - qi::rule(), space_type> rings; - qi::rule >(), space_type> rings_array; -}; - -}} - -#endif // MAPNIK_JSON_POSITIONS_GRAMMAR_HPP diff --git a/include/mapnik/json/positions_grammar_impl.hpp b/include/mapnik/json/positions_grammar_impl.hpp deleted file mode 100644 index 32379ea2c..000000000 --- a/include/mapnik/json/positions_grammar_impl.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/***************************************************************************** - * - * 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 - * - *****************************************************************************/ - -// mapnik -#include -#include -// boost -#include -#include -#include -#include -#include -// stl -#include -#include - -namespace mapnik { namespace json { - -struct set_position_impl -{ - using result_type = void; - template - result_type operator() (T0 & coords, T1 const& pos) const - { - if (pos) coords = *pos; - } -}; - -struct push_position_impl -{ - using result_type = void; - template - result_type operator() (T0 & coords, T1 const& pos) const - { - if (pos) coords.emplace_back(*pos); - } -}; - -template -positions_grammar::positions_grammar(ErrorHandler & error_handler) - : positions_grammar::base_type(coords,"coordinates") -{ - qi::lit_type lit; - qi::double_type double_; - qi::_val_type _val; - qi::_1_type _1; - qi::_2_type _2; - qi::_3_type _3; - qi::_4_type _4; - qi::omit_type omit; - using qi::fail; - using qi::on_error; - - boost::phoenix::function set_position; - boost::phoenix::function push_position; - - coords = rings_array[_val = _1] | rings [_val = _1] | ring[_val = _1] | pos[set_position(_val,_1)] - ; - pos = lit('[') > -(double_ > lit(',') > double_) > omit[*(lit(',') > double_)] > lit(']') - ; - ring = lit('[') >> pos[push_position(_val,_1)] % lit(',') > lit(']') - ; - rings = lit('[') >> ring % lit(',') > lit(']') - ; - rings_array = lit('[') >> rings % lit(',') > lit(']') - ; - coords.name("Coordinates"); - pos.name("Position"); - ring.name("Ring"); - rings.name("Rings"); - rings_array.name("Rings array"); - - // error handler - auto error_handler_function = boost::phoenix::function(error_handler); - on_error(coords, error_handler_function(_1, _2, _3, _4)); -} - -}} diff --git a/src/json/mapnik_json_feature_collection_grammar.cpp b/src/json/mapnik_json_feature_collection_grammar.cpp deleted file mode 100644 index e262d7cfc..000000000 --- a/src/json/mapnik_json_feature_collection_grammar.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/***************************************************************************** - * - * 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 -#include -#include - -using iterator_type = char const*; -template struct mapnik::json::feature_collection_grammar ; -template struct mapnik::json::feature_grammar_callback ; diff --git a/src/json/mapnik_json_feature_grammar.cpp b/src/json/mapnik_json_feature_grammar.cpp deleted file mode 100644 index 1aa6c7e9e..000000000 --- a/src/json/mapnik_json_feature_grammar.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/***************************************************************************** - * - * 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 -#include -#include - -using iterator_type = char const*; -template struct mapnik::json::feature_grammar; diff --git a/src/json/mapnik_json_geometry_grammar.cpp b/src/json/mapnik_json_geometry_grammar.cpp deleted file mode 100644 index f2b96f230..000000000 --- a/src/json/mapnik_json_geometry_grammar.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/***************************************************************************** - * - * 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 -#include - -using iterator_type = char const*; -template struct mapnik::json::geometry_grammar; diff --git a/src/json/mapnik_json_geometry_parser.cpp b/src/json/mapnik_json_geometry_parser.cpp deleted file mode 100644 index 278d2c4be..000000000 --- a/src/json/mapnik_json_geometry_parser.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2016 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 - -// boost -#include -#include - -namespace mapnik { namespace json { - -bool from_geojson(std::string const& json, mapnik::geometry::geometry & geom) -{ - using namespace boost::spirit; - static const geometry_grammar g; - standard::space_type space; - char const* start = json.c_str(); - char const* end = start + json.length(); - return qi::phrase_parse(start, end, g, space, geom); -} - -}} diff --git a/src/json/mapnik_json_positions_grammar.cpp b/src/json/mapnik_json_positions_grammar.cpp deleted file mode 100644 index a13f0e313..000000000 --- a/src/json/mapnik_json_positions_grammar.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/***************************************************************************** - * - * 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 -#include - -using iterator_type = char const*; -template struct mapnik::json::positions_grammar;