also move feature_collection_grammar to impl file

This commit is contained in:
Dane Springmeyer 2014-07-28 16:51:24 -07:00
parent cb3a4e10b7
commit d55a0010dc
3 changed files with 101 additions and 66 deletions

View file

@ -54,76 +54,11 @@ struct generate_id
mutable int id_;
};
template <typename Iterator, typename FeatureType>
struct feature_collection_grammar :
qi::grammar<Iterator, std::vector<feature_ptr>(), 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<mapnik::feature_ptr>(new_<mapnik::feature_impl>(ctx_,generate_id_()))]
>> feature_g(*_a)[push_back(_r1,_a)]
;
feature_from_geometry =
eps[_a = phoenix::construct<mapnik::feature_ptr>(new_<mapnik::feature_impl>(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<qi::fail>
(
feature_collection
, std::clog
<< phoenix::val("Error parsing GeoJSON ")
<< _4
<< phoenix::val(" here: \"")
<< construct<std::string>(_3, _2)
<< phoenix::val('\"')
<< std::endl
);
}
feature_collection_grammar(context_ptr const& ctx, mapnik::transcoder const& tr);
feature_grammar<Iterator,FeatureType> feature_g;
geometry_grammar<Iterator> geometry_g;
phoenix::function<extract_geometry> extract_geometry_;

View file

@ -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 <mapnik/json/feature_collection_grammar.hpp>
// spirit::qi
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
namespace mapnik { namespace json {
template <typename Iterator, typename FeatureType>
feature_collection_grammar<Iterator,FeatureType>::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<mapnik::feature_ptr>(new_<mapnik::feature_impl>(ctx_,generate_id_()))]
>> feature_g(*_a)[push_back(_r1,_a)]
;
feature_from_geometry =
eps[_a = phoenix::construct<mapnik::feature_ptr>(new_<mapnik::feature_impl>(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<qi::fail>
(
feature_collection
, std::clog
<< phoenix::val("Error parsing GeoJSON ")
<< _4
<< phoenix::val(" here: \"")
<< construct<std::string>(_3, _2)
<< phoenix::val('\"')
<< std::endl
);
}
}}

View file

@ -48,6 +48,7 @@
#include <mapnik/projection.hpp>
#include <mapnik/util/geometry_to_ds_type.hpp>
#include <mapnik/json/feature_collection_grammar.hpp>
#include <mapnik/json/feature_collection_grammar_impl.hpp>
#include <mapnik/json/feature_grammar_impl.hpp>
#include <mapnik/json/geometry_grammar_impl.hpp>
#include <boost/spirit/include/qi.hpp>