Merge pull request #2231 from mapnik/fast-static-grammars
static grammars
This commit is contained in:
commit
cd4fdf17fe
25 changed files with 95 additions and 250 deletions
|
@ -30,42 +30,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class test2 : public benchmark::test_case
|
||||
{
|
||||
std::string expr_;
|
||||
public:
|
||||
test2(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::transcoder tr("utf-8");
|
||||
mapnik::expression_grammar<std::string::const_iterator> expr_grammar(tr);
|
||||
mapnik::expression_ptr expr = mapnik::parse_expression(expr_,expr_grammar);
|
||||
std::string result = mapnik::to_expression_string(*expr);
|
||||
bool ret = (result == expr_);
|
||||
if (!ret)
|
||||
{
|
||||
std::clog << result << " != " << expr_ << "\n";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
mapnik::transcoder tr("utf-8");
|
||||
mapnik::expression_grammar<std::string::const_iterator> expr_grammar(tr);
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
mapnik::expression_ptr expr = mapnik::parse_expression(expr_,expr_grammar);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
test test_runner(params);
|
||||
run(test_runner,"expr: grammer per parse");
|
||||
test2 test_runner2(params);
|
||||
return run(test_runner2,"expr: reuse grammar");
|
||||
run(test_runner,"expr parsing");
|
||||
}
|
||||
|
|
|
@ -33,9 +33,6 @@
|
|||
#include <mapnik/color_factory.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/expression.hpp>
|
||||
#include <mapnik/expression_string.hpp>
|
||||
#include <mapnik/expression_grammar.hpp>
|
||||
|
||||
#if defined(HAVE_CAIRO)
|
||||
#include <mapnik/cairo_renderer.hpp>
|
||||
|
@ -58,9 +55,6 @@ int main ( int argc , char** argv)
|
|||
datasource_cache::instance().register_datasources("plugins/input/");
|
||||
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.33/ttf/DejaVuSans.ttf");
|
||||
|
||||
mapnik::transcoder tr("utf-8");
|
||||
mapnik::expression_grammar<std::string::const_iterator> expr_grammar(tr);
|
||||
|
||||
Map m(800,600);
|
||||
m.set_background(parse_color("white"));
|
||||
m.set_srs(srs_merc);
|
||||
|
@ -70,7 +64,7 @@ int main ( int argc , char** argv)
|
|||
feature_type_style provpoly_style;
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[NAME_EN] = 'Ontario'", expr_grammar));
|
||||
r.set_filter(parse_expression("[NAME_EN] = 'Ontario'"));
|
||||
{
|
||||
polygon_symbolizer poly_sym;
|
||||
put(poly_sym, keys::fill, color(250, 190, 183));
|
||||
|
@ -80,7 +74,7 @@ int main ( int argc , char** argv)
|
|||
}
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[NOM_FR] = 'Québec'", expr_grammar));
|
||||
r.set_filter(parse_expression("[NOM_FR] = 'Québec'"));
|
||||
{
|
||||
polygon_symbolizer poly_sym;
|
||||
put(poly_sym, keys::fill, color(217, 235, 203));
|
||||
|
@ -113,7 +107,7 @@ int main ( int argc , char** argv)
|
|||
feature_type_style qcdrain_style;
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[HYC] = 8", expr_grammar));
|
||||
r.set_filter(parse_expression("[HYC] = 8"));
|
||||
{
|
||||
polygon_symbolizer poly_sym;
|
||||
put(poly_sym, keys::fill, color(153, 204, 255));
|
||||
|
@ -127,7 +121,7 @@ int main ( int argc , char** argv)
|
|||
feature_type_style roads34_style;
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4", expr_grammar));
|
||||
r.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(171,158,137));
|
||||
|
@ -144,7 +138,7 @@ int main ( int argc , char** argv)
|
|||
feature_type_style roads2_style_1;
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[CLASS] = 2", expr_grammar));
|
||||
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(171,158,137));
|
||||
|
@ -160,7 +154,7 @@ int main ( int argc , char** argv)
|
|||
feature_type_style roads2_style_2;
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[CLASS] = 2", expr_grammar));
|
||||
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(255,250,115));
|
||||
|
@ -177,7 +171,7 @@ int main ( int argc , char** argv)
|
|||
feature_type_style roads1_style_1;
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[CLASS] = 1", expr_grammar));
|
||||
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(188,149,28));
|
||||
|
@ -193,7 +187,7 @@ int main ( int argc , char** argv)
|
|||
feature_type_style roads1_style_2;
|
||||
{
|
||||
rule r;
|
||||
r.set_filter(parse_expression("[CLASS] = 1", expr_grammar));
|
||||
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(242,191,36));
|
||||
|
@ -218,7 +212,7 @@ int main ( int argc , char** argv)
|
|||
placement_finder->defaults.format->fill = color(0,0,0);
|
||||
placement_finder->defaults.format->halo_fill = color(255,255,200);
|
||||
placement_finder->defaults.format->halo_radius = 1;
|
||||
placement_finder->defaults.set_old_style_expression(parse_expression("[GEONAME]", expr_grammar));
|
||||
placement_finder->defaults.set_old_style_expression(parse_expression("[GEONAME]"));
|
||||
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
|
||||
r.append(std::move(text_sym));
|
||||
}
|
||||
|
|
|
@ -38,13 +38,10 @@ namespace mapnik
|
|||
{
|
||||
|
||||
// fwd declare to reduce compile time
|
||||
template <typename Iterator> struct expression_grammar;
|
||||
typedef std::shared_ptr<expr_node> expression_ptr;
|
||||
typedef std::set<expression_ptr> expression_set;
|
||||
|
||||
|
||||
MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt, std::string const& encoding = "UTF8");
|
||||
MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt, mapnik::expression_grammar<std::string::const_iterator> const& g);
|
||||
}
|
||||
|
||||
#endif // MAPNIK_EXPRESSION_HPP
|
||||
|
|
|
@ -127,10 +127,11 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
|
|||
{
|
||||
typedef qi::rule<Iterator, expr_node(), space_type> rule_type;
|
||||
|
||||
explicit expression_grammar(mapnik::transcoder const& tr);
|
||||
explicit expression_grammar(std::string const& encoding = "utf-8");
|
||||
|
||||
qi::real_parser<double, qi::strict_real_policies<double> > strict_double;
|
||||
typename integer_parser<mapnik::value_integer>::type int__;
|
||||
mapnik::transcoder tr_;
|
||||
boost::phoenix::function<unicode_impl> unicode_;
|
||||
boost::phoenix::function<regex_match_impl> regex_match_;
|
||||
boost::phoenix::function<regex_replace_impl> regex_replace_;
|
||||
|
|
|
@ -64,11 +64,12 @@ expr_node regex_replace_impl::operator() (T0 & node, T1 const& pattern, T2 const
|
|||
}
|
||||
|
||||
template <typename Iterator>
|
||||
expression_grammar<Iterator>::expression_grammar(mapnik::transcoder const& tr)
|
||||
expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
|
||||
: expression_grammar::base_type(expr),
|
||||
unicode_(unicode_impl(tr)),
|
||||
regex_match_(regex_match_impl(tr)),
|
||||
regex_replace_(regex_replace_impl(tr))
|
||||
tr_(encoding),
|
||||
unicode_(unicode_impl(tr_)),
|
||||
regex_match_(regex_match_impl(tr_)),
|
||||
regex_replace_(regex_replace_impl(tr_))
|
||||
{
|
||||
qi::_1_type _1;
|
||||
qi::_a_type _a;
|
||||
|
|
|
@ -34,12 +34,9 @@
|
|||
namespace mapnik {
|
||||
|
||||
// fwd declare to reduce compile time
|
||||
template <typename Iterator> struct path_expression_grammar;
|
||||
class feature_impl;
|
||||
|
||||
MAPNIK_DECL path_expression_ptr parse_path(std::string const & str);
|
||||
MAPNIK_DECL path_expression_ptr parse_path(std::string const & str,
|
||||
path_expression_grammar<std::string::const_iterator> const& g);
|
||||
|
||||
struct MAPNIK_DECL path_processor
|
||||
{
|
||||
|
|
|
@ -29,19 +29,8 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
template <typename Iterator> struct transform_expression_grammar;
|
||||
|
||||
typedef transform_expression_grammar<std::string::const_iterator>
|
||||
transform_expression_grammar_string;
|
||||
|
||||
MAPNIK_DECL transform_list_ptr parse_transform(std::string const& str);
|
||||
|
||||
MAPNIK_DECL transform_list_ptr parse_transform(std::string const& str,
|
||||
std::string const& encoding);
|
||||
|
||||
MAPNIK_DECL bool parse_transform(transform_list& list,
|
||||
std::string const& str,
|
||||
transform_expression_grammar_string const& g);
|
||||
std::string const& encoding="utf-8");
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
|
|
|
@ -35,11 +35,8 @@ namespace mapnik { namespace svg {
|
|||
bool parse_points(const char * wkt, PathType & p);
|
||||
|
||||
template <typename TransformType>
|
||||
bool MAPNIK_DECL parse_transform(const char * wkt, TransformType & tr);
|
||||
bool MAPNIK_DECL parse_svg_transform(const char * wkt, TransformType & tr);
|
||||
|
||||
//template <typename TransformType>
|
||||
//bool MAPNIK_DECL parse_transform(std::string const& wkt, TransformType & tr);
|
||||
|
||||
}}
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_SVG_PATH_PARSER_HPP
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace mapnik {
|
|||
struct transform_expression_grammar
|
||||
: qi::grammar<Iterator, transform_list(), space_type>
|
||||
{
|
||||
explicit transform_expression_grammar(expression_grammar<Iterator> const& g);
|
||||
explicit transform_expression_grammar();
|
||||
|
||||
typedef qi::rule<Iterator, transform_node(), space_type> node_rule;
|
||||
typedef qi::rule<Iterator, transform_list(), space_type> list_rule;
|
||||
|
@ -57,6 +57,7 @@ namespace mapnik {
|
|||
qi::rule<Iterator, transform_node(), space_type> rotate;
|
||||
qi::rule<Iterator, transform_node(), space_type> skewX;
|
||||
qi::rule<Iterator, transform_node(), space_type> skewY;
|
||||
mapnik::expression_grammar<Iterator> g_;
|
||||
};
|
||||
|
||||
} // namespace mapnik
|
||||
|
|
|
@ -160,7 +160,7 @@ struct do_xml_attribute_cast<mapnik::color>
|
|||
{
|
||||
static inline boost::optional<mapnik::color> xml_attribute_cast_impl(xml_tree const& tree, std::string const& source)
|
||||
{
|
||||
return parse_color(source, tree.color_grammar);
|
||||
return parse_color(source);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -187,7 +187,7 @@ struct do_xml_attribute_cast<mapnik::expression_ptr>
|
|||
}
|
||||
else
|
||||
{
|
||||
mapnik::expression_ptr expr = parse_expression(source, tree.expr_grammar);
|
||||
mapnik::expression_ptr expr = parse_expression(source);
|
||||
tree.expr_cache_.insert(std::make_pair(source,expr));
|
||||
return expr;
|
||||
}
|
||||
|
|
|
@ -26,20 +26,13 @@
|
|||
// mapnik
|
||||
#include <mapnik/xml_node.hpp>
|
||||
#include <mapnik/expression.hpp>
|
||||
#include <mapnik/expression_grammar.hpp>
|
||||
#include <mapnik/path_expression_grammar.hpp>
|
||||
#include <mapnik/transform_expression_grammar.hpp>
|
||||
#include <mapnik/image_filter_grammar.hpp>
|
||||
#include <mapnik/image_filter.hpp>
|
||||
#include <mapnik/css_color_grammar.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
|
||||
//stl
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
class xml_tree
|
||||
{
|
||||
public:
|
||||
|
@ -51,15 +44,8 @@ public:
|
|||
private:
|
||||
xml_node node_;
|
||||
std::string file_;
|
||||
transcoder tr_;
|
||||
public:
|
||||
mutable std::map<std::string,mapnik::expression_ptr> expr_cache_;
|
||||
mapnik::css_color_grammar<std::string::const_iterator> color_grammar;
|
||||
mapnik::expression_grammar<std::string::const_iterator> expr_grammar;
|
||||
path_expression_grammar<std::string::const_iterator> path_expr_grammar;
|
||||
transform_expression_grammar<std::string::const_iterator> transform_expr_grammar;
|
||||
image_filter_grammar<std::string::const_iterator,std::vector<filter::filter_type> > image_filters_grammar;
|
||||
|
||||
};
|
||||
|
||||
} //ns mapnik
|
||||
|
|
|
@ -423,8 +423,6 @@ void csv_datasource::parse_csv(T & stream,
|
|||
}
|
||||
|
||||
mapnik::transcoder tr(desc_.get_encoding());
|
||||
mapnik::wkt_parser parse_wkt;
|
||||
mapnik::json::geometry_parser<std::string::const_iterator> parse_json;
|
||||
|
||||
// handle rare case of a single line of data and user-provided headers
|
||||
// where a lack of a newline will mean that std::getline returns false
|
||||
|
@ -543,7 +541,7 @@ void csv_datasource::parse_csv(T & stream,
|
|||
break;
|
||||
}
|
||||
|
||||
if (parse_wkt.parse(value, feature->paths()))
|
||||
if (mapnik::from_wkt(value, feature->paths()))
|
||||
{
|
||||
parsed_wkt = true;
|
||||
}
|
||||
|
@ -578,7 +576,7 @@ void csv_datasource::parse_csv(T & stream,
|
|||
{
|
||||
break;
|
||||
}
|
||||
if (parse_json.parse(value.begin(),value.end(), feature->paths()))
|
||||
if (mapnik::json::from_geojson(value, feature->paths()))
|
||||
{
|
||||
parsed_json = true;
|
||||
}
|
||||
|
@ -686,7 +684,7 @@ void csv_datasource::parse_csv(T & stream,
|
|||
(value_length > 1 && !has_dot && value[0] == '0'))
|
||||
{
|
||||
matched = true;
|
||||
feature->put(fld_name,tr.transcode(value.c_str()));
|
||||
feature->put(fld_name,std::move(tr.transcode(value.c_str())));
|
||||
if (feature_count == 1)
|
||||
{
|
||||
desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String));
|
||||
|
@ -732,7 +730,7 @@ void csv_datasource::parse_csv(T & stream,
|
|||
if (!matched)
|
||||
{
|
||||
// fallback to normal string
|
||||
feature->put(fld_name,tr.transcode(value.c_str()));
|
||||
feature->put(fld_name,std::move(tr.transcode(value.c_str())));
|
||||
if (feature_count == 1)
|
||||
{
|
||||
desc_.add_descriptor(
|
||||
|
|
|
@ -132,6 +132,8 @@ geojson_datasource::geojson_datasource(parameters const& params)
|
|||
|
||||
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
|
||||
mapnik::json::generic_json<boost::spirit::multi_pass<base_iterator_type> > json;
|
||||
// TODO - make it possible for this to be static const
|
||||
// by avoiding ctor taking arg - https://github.com/mapnik/mapnik/pull/2231
|
||||
mapnik::json::feature_collection_parser<boost::spirit::multi_pass<base_iterator_type> > p(json, ctx,*tr_);
|
||||
bool result = p.parse(begin,end, features_);
|
||||
if (!result)
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace mapnik {
|
|||
|
||||
color parse_color(std::string const& str)
|
||||
{
|
||||
css_color_grammar<std::string::const_iterator> g;
|
||||
static const css_color_grammar<std::string::const_iterator> g;
|
||||
return parse_color(str, g);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,14 +35,7 @@ namespace mapnik
|
|||
|
||||
expression_ptr parse_expression(std::string const& str, std::string const& encoding)
|
||||
{
|
||||
transcoder tr(encoding);
|
||||
expression_grammar<std::string::const_iterator> g(tr);
|
||||
return parse_expression(str, g);
|
||||
}
|
||||
|
||||
expression_ptr parse_expression(std::string const& str,
|
||||
mapnik::expression_grammar<std::string::const_iterator> const& g)
|
||||
{
|
||||
static const expression_grammar<std::string::const_iterator> g;
|
||||
boost::spirit::standard_wide::space_type space;
|
||||
auto node = std::make_shared<expr_node>();
|
||||
std::string::const_iterator itr = str.begin();
|
||||
|
|
|
@ -46,7 +46,7 @@ bool parse_image_filters(std::string const& filters, std::vector<filter_type>& i
|
|||
{
|
||||
std::string::const_iterator itr = filters.begin();
|
||||
std::string::const_iterator end = filters.end();
|
||||
mapnik::image_filter_grammar<std::string::const_iterator,
|
||||
static const mapnik::image_filter_grammar<std::string::const_iterator,
|
||||
std::vector<mapnik::filter::filter_type> > filter_grammar;
|
||||
boost::spirit::qi::ascii::space_type space;
|
||||
bool r = boost::spirit::qi::phrase_parse(itr,end,
|
||||
|
|
|
@ -42,20 +42,21 @@ template <typename Iterator>
|
|||
geometry_parser<Iterator>::~geometry_parser() {}
|
||||
|
||||
template <typename Iterator>
|
||||
bool geometry_parser<Iterator>::parse(iterator_type first, iterator_type last, boost::ptr_vector<mapnik::geometry_type>& path)
|
||||
bool geometry_parser<Iterator>::parse(iterator_type first, iterator_type last, boost::ptr_vector<mapnik::geometry_type>& paths)
|
||||
{
|
||||
using namespace boost::spirit;
|
||||
standard_wide::space_type space;
|
||||
return qi::phrase_parse(first, last, (*grammar_)(boost::phoenix::ref(path)), space);
|
||||
return qi::phrase_parse(first, last, (*grammar_)(boost::phoenix::ref(paths)), space);
|
||||
}
|
||||
|
||||
|
||||
bool from_geojson(std::string const& json, boost::ptr_vector<geometry_type> & paths)
|
||||
{
|
||||
geometry_parser<std::string::const_iterator> parser;
|
||||
using namespace boost::spirit;
|
||||
static const geometry_grammar<std::string::const_iterator> g;
|
||||
standard_wide::space_type space;
|
||||
std::string::const_iterator start = json.begin();
|
||||
std::string::const_iterator end = json.end();
|
||||
return parser.parse(start, end ,paths);
|
||||
return qi::phrase_parse(start, end, (g)(boost::phoenix::ref(paths)), space);
|
||||
}
|
||||
|
||||
template class geometry_parser<std::string::const_iterator> ;
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
#include <mapnik/image_filter_types.hpp>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/group/group_rule.hpp>
|
||||
|
||||
#include <mapnik/transform_expression.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/optional.hpp>
|
||||
|
@ -452,18 +452,9 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
|
|||
optional<std::string> filters = sty.get_opt_attr<std::string>("image-filters");
|
||||
if (filters)
|
||||
{
|
||||
std::string::const_iterator itr = filters->begin();
|
||||
std::string::const_iterator end = filters->end();
|
||||
boost::spirit::qi::ascii::space_type space;
|
||||
bool result = boost::spirit::qi::phrase_parse(itr,end,
|
||||
sty.get_tree().image_filters_grammar,
|
||||
space,
|
||||
style.image_filters());
|
||||
if (!result || itr!=end)
|
||||
{
|
||||
throw config_error("failed to parse image-filters: '" + std::string(itr,end) + "'");
|
||||
if (!parse_image_filters(*filters, style.image_filters())) {
|
||||
throw config_error("failed to parse image-filters: '" + *filters + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// direct image filters (applied directly on main image buffer
|
||||
|
@ -473,16 +464,8 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
|
|||
optional<std::string> direct_filters = sty.get_opt_attr<std::string>("direct-image-filters");
|
||||
if (direct_filters)
|
||||
{
|
||||
std::string::const_iterator itr = direct_filters->begin();
|
||||
std::string::const_iterator end = direct_filters->end();
|
||||
boost::spirit::qi::ascii::space_type space;
|
||||
bool result = boost::spirit::qi::phrase_parse(itr,end,
|
||||
sty.get_tree().image_filters_grammar,
|
||||
space,
|
||||
style.direct_image_filters());
|
||||
if (!result || itr!=end)
|
||||
{
|
||||
throw config_error("failed to parse direct-image-filters: '" + std::string(itr,end) + "'");
|
||||
if (!parse_image_filters(*direct_filters, style.direct_image_filters())) {
|
||||
throw config_error("failed to parse direct-image-filters: '" + *direct_filters + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -902,14 +885,7 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt)
|
|||
optional<std::string> geometry_transform_wkt = pt.get_opt_attr<std::string>("geometry-transform");
|
||||
if (geometry_transform_wkt)
|
||||
{
|
||||
mapnik::transform_list_ptr tl = std::make_shared<mapnik::transform_list>();
|
||||
if (!mapnik::parse_transform(*tl, *geometry_transform_wkt, pt.get_tree().transform_expr_grammar))
|
||||
{
|
||||
std::string ss("Could not parse transform from '");
|
||||
ss += *geometry_transform_wkt + "', expected transform attribute";
|
||||
throw config_error(ss);
|
||||
}
|
||||
put(sym, keys::geometry_transform, tl);
|
||||
put(sym, keys::geometry_transform, mapnik::parse_transform(*geometry_transform_wkt));
|
||||
}
|
||||
|
||||
// clip
|
||||
|
@ -966,16 +942,11 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym)
|
|||
*file = ensure_relative_to_xml(file);
|
||||
std::string filename = *file;
|
||||
ensure_exists(filename);
|
||||
put(symbol, keys::file, parse_path(filename, sym.get_tree().path_expr_grammar));
|
||||
put(symbol, keys::file, parse_path(filename));
|
||||
|
||||
if (image_transform_wkt)
|
||||
{
|
||||
mapnik::transform_list_ptr tl = std::make_shared<mapnik::transform_list>();
|
||||
if (!mapnik::parse_transform(*tl, *image_transform_wkt, sym.get_tree().transform_expr_grammar))
|
||||
{
|
||||
throw mapnik::config_error("Failed to parse transform: '" + *image_transform_wkt + "'");
|
||||
}
|
||||
put(symbol, keys::image_transform, tl);
|
||||
put(symbol, keys::image_transform, mapnik::parse_transform(*image_transform_wkt));
|
||||
}
|
||||
}
|
||||
parse_symbolizer_base(symbol, sym);
|
||||
|
@ -1035,7 +1006,7 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
|
|||
if (!filename.empty())
|
||||
{
|
||||
ensure_exists(filename);
|
||||
put(symbol,keys::file, parse_path(filename, sym.get_tree().path_expr_grammar));
|
||||
put(symbol,keys::file, parse_path(filename));
|
||||
}
|
||||
|
||||
// overall opacity to be applied to all paths
|
||||
|
@ -1047,12 +1018,7 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
|
|||
optional<std::string> image_transform_wkt = sym.get_opt_attr<std::string>("transform");
|
||||
if (image_transform_wkt)
|
||||
{
|
||||
mapnik::transform_list_ptr tl = std::make_shared<mapnik::transform_list>();
|
||||
if (!mapnik::parse_transform(*tl, *image_transform_wkt, sym.get_tree().transform_expr_grammar))
|
||||
{
|
||||
throw mapnik::config_error("Failed to parse transform: '" + *image_transform_wkt + "'");
|
||||
}
|
||||
put(symbol, keys::image_transform, tl);
|
||||
put(symbol, keys::image_transform, mapnik::parse_transform(*image_transform_wkt));
|
||||
}
|
||||
|
||||
optional<color> c = sym.get_opt_attr<color>("fill");
|
||||
|
@ -1116,7 +1082,7 @@ void map_parser::parse_line_pattern_symbolizer(rule & rule, xml_node const & sym
|
|||
file = ensure_relative_to_xml(file);
|
||||
ensure_exists(file);
|
||||
line_pattern_symbolizer symbol;
|
||||
put(symbol, keys::file, parse_path(file, sym.get_tree().path_expr_grammar));
|
||||
put(symbol, keys::file, parse_path(file));
|
||||
|
||||
// offset value
|
||||
optional<double> offset = sym.get_opt_attr<double>("offset");
|
||||
|
@ -1158,7 +1124,7 @@ void map_parser::parse_polygon_pattern_symbolizer(rule & rule,
|
|||
file = ensure_relative_to_xml(file);
|
||||
ensure_exists(file);
|
||||
polygon_pattern_symbolizer symbol;
|
||||
put(symbol, keys::file, parse_path(file, sym.get_tree().path_expr_grammar));
|
||||
put(symbol, keys::file, parse_path(file));
|
||||
|
||||
// pattern alignment
|
||||
optional<pattern_alignment_e> p_alignment = sym.get_opt_attr<pattern_alignment_e>("alignment");
|
||||
|
@ -1215,12 +1181,7 @@ void map_parser::parse_text_symbolizer(rule & rule, xml_node const& sym)
|
|||
optional<std::string> halo_transform_wkt = sym.get_opt_attr<std::string>("halo-transform");
|
||||
if (halo_transform_wkt)
|
||||
{
|
||||
mapnik::transform_list_ptr tl = std::make_shared<mapnik::transform_list>();
|
||||
if (!mapnik::parse_transform(*tl, *halo_transform_wkt, sym.get_tree().transform_expr_grammar))
|
||||
{
|
||||
throw mapnik::config_error("Failed to parse halo-transform: '" + *halo_transform_wkt + "'");
|
||||
}
|
||||
put(text_symbol, keys::halo_transform, tl);
|
||||
put(text_symbol, keys::halo_transform, mapnik::parse_transform(*halo_transform_wkt));
|
||||
}
|
||||
|
||||
rule.append(std::move(text_symbol));
|
||||
|
@ -1256,12 +1217,7 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym)
|
|||
optional<std::string> image_transform_wkt = sym.get_opt_attr<std::string>("transform");
|
||||
if (image_transform_wkt)
|
||||
{
|
||||
mapnik::transform_list_ptr tl = std::make_shared<mapnik::transform_list>();
|
||||
if (!mapnik::parse_transform(*tl, *image_transform_wkt, sym.get_tree().transform_expr_grammar))
|
||||
{
|
||||
throw mapnik::config_error("Failed to parse transform: '" + *image_transform_wkt + "'");
|
||||
}
|
||||
put(shield_symbol, keys::image_transform, tl);
|
||||
put(shield_symbol, keys::image_transform, mapnik::parse_transform(*image_transform_wkt));
|
||||
}
|
||||
|
||||
// shield displacement
|
||||
|
@ -1310,7 +1266,7 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym)
|
|||
|
||||
file = ensure_relative_to_xml(file);
|
||||
ensure_exists(file);
|
||||
put(shield_symbol, keys::file , parse_path(file, sym.get_tree().path_expr_grammar));
|
||||
put(shield_symbol, keys::file , parse_path(file));
|
||||
parse_symbolizer_base(shield_symbol, sym);
|
||||
optional<halo_rasterizer_e> halo_rasterizer_ = sym.get_opt_attr<halo_rasterizer_e>("halo-rasterizer");
|
||||
if (halo_rasterizer_) put(shield_symbol, keys::halo_rasterizer, halo_rasterizer_enum(*halo_rasterizer_));
|
||||
|
|
|
@ -31,30 +31,22 @@
|
|||
// boost
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
path_expression_ptr parse_path(std::string const& str)
|
||||
{
|
||||
path_expression_grammar<std::string::const_iterator> g;
|
||||
return parse_path(str,g);
|
||||
}
|
||||
|
||||
path_expression_ptr parse_path(std::string const& str,
|
||||
path_expression_grammar<std::string::const_iterator> const& g)
|
||||
{
|
||||
path_expression path;
|
||||
static const path_expression_grammar<std::string::const_iterator> g;
|
||||
auto path = std::make_shared<path_expression>();
|
||||
boost::spirit::standard_wide::space_type space;
|
||||
std::string::const_iterator itr = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
bool r = qi::phrase_parse(itr, end, g, space, path);
|
||||
if (r && itr == end)
|
||||
bool r = qi::phrase_parse(itr, end, g, space, *path);
|
||||
if (r && itr == end)
|
||||
{
|
||||
return std::make_shared<path_expression>(path); //path;
|
||||
return path;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -23,44 +23,29 @@
|
|||
#include <mapnik/parse_transform.hpp>
|
||||
#include <mapnik/transform_expression_grammar.hpp>
|
||||
#include <mapnik/transform_processor.hpp>
|
||||
#include <mapnik/debug.hpp>
|
||||
|
||||
// stl
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
transform_list_ptr parse_transform(std::string const& str)
|
||||
{
|
||||
return parse_transform(str, "utf-8");
|
||||
}
|
||||
|
||||
transform_list_ptr parse_transform(std::string const& str, std::string const& encoding)
|
||||
{
|
||||
static const transform_expression_grammar<std::string::const_iterator> g;
|
||||
transform_list_ptr tl = std::make_shared<transform_list>();
|
||||
transcoder tc(encoding);
|
||||
expression_grammar<std::string::const_iterator> ge(tc);
|
||||
transform_expression_grammar_string gte(ge);
|
||||
|
||||
if (!parse_transform(*tl, str, gte))
|
||||
{
|
||||
tl.reset();
|
||||
}
|
||||
return tl;
|
||||
}
|
||||
|
||||
bool parse_transform(transform_list& transform,
|
||||
std::string const& str,
|
||||
transform_expression_grammar_string const& g)
|
||||
{
|
||||
std::string::const_iterator itr = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
bool r = qi::phrase_parse(itr, end, g, space_type(), transform);
|
||||
|
||||
#ifdef MAPNIK_LOG
|
||||
MAPNIK_LOG_DEBUG(load_map) << "map_parser: Parsed transform [ "
|
||||
<< transform_processor_type::to_string(transform) << " ]";
|
||||
#endif
|
||||
|
||||
return (r && itr==end);
|
||||
bool r = qi::phrase_parse(itr, end, g, space_type(), *tl);
|
||||
if (r && itr == end)
|
||||
{
|
||||
return tl;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Failed to parse transform: \"" + str + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace mapnik
|
||||
|
|
|
@ -303,7 +303,7 @@ void parse_attr(svg_parser & parser, const xmlChar * name, const xmlChar * value
|
|||
if (xmlStrEqual(name, BAD_CAST "transform"))
|
||||
{
|
||||
agg::trans_affine tr;
|
||||
mapnik::svg::parse_transform((const char*) value,tr);
|
||||
mapnik::svg::parse_svg_transform((const char*) value,tr);
|
||||
parser.path_.transform().premultiply(tr);
|
||||
}
|
||||
else if (xmlStrEqual(name, BAD_CAST "fill"))
|
||||
|
@ -911,7 +911,7 @@ bool parse_common_gradient(svg_parser & parser, xmlTextReaderPtr reader)
|
|||
if (value)
|
||||
{
|
||||
agg::trans_affine tr;
|
||||
mapnik::svg::parse_transform((const char*) value,tr);
|
||||
mapnik::svg::parse_svg_transform((const char*) value,tr);
|
||||
parser.temporary_gradient_.second.set_transform(tr);
|
||||
xmlFree(value);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
// mapnik
|
||||
#include <mapnik/svg/svg_path_parser.hpp>
|
||||
#include <mapnik/svg/svg_transform_grammar.hpp>
|
||||
// agg
|
||||
#include "agg_trans_affine.h"
|
||||
// stl
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
@ -32,32 +30,18 @@
|
|||
namespace mapnik { namespace svg {
|
||||
|
||||
template <typename TransformType>
|
||||
bool parse_transform(const char * wkt, TransformType & p)
|
||||
bool parse_svg_transform(const char * wkt, TransformType & p)
|
||||
{
|
||||
using namespace boost::spirit;
|
||||
typedef const char * iterator_type;
|
||||
typedef ascii::space_type skip_type;
|
||||
// TODO - make it possible for this to be static const
|
||||
// by avoiding ctor taking arg - https://github.com/mapnik/mapnik/pull/2231
|
||||
svg_transform_grammar<iterator_type,skip_type,TransformType> g(p);
|
||||
iterator_type first = wkt;
|
||||
iterator_type last = wkt + std::strlen(wkt);
|
||||
return qi::phrase_parse(first, last, g, skip_type());
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename TransformType>
|
||||
bool parse_transform(std::string const& wkt, TransformType & p)
|
||||
{
|
||||
using namespace boost::spirit;
|
||||
typedef std::string::const_iterator iterator_type;
|
||||
typedef ascii::space_type skip_type;
|
||||
svg_transform_grammar<iterator_type,skip_type,TransformType> g(p);
|
||||
iterator_type first = wkt.begin();
|
||||
iterator_type last = wkt.end();
|
||||
return qi::phrase_parse(first, last, g, skip_type());
|
||||
}
|
||||
*/
|
||||
|
||||
template MAPNIK_DECL bool parse_transform<agg::trans_affine>(const char*, agg::trans_affine&);
|
||||
//template bool parse_transform<agg::trans_affine>(std::string const& , agg::trans_affine&);
|
||||
|
||||
}}
|
||||
template MAPNIK_DECL bool parse_svg_transform<agg::trans_affine>(const char*, agg::trans_affine&);
|
||||
}}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace mapnik {
|
|||
namespace qi = boost::spirit::qi;
|
||||
|
||||
template <typename Iterator>
|
||||
transform_expression_grammar<Iterator>::transform_expression_grammar(expression_grammar<Iterator> const& g)
|
||||
transform_expression_grammar<Iterator>::transform_expression_grammar()
|
||||
: transform_expression_grammar::base_type(start)
|
||||
{
|
||||
using boost::phoenix::construct;
|
||||
|
@ -123,8 +123,8 @@ transform_expression_grammar<Iterator>::transform_expression_grammar(expression_
|
|||
// expressions are separated by a comma.
|
||||
sep_expr = lit(',') >> expr [ _val = _1 ];
|
||||
|
||||
attr = g.attr.alias();
|
||||
expr = g.expr.alias();
|
||||
attr = g_.attr.alias();
|
||||
expr = g_.expr.alias();
|
||||
}
|
||||
|
||||
template struct mapnik::transform_expression_grammar<std::string::const_iterator>;
|
||||
|
|
|
@ -47,8 +47,12 @@ bool wkt_parser::parse(std::string const& wkt, boost::ptr_vector<geometry_type>
|
|||
|
||||
bool from_wkt(std::string const& wkt, boost::ptr_vector<geometry_type> & paths)
|
||||
{
|
||||
wkt_parser parser;
|
||||
return parser.parse(wkt,paths);
|
||||
using namespace boost::spirit;
|
||||
static const mapnik::wkt::wkt_collection_grammar<std::string::const_iterator> g;
|
||||
ascii::space_type space;
|
||||
std::string::const_iterator first = wkt.begin();
|
||||
std::string::const_iterator last = wkt.end();
|
||||
return qi::phrase_parse(first, last, g, space, paths);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
//mapnik
|
||||
#include <mapnik/std.hpp>
|
||||
#include <mapnik/xml_tree.hpp>
|
||||
#include <mapnik/xml_attribute_cast.hpp>
|
||||
#include <mapnik/util/conversions.hpp>
|
||||
|
@ -32,6 +33,9 @@
|
|||
#include <mapnik/text/text_properties.hpp>
|
||||
#include <mapnik/config_error.hpp>
|
||||
#include <mapnik/raster_colorizer.hpp>
|
||||
|
||||
#include <mapnik/expression.hpp>
|
||||
|
||||
// stl
|
||||
#include <type_traits>
|
||||
|
||||
|
@ -95,13 +99,7 @@ struct name_trait< mapnik::enumeration<ENUM, MAX> >
|
|||
|
||||
xml_tree::xml_tree(std::string const& encoding)
|
||||
: node_(*this, "<root>"),
|
||||
file_(),
|
||||
tr_(encoding),
|
||||
color_grammar(),
|
||||
expr_grammar(tr_),
|
||||
path_expr_grammar(),
|
||||
transform_expr_grammar(expr_grammar),
|
||||
image_filters_grammar()
|
||||
file_()
|
||||
{
|
||||
node_.set_processed(true); //root node is always processed
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue