From c13448f75ec4619ad532f6ed601d705fe13dcfde Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 10 Feb 2014 19:41:17 -0800 Subject: [PATCH] collect attributes from all properties - closes #2153 --- include/mapnik/attribute_collector.hpp | 176 +++++++++---------------- 1 file changed, 63 insertions(+), 113 deletions(-) diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index 2a3df94d1..40c465d5e 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -62,7 +62,6 @@ struct expression_attributes : boost::static_visitor { boost::apply_visitor(*this, x.left); boost::apply_visitor(*this, x.right); - } template @@ -88,121 +87,75 @@ private: Container& names_; }; +template +struct extract_attribute_names : boost::static_visitor +{ + expression_attributes > f_attr; + + explicit extract_attribute_names(Container& names) + : names_(names), + f_attr(names) {} + + void operator() (mapnik::expression_ptr const& expr) const + { + if (expr) + { + boost::apply_visitor(f_attr, *expr); + } + } + void operator() (mapnik::transform_type const& expr) const + { + if (expr) + { + transform_processor_type::collect_attributes(names_, *expr); + } + } + + void operator() (mapnik::text_placements_ptr const& expr) const + { + if (expr) + { + expression_set::const_iterator it; + expression_set expressions; + // TODO - optimize (dane) + expr->add_expressions(expressions); + for (it=expressions.begin(); it != expressions.end(); ++it) + { + if (*it) boost::apply_visitor(f_attr, **it); + } + } + } + + void operator() (mapnik::path_expression_ptr const& expr) const + { + if (expr) + { + path_processor_type::collect_attributes(*expr,names_); + } + } + + template + void operator() (T const& val) const {} + +private: + Container& names_; +}; + struct symbolizer_attributes : public boost::static_visitor<> { symbolizer_attributes(std::set& names, double & filter_factor) : names_(names), filter_factor_(filter_factor), - f_attr(names) {} + f_attrs(names) {} template - void operator () (T const&) const {} - - void operator () (text_symbolizer const& sym) + void operator () (T const& sym) { - expression_set::const_iterator it; - expression_set expressions; - get(sym, keys::text_placements_)->add_expressions(expressions); - for (it=expressions.begin(); it != expressions.end(); ++it) + for (auto const& prop : sym.properties) { - if (*it) boost::apply_visitor(f_attr, **it); + boost::apply_visitor(f_attrs, prop.second); } - collect_transform(get(sym, keys::geometry_transform)); - } - - void operator () (point_symbolizer const& sym) - { - path_expression_ptr const& filename_expr = get(sym, keys::file); - if (filename_expr) - { - path_processor_type::collect_attributes(*filename_expr,names_); - } - collect_transform(get(sym, keys::geometry_transform)); - collect_transform(get(sym, keys::image_transform)); - } - - void operator () (line_symbolizer const& sym) - { - collect_transform(get(sym, keys::geometry_transform)); - } - - void operator () (line_pattern_symbolizer const& sym) - { - path_expression_ptr const& filename_expr = get(sym, keys::file); - if (filename_expr) - { - path_processor_type::collect_attributes(*filename_expr,names_); - } - collect_transform(get(sym, keys::geometry_transform)); - collect_transform(get(sym, keys::image_transform)); - } - - void operator () (polygon_symbolizer const& sym) - { - collect_transform(get(sym, keys::geometry_transform)); - } - - void operator () (polygon_pattern_symbolizer const& sym) - { - path_expression_ptr const& filename_expr = get(sym, keys::file); - if (filename_expr) - { - path_processor_type::collect_attributes(*filename_expr,names_); - } - collect_transform(get(sym, keys::geometry_transform)); - collect_transform(get(sym, keys::image_transform)); - } - - void operator () (shield_symbolizer const& sym) - { - expression_set::const_iterator it; - expression_set expressions; - get(sym, keys::text_placements_)->add_expressions(expressions); - for (it=expressions.begin(); it != expressions.end(); ++it) - { - if (*it) boost::apply_visitor(f_attr, **it); - } - - path_expression_ptr const& filename_expr = get(sym, keys::file); - if (filename_expr) - { - path_processor_type::collect_attributes(*filename_expr,names_); - } - - collect_transform(get(sym, keys::geometry_transform)); - collect_transform(get(sym, keys::image_transform)); - } - - void operator () (markers_symbolizer const& sym) - { - expression_ptr const& height_expr = get(sym,keys::height); - if (height_expr) - { - boost::apply_visitor(f_attr,*height_expr); - } - expression_ptr const& width_expr = get(sym,keys::width); - if (width_expr) - { - boost::apply_visitor(f_attr,*width_expr); - } - path_expression_ptr const& filename_expr = get(sym, keys::file); - if (filename_expr) - { - path_processor_type::collect_attributes(*filename_expr,names_); - } - collect_transform(get(sym, keys::geometry_transform)); - collect_transform(get(sym, keys::image_transform)); - } - - void operator () (building_symbolizer const& sym) - { - expression_ptr const& height_expr = get(sym,keys::height); - if (height_expr) - { - boost::apply_visitor(f_attr,*height_expr); - } - collect_transform(get(sym, keys::geometry_transform)); } void operator () (raster_symbolizer const& sym) @@ -220,19 +173,16 @@ struct symbolizer_attributes : public boost::static_visitor<> filter_factor_ = 2; } } + for (auto const& prop : sym.properties) + { + boost::apply_visitor(f_attrs, prop.second); + } } private: std::set& names_; double & filter_factor_; - expression_attributes > f_attr; - void collect_transform(transform_list_ptr const& trans_expr) - { - if (trans_expr) - { - transform_processor_type::collect_attributes(names_, *trans_expr); - } - } + extract_attribute_names > f_attrs; };