topojson grammar - change interface + instantiate with Iterator = char const*
to reduce binary size
This commit is contained in:
parent
f360f50eed
commit
af099a57ef
4 changed files with 11 additions and 10 deletions
|
@ -160,7 +160,7 @@ topojson_datasource::topojson_datasource(parameters const& params)
|
||||||
}
|
}
|
||||||
if (!inline_string_.empty())
|
if (!inline_string_.empty())
|
||||||
{
|
{
|
||||||
parse_topojson(inline_string_);
|
parse_topojson(inline_string_.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -172,20 +172,22 @@ topojson_datasource::topojson_datasource(parameters const& params)
|
||||||
std::string file_buffer;
|
std::string file_buffer;
|
||||||
file_buffer.resize(file.size());
|
file_buffer.resize(file.size());
|
||||||
std::fread(&file_buffer[0], file.size(), 1, file.get());
|
std::fread(&file_buffer[0], file.size(), 1, file.get());
|
||||||
parse_topojson(file_buffer);
|
parse_topojson(file_buffer.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using base_iterator_type = std::string::const_iterator;
|
using iterator_type = const char*;
|
||||||
const mapnik::topojson::topojson_grammar<base_iterator_type> g;
|
const mapnik::topojson::topojson_grammar<iterator_type> g;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void topojson_datasource::parse_topojson(T const& buffer)
|
void topojson_datasource::parse_topojson(T const& buffer)
|
||||||
{
|
{
|
||||||
boost::spirit::standard::space_type space;
|
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)
|
if (!result)
|
||||||
{
|
{
|
||||||
throw mapnik::datasource_exception("topojson_datasource: Failed parse TopoJSON file '" + filename_ + "'");
|
throw mapnik::datasource_exception("topojson_datasource: Failed parse TopoJSON file '" + filename_ + "'");
|
||||||
|
|
|
@ -61,4 +61,3 @@ generic_json<Iterator>::generic_json()
|
||||||
|
|
||||||
using iterator_type = char const*;
|
using iterator_type = char const*;
|
||||||
template struct mapnik::json::generic_json<iterator_type>;
|
template struct mapnik::json::generic_json<iterator_type>;
|
||||||
template struct mapnik::json::generic_json<std::string::const_iterator>;
|
|
||||||
|
|
|
@ -24,5 +24,5 @@
|
||||||
#include <mapnik/json/topojson_grammar_impl.hpp>
|
#include <mapnik/json/topojson_grammar_impl.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using iterator_type = std::string::const_iterator;
|
using iterator_type = char const*;
|
||||||
template struct mapnik::topojson::topojson_grammar<iterator_type> ;
|
template struct mapnik::topojson::topojson_grammar<iterator_type> ;
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using iterator_type = std::string::const_iterator;
|
using iterator_type = char const*;
|
||||||
const mapnik::topojson::topojson_grammar<iterator_type> grammar;
|
const mapnik::topojson::topojson_grammar<iterator_type> grammar;
|
||||||
|
|
||||||
bool parse_topology(std::string const& filename, mapnik::topojson::topology & topo)
|
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());
|
std::fread(&buffer[0], buffer.size(), 1, file.get());
|
||||||
if (!file) return false;
|
if (!file) return false;
|
||||||
boost::spirit::standard::space_type space;
|
boost::spirit::standard::space_type space;
|
||||||
iterator_type itr = buffer.begin();
|
iterator_type itr = buffer.c_str();
|
||||||
iterator_type end = buffer.end();
|
iterator_type end = itr + buffer.length();
|
||||||
bool result = boost::spirit::qi::phrase_parse(itr, end, grammar, space, topo);
|
bool result = boost::spirit::qi::phrase_parse(itr, end, grammar, space, topo);
|
||||||
return (result && (itr == end));
|
return (result && (itr == end));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue