topojson grammar - change interface + instantiate with Iterator = char const* to reduce binary size

This commit is contained in:
artemp 2016-08-31 17:42:18 +01:00
parent f360f50eed
commit af099a57ef
4 changed files with 11 additions and 10 deletions

View file

@ -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<base_iterator_type> g;
using iterator_type = const char*;
const mapnik::topojson::topojson_grammar<iterator_type> g;
}
template <typename T>
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_ + "'");

View file

@ -61,4 +61,3 @@ generic_json<Iterator>::generic_json()
using iterator_type = char const*;
template struct mapnik::json::generic_json<iterator_type>;
template struct mapnik::json::generic_json<std::string::const_iterator>;

View file

@ -24,5 +24,5 @@
#include <mapnik/json/topojson_grammar_impl.hpp>
#include <string>
using iterator_type = std::string::const_iterator;
using iterator_type = char const*;
template struct mapnik::topojson::topojson_grammar<iterator_type> ;

View file

@ -31,7 +31,7 @@
namespace {
using iterator_type = std::string::const_iterator;
using iterator_type = char const*;
const mapnik::topojson::topojson_grammar<iterator_type> 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));
}