diff --git a/include/mapnik/parse_path.hpp b/include/mapnik/parse_path.hpp index 828c0204f..90b065ac9 100644 --- a/include/mapnik/parse_path.hpp +++ b/include/mapnik/parse_path.hpp @@ -28,6 +28,7 @@ #include #include #include +#include // boost #include @@ -40,16 +41,11 @@ namespace mapnik { -typedef boost::variant path_component; -typedef std::vector path_expression; typedef boost::shared_ptr path_expression_ptr; -template struct path_expression_grammar; MAPNIK_DECL path_expression_ptr parse_path(std::string const & str); -MAPNIK_DECL bool parse_path_from_string(path_expression_ptr const& path, - std::string const & str, - path_expression_grammar const& g); - +MAPNIK_DECL path_expression_ptr parse_path(std::string const & str, + path_expression_grammar const& g); template struct path_processor diff --git a/include/mapnik/path_expression_grammar.hpp b/include/mapnik/path_expression_grammar.hpp index f60f33feb..58f8345a2 100644 --- a/include/mapnik/path_expression_grammar.hpp +++ b/include/mapnik/path_expression_grammar.hpp @@ -39,14 +39,16 @@ namespace mapnik { + using namespace boost; namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; namespace standard_wide = boost::spirit::standard_wide; using standard_wide::space_type; -using standard_wide::space; + typedef boost::variant path_component; +typedef std::vector path_expression; template struct path_expression_grammar : qi::grammar(), space_type> diff --git a/src/load_map.cpp b/src/load_map.cpp index d8ec28825..f7efc5488 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -899,13 +899,7 @@ 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); - path_expression_ptr expr(boost::make_shared()); - if (!parse_path_from_string(expr, filename, sym.get_tree().path_expr_grammar)) - { - throw mapnik::config_error("Failed to parse path_expression '" + filename + "'"); - } - - symbol.set_filename(expr); + symbol.set_filename( parse_path(filename, sym.get_tree().path_expr_grammar) ); optional image_transform_wkt = sym.get_opt_attr("transform"); if (image_transform_wkt) @@ -928,14 +922,13 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym) } } - -void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& node) +void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym) { try { std::string filename(""); - optional file = node.get_opt_attr("file"); - optional base = node.get_opt_attr("base"); + optional file = sym.get_opt_attr("file"); + optional base = sym.get_opt_attr("base"); if (file && !file->empty()) { @@ -951,7 +944,7 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& node) filename = ensure_relative_to_xml(file); } - optional marker_type = node.get_opt_attr("marker-type"); + optional marker_type = sym.get_opt_attr("marker-type"); if (marker_type) { // TODO - revisit whether to officially deprecate marker-type @@ -971,68 +964,67 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& node) } } - markers_symbolizer sym; + markers_symbolizer symbol; if (!filename.empty()) { ensure_exists(filename); - path_expression_ptr expr(boost::make_shared()); - if (!parse_path_from_string(expr, filename, node.get_tree().path_expr_grammar)) - { - throw mapnik::config_error("Failed to parse path_expression '" + filename + "'"); - } - sym.set_filename(expr); + symbol.set_filename( parse_path(filename, sym.get_tree().path_expr_grammar) ); } // overall opacity to be applied to all paths - optional opacity = node.get_opt_attr("opacity"); - if (opacity) sym.set_opacity(*opacity); + optional opacity = sym.get_opt_attr("opacity"); + if (opacity) symbol.set_opacity(*opacity); - optional fill_opacity = node.get_opt_attr("fill-opacity"); - if (fill_opacity) sym.set_fill_opacity(*fill_opacity); + optional fill_opacity = sym.get_opt_attr("fill-opacity"); + if (fill_opacity) symbol.set_fill_opacity(*fill_opacity); - optional image_transform_wkt = node.get_opt_attr("transform"); + optional image_transform_wkt = sym.get_opt_attr("transform"); if (image_transform_wkt) { mapnik::transform_list_ptr tl = boost::make_shared(); - if (!mapnik::parse_transform(*tl, *image_transform_wkt, node.get_tree().transform_expr_grammar)) + 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 + "'"); } - sym.set_image_transform(tl); + symbol.set_image_transform(tl); } - optional c = node.get_opt_attr("fill"); - if (c) sym.set_fill(*c); - optional spacing = node.get_opt_attr("spacing"); - if (spacing) sym.set_spacing(*spacing); - optional max_error = node.get_opt_attr("max-error"); - if (max_error) sym.set_max_error(*max_error); - optional allow_overlap = node.get_opt_attr("allow-overlap"); - optional ignore_placement = node.get_opt_attr("ignore-placement"); - if (allow_overlap) sym.set_allow_overlap(*allow_overlap); - if (ignore_placement) sym.set_ignore_placement(*ignore_placement); + optional c = sym.get_opt_attr("fill"); + if (c) symbol.set_fill(*c); + + optional spacing = sym.get_opt_attr("spacing"); + if (spacing) symbol.set_spacing(*spacing); + + optional max_error = sym.get_opt_attr("max-error"); + if (max_error) symbol.set_max_error(*max_error); + + optional allow_overlap = sym.get_opt_attr("allow-overlap"); + if (allow_overlap) symbol.set_allow_overlap(*allow_overlap); + + optional ignore_placement = sym.get_opt_attr("ignore-placement"); + if (ignore_placement) symbol.set_ignore_placement(*ignore_placement); - optional width = node.get_opt_attr("width"); - if (width) sym.set_width(*width); + optional width = sym.get_opt_attr("width"); + if (width) symbol.set_width(*width); - optional height = node.get_opt_attr("height"); - if (height) sym.set_height(*height); + optional height = sym.get_opt_attr("height"); + if (height) symbol.set_height(*height); stroke strk; - if (parse_stroke(strk,node)) + if (parse_stroke(strk,sym)) { - sym.set_stroke(strk); + symbol.set_stroke(strk); } - marker_placement_e placement = node.get_attr("placement",sym.get_marker_placement()); - sym.set_marker_placement(placement); - parse_symbolizer_base(sym, node); - rule.append(sym); + marker_placement_e placement = sym.get_attr("placement",symbol.get_marker_placement()); + symbol.set_marker_placement(placement); + parse_symbolizer_base(symbol, sym); + rule.append(symbol); } catch (config_error const& ex) { - ex.append_context(node); + ex.append_context(sym); throw; } } @@ -1060,12 +1052,7 @@ void map_parser::parse_line_pattern_symbolizer(rule & rule, xml_node const & sym file = ensure_relative_to_xml(file); ensure_exists(file); - path_expression_ptr expr(boost::make_shared()); - if (!parse_path_from_string(expr, file, sym.get_tree().path_expr_grammar)) - { - throw mapnik::config_error("Failed to parse path_expression '" + file + "'"); - } - line_pattern_symbolizer symbol(expr); + line_pattern_symbolizer symbol( parse_path(file, sym.get_tree().path_expr_grammar) ); parse_symbolizer_base(symbol, sym); rule.append(symbol); @@ -1102,12 +1089,7 @@ void map_parser::parse_polygon_pattern_symbolizer(rule & rule, file = ensure_relative_to_xml(file); ensure_exists(file); - path_expression_ptr expr(boost::make_shared()); - if (!parse_path_from_string(expr, file, sym.get_tree().path_expr_grammar)) - { - throw mapnik::config_error("Failed to parse path_expression '" + file + "'"); - } - polygon_pattern_symbolizer symbol(expr); + polygon_pattern_symbolizer symbol( parse_path(file, sym.get_tree().path_expr_grammar) ); // pattern alignment pattern_alignment_e p_alignment = sym.get_attr("alignment",LOCAL_ALIGNMENT); @@ -1254,12 +1236,7 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym) file = ensure_relative_to_xml(file); ensure_exists(file); - path_expression_ptr expr(boost::make_shared()); - if (!parse_path_from_string(expr, file, sym.get_tree().path_expr_grammar)) - { - throw mapnik::config_error("Failed to parse path_expression '" + file + "'"); - } - shield_symbol.set_filename(expr); + shield_symbol.set_filename( parse_path(file, sym.get_tree().path_expr_grammar) ); parse_symbolizer_base(shield_symbol, sym); rule.append(shield_symbol); } diff --git a/src/parse_path.cpp b/src/parse_path.cpp index 9e564653a..7932710ff 100644 --- a/src/parse_path.cpp +++ b/src/parse_path.cpp @@ -29,12 +29,18 @@ namespace mapnik { path_expression_ptr parse_path(std::string const & str) { - path_expression_ptr path = boost::make_shared(); path_expression_grammar g; + return parse_path(str,g); +} +path_expression_ptr parse_path(std::string const & str, + path_expression_grammar const& g) +{ + path_expression_ptr path = boost::make_shared(); + std::string::const_iterator itr = str.begin(); std::string::const_iterator end = str.end(); - bool r = qi::phrase_parse(itr, end, g, space, *path); + bool r = qi::phrase_parse(itr, end, g, boost::spirit::standard_wide::space, *path); if (r && itr == end) { return path; @@ -45,14 +51,4 @@ path_expression_ptr parse_path(std::string const & str) } } -bool parse_path_from_string(path_expression_ptr const& path, - std::string const & str, - path_expression_grammar 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, *path); - return (r && itr==end); -} - }