Skip to content

Commit

Permalink
crundel: add deep-copy option for copying rules and feature_type_styles
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoup committed Oct 20, 2011
1 parent 2763749 commit 48311f3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/mapnik/feature_type_style.hpp
Expand Up @@ -51,7 +51,7 @@ class MAPNIK_DECL feature_type_style
public: public:
feature_type_style(); feature_type_style();


feature_type_style(feature_type_style const& rhs); feature_type_style(feature_type_style const& rhs, bool deep_copy = false);


feature_type_style& operator=(feature_type_style const& rhs); feature_type_style& operator=(feature_type_style const& rhs);


Expand Down
85 changes: 83 additions & 2 deletions include/mapnik/rule.hpp
Expand Up @@ -36,6 +36,7 @@
#include <mapnik/glyph_symbolizer.hpp> #include <mapnik/glyph_symbolizer.hpp>
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
#include <mapnik/filter_factory.hpp> #include <mapnik/filter_factory.hpp>
#include <mapnik/expression_string.hpp>


// boost // boost
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
Expand Down Expand Up @@ -164,7 +165,7 @@ class rule
else_filter_(false), else_filter_(false),
also_filter_(false) {} also_filter_(false) {}


rule(const rule& rhs) rule(const rule& rhs, bool deep_copy = false)
: name_(rhs.name_), : name_(rhs.name_),
title_(rhs.title_), title_(rhs.title_),
abstract_(rhs.abstract_), abstract_(rhs.abstract_),
Expand All @@ -173,7 +174,54 @@ class rule
syms_(rhs.syms_), syms_(rhs.syms_),
filter_(rhs.filter_), filter_(rhs.filter_),
else_filter_(rhs.else_filter_), else_filter_(rhs.else_filter_),
also_filter_(rhs.also_filter_) {} also_filter_(rhs.also_filter_)
{
if (deep_copy) {
//std::string expr = to_expression_string(rhs.filter_);
//filter_ = parse_expression(expr,"utf8");

symbolizers::iterator it = syms_.begin(),
end = syms_.end();

// FIXME - metawriter_ptr?

for(; it != end; ++it) {

/*if (polygon_symbolizer *sym = boost::get<polygon_symbolizer>(&(*it))) {
// no shared pointers
} else if (line_symbolizer *sym = boost::get<line_symbolizer>(&(*it))) {
// no shared pointers
} else if (building_symbolizer *sym = boost::get<building_symbolizer>(&(*it))) {
// no shared pointers
}*/

if (markers_symbolizer *sym = boost::get<markers_symbolizer>(&(*it))) {
copy_path_ptr(sym);
} else if (point_symbolizer *sym = boost::get<point_symbolizer>(&(*it))) {
copy_path_ptr(sym);
} else if (polygon_pattern_symbolizer *sym = boost::get<polygon_pattern_symbolizer>(&(*it))) {
copy_path_ptr(sym);
} else if (line_pattern_symbolizer *sym = boost::get<line_pattern_symbolizer>(&(*it))) {
copy_path_ptr(sym);
} else if (raster_symbolizer *sym = boost::get<raster_symbolizer>(&(*it))) {
raster_colorizer_ptr old_colorizer = sym->get_colorizer(),
new_colorizer = raster_colorizer_ptr();

new_colorizer->set_stops( old_colorizer->get_stops());
new_colorizer->set_default_mode( old_colorizer->get_default_mode() );
new_colorizer->set_default_color( old_colorizer->get_default_color() );
new_colorizer->set_epsilon( old_colorizer->get_epsilon() );

sym->set_colorizer(new_colorizer);
} else if (shield_symbolizer *sym = boost::get<shield_symbolizer>(&(*it))) {
copy_path_ptr(sym);
copy_text_ptr(sym);
} else if (text_symbolizer *sym = boost::get<text_symbolizer>(&(*it))) {
copy_text_ptr(sym);
}
}
}
}


rule& operator=(rule const& rhs) rule& operator=(rule const& rhs)
{ {
Expand Down Expand Up @@ -323,6 +371,39 @@ class rule
else_filter_=rhs.else_filter_; else_filter_=rhs.else_filter_;
also_filter_=rhs.also_filter_; also_filter_=rhs.also_filter_;
} }

template <class T>
void copy_path_ptr(T* sym)
{
std::string path = path_processor_type::to_string(*sym->get_filename());
sym->set_filename( parse_path(path) );
}

template <class T>
void copy_text_ptr(T* sym)
{
std::string name = to_expression_string(*sym->get_name());
sym->set_name( parse_expression(name) );

// FIXME - orientation doesn't appear to be initialized in constructor?
//std::string orientation = to_expression_string(*sym->get_orientation());
//sym->set_orientation( parse_expression(orientation) );

unsigned text_size = sym->get_text_size();
position displace = sym->get_displacement();
vertical_alignment_e valign = sym->get_vertical_alignment();
horizontal_alignment_e halign = sym->get_horizontal_alignment();
justify_alignment_e jalign = sym->get_justify_alignment();

text_placements_ptr placements = text_placements_ptr(boost::make_shared<text_placements_dummy>());
sym->set_placement_options( placements );

sym->set_text_size(text_size);
sym->set_displacement(displace);
sym->set_vertical_alignment(valign);
sym->set_horizontal_alignment(halign);
sym->set_justify_alignment(jalign);
}
}; };


} }
Expand Down
16 changes: 13 additions & 3 deletions src/feature_type_style.cpp
Expand Up @@ -37,9 +37,19 @@ IMPLEMENT_ENUM( filter_mode_e, filter_mode_strings )
feature_type_style::feature_type_style() feature_type_style::feature_type_style()
: filter_mode_(FILTER_ALL) {} : filter_mode_(FILTER_ALL) {}


feature_type_style::feature_type_style(feature_type_style const& rhs) feature_type_style::feature_type_style(feature_type_style const& rhs, bool deep_copy)
: rules_(rhs.rules_), : filter_mode_(rhs.filter_mode_)
filter_mode_(rhs.filter_mode_) {} {
if (!deep_copy) {
rules_ = rhs.rules_;
} else {
rules::const_iterator it = rhs.rules_.begin(),
end = rhs.rules_.end();
for(; it != end; ++it) {
rules_.push_back(rule(*it, deep_copy));
}
}
}


feature_type_style& feature_type_style::operator=(feature_type_style const& rhs) feature_type_style& feature_type_style::operator=(feature_type_style const& rhs)
{ {
Expand Down

0 comments on commit 48311f3

Please sign in to comment.