re-use feature_collection_grammar

This commit is contained in:
artemp 2014-07-30 11:28:23 +01:00
parent 3f5344ca82
commit 61c05bfb45

View file

@ -145,24 +145,22 @@ geojson_datasource::geojson_datasource(parameters const& params)
} }
} }
namespace {
using base_iterator_type = std::istreambuf_iterator<char>;
const mapnik::transcoder tr("utf8");
const mapnik::json::feature_collection_grammar<boost::spirit::multi_pass<base_iterator_type>,mapnik::feature_impl> fc_grammar(tr);
}
template <typename T> template <typename T>
void geojson_datasource::parse_geojson(T & stream) void geojson_datasource::parse_geojson(T & stream)
{ {
using base_iterator_type = std::istreambuf_iterator<char>;
boost::spirit::multi_pass<base_iterator_type> begin = boost::spirit::multi_pass<base_iterator_type> begin =
boost::spirit::make_default_multi_pass(base_iterator_type(stream)); boost::spirit::make_default_multi_pass(base_iterator_type(stream));
boost::spirit::multi_pass<base_iterator_type> end = boost::spirit::multi_pass<base_iterator_type> end =
boost::spirit::make_default_multi_pass(base_iterator_type()); boost::spirit::make_default_multi_pass(base_iterator_type());
// FIXME - for perf we need to declare grammar as 'static const'
// but we cannot because then all features will interact only with the first context_ptr
// created in the process which leads to very odd bugs
mapnik::transcoder tr("utf8");
mapnik::json::feature_collection_grammar<boost::spirit::multi_pass<base_iterator_type>,mapnik::feature_impl> fc_grammar(tr);
boost::spirit::standard_wide::space_type space; boost::spirit::standard_wide::space_type space;
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>(); mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
bool result = boost::spirit::qi::phrase_parse(begin, end, (fc_grammar)(boost::phoenix::ref(ctx)), space, features_); bool result = boost::spirit::qi::phrase_parse(begin, end, (fc_grammar)(boost::phoenix::ref(ctx)), space, features_);
if (!result) if (!result)