diff --git a/include/mapnik/json/feature_collection_grammar.hpp b/include/mapnik/json/feature_collection_grammar.hpp index 378353977..1fd77a80a 100644 --- a/include/mapnik/json/feature_collection_grammar.hpp +++ b/include/mapnik/json/feature_collection_grammar.hpp @@ -54,76 +54,11 @@ struct generate_id mutable int id_; }; - template struct feature_collection_grammar : qi::grammar(), space_type> { - feature_collection_grammar(context_ptr const& ctx, mapnik::transcoder const& tr) - : feature_collection_grammar::base_type(start,"start"), - feature_g(tr), - ctx_(ctx), - generate_id_(1) - { - qi::lit_type lit; - qi::eps_type eps; - qi::_4_type _4; - qi::_3_type _2; - qi::_2_type _3; - qi::_a_type _a; - qi::_val_type _val; - qi::_r1_type _r1; - using phoenix::push_back; - using phoenix::construct; - using phoenix::new_; - using phoenix::val; - - start = feature_collection | feature_from_geometry(_val) | feature(_val) - ; - - feature_collection = lit('{') >> (type | features | feature_g.json_.key_value) % lit(',') >> lit('}') - ; - - type = lit("\"type\"") >> lit(':') >> lit("\"FeatureCollection\"") - ; - - features = lit("\"features\"") - >> lit(':') - >> lit('[') - >> -(feature(_val) % lit(',')) - >> lit(']') - ; - - feature = eps[_a = phoenix::construct(new_(ctx_,generate_id_()))] - >> feature_g(*_a)[push_back(_r1,_a)] - ; - - feature_from_geometry = - eps[_a = phoenix::construct(new_(ctx_,generate_id_()))] - >> geometry_g(extract_geometry_(*_a)) [push_back(_r1, _a)] - ; - - start.name("start"); - type.name("type"); - features.name("features"); - feature.name("feature"); - feature_from_geometry.name("feature-from-geometry"); - feature_g.name("feature-grammar"); - geometry_g.name("geometry-grammar"); - - qi::on_error - ( - feature_collection - , std::clog - << phoenix::val("Error parsing GeoJSON ") - << _4 - << phoenix::val(" here: \"") - << construct(_3, _2) - << phoenix::val('\"') - << std::endl - ); - } - + feature_collection_grammar(context_ptr const& ctx, mapnik::transcoder const& tr); feature_grammar feature_g; geometry_grammar geometry_g; phoenix::function extract_geometry_; diff --git a/include/mapnik/json/feature_collection_grammar_impl.hpp b/include/mapnik/json/feature_collection_grammar_impl.hpp new file mode 100644 index 000000000..75a308803 --- /dev/null +++ b/include/mapnik/json/feature_collection_grammar_impl.hpp @@ -0,0 +1,99 @@ +/***************************************************************************** + * + * 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 + +// spirit::qi +#include +#include + +namespace mapnik { namespace json { + +template +feature_collection_grammar::feature_collection_grammar(context_ptr const& ctx, mapnik::transcoder const& tr) + : feature_collection_grammar::base_type(start,"start"), + feature_g(tr), + ctx_(ctx), + generate_id_(1) +{ + qi::lit_type lit; + qi::eps_type eps; + qi::_4_type _4; + qi::_3_type _2; + qi::_2_type _3; + qi::_a_type _a; + qi::_val_type _val; + qi::_r1_type _r1; + using phoenix::push_back; + using phoenix::construct; + using phoenix::new_; + using phoenix::val; + + start = feature_collection | feature_from_geometry(_val) | feature(_val) + ; + + feature_collection = lit('{') >> (type | features | feature_g.json_.key_value) % lit(',') >> lit('}') + ; + + type = lit("\"type\"") >> lit(':') >> lit("\"FeatureCollection\"") + ; + + features = lit("\"features\"") + >> lit(':') + >> lit('[') + >> -(feature(_val) % lit(',')) + >> lit(']') + ; + + feature = eps[_a = phoenix::construct(new_(ctx_,generate_id_()))] + >> feature_g(*_a)[push_back(_r1,_a)] + ; + + feature_from_geometry = + eps[_a = phoenix::construct(new_(ctx_,generate_id_()))] + >> geometry_g(extract_geometry_(*_a)) [push_back(_r1, _a)] + ; + + start.name("start"); + type.name("type"); + features.name("features"); + feature.name("feature"); + feature_from_geometry.name("feature-from-geometry"); + feature_g.name("feature-grammar"); + geometry_g.name("geometry-grammar"); + + qi::on_error + ( + feature_collection + , std::clog + << phoenix::val("Error parsing GeoJSON ") + << _4 + << phoenix::val(" here: \"") + << construct(_3, _2) + << phoenix::val('\"') + << std::endl + ); +} + +}} diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index bcde63f5e..8a4f4158a 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include