use boost::ptr_containers to store Map elements

This commit is contained in:
artemp 2012-07-09 08:44:56 +01:00
parent ee7f72dcce
commit 18633adc7e
13 changed files with 118 additions and 91 deletions

View file

@ -62,8 +62,8 @@ struct map_pickle_suite : boost::python::pickle_suite
for (; it != end; ++it)
{
std::string const& name = it->first;
const mapnik::feature_type_style & style = it->second;
boost::python::tuple style_pair = boost::python::make_tuple(name,style);
const mapnik::feature_type_style * style = it->second;
boost::python::tuple style_pair = boost::python::make_tuple(name,*style);
s.append(style_pair);
}

View file

@ -312,6 +312,7 @@ StyleModel::StyleModel(boost::shared_ptr<mapnik::Map> map, QObject * parent)
: QAbstractItemModel(parent),
root_(new node(map_node(map)))
{
/*
typedef std::map<std::string,mapnik::feature_type_style> style_type;
style_type const & styles = map->styles();
style_type::const_iterator itr = styles.begin();
@ -331,6 +332,7 @@ StyleModel::StyleModel(boost::shared_ptr<mapnik::Map> map, QObject * parent)
}
}
}
*/
}
StyleModel::~StyleModel() {}

View file

@ -31,6 +31,7 @@
// boost
#include <boost/optional.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
// stl
#include <vector>
@ -45,7 +46,7 @@ enum filter_mode_enum {
DEFINE_ENUM( filter_mode_e, filter_mode_enum );
typedef std::vector<rule> rules;
typedef boost::ptr_vector<rule> rules;
typedef std::vector<rule*> rule_ptrs;
class MAPNIK_DECL feature_type_style
@ -71,7 +72,7 @@ public:
feature_type_style& operator=(feature_type_style const& rhs);
void add_rule(rule const& rule);
void add_rule(std::auto_ptr<rule> rule);
rules const& get_rules() const;
rule_ptrs const& get_if_rules(double scale_denom);

View file

@ -33,6 +33,7 @@
// boost
#include <boost/optional/optional.hpp>
#include <boost/ptr_container/ptr_map.hpp>
namespace mapnik
{
@ -71,7 +72,7 @@ private:
int buffer_size_;
boost::optional<color> background_;
boost::optional<std::string> background_image_;
std::map<std::string,feature_type_style> styles_;
boost::ptr_map<std::string,feature_type_style> styles_;
std::map<std::string,metawriter_ptr> metawriters_;
std::map<std::string,font_set> fontsets_;
std::vector<layer> layers_;
@ -83,8 +84,8 @@ private:
public:
typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator;
typedef std::map<std::string,feature_type_style>::iterator style_iterator;
typedef boost::ptr_map<std::string,feature_type_style>::const_iterator const_style_iterator;
typedef boost::ptr_map<std::string,feature_type_style>::iterator style_iterator;
typedef std::map<std::string,font_set>::const_iterator const_fontset_iterator;
typedef std::map<std::string,font_set>::iterator fontset_iterator;
typedef std::map<std::string,metawriter_ptr>::const_iterator const_metawriter_iterator;
@ -121,12 +122,12 @@ public:
/*! \brief Get all styles
* @return Const reference to styles
*/
std::map<std::string,feature_type_style> const& styles() const;
boost::ptr_map<std::string,feature_type_style> const& styles() const;
/*! \brief Get all styles
* @return Non-constant reference to styles
*/
std::map<std::string,feature_type_style> & styles();
boost::ptr_map<std::string,feature_type_style> & styles();
/*! \brief Get first iterator in styles.
* @return Constant style iterator.
@ -154,7 +155,7 @@ public:
* @return true If success.
* @return false If no success.
*/
bool insert_style(std::string const& name,feature_type_style const& style);
bool insert_style(std::string const& name, std::auto_ptr<feature_type_style> style);
/*! \brief Remove a style from the map.
* @param name The name of the style.

View file

@ -43,16 +43,22 @@ struct MAPNIK_DECL raster_symbolizer : public symbolizer_base
opacity_(1.0),
colorizer_(),
filter_factor_(-1),
mesh_size_(16) {}
mesh_size_(16)
{
std::cout << "raster_symbolizer: default ctor called" << std::endl;
}
raster_symbolizer(const raster_symbolizer &rhs)
: symbolizer_base(rhs),
mode_(rhs.get_mode()),
scaling_(rhs.get_scaling()),
opacity_(rhs.get_opacity()),
mode_(rhs.mode_),
scaling_(rhs.scaling_),
opacity_(rhs.opacity_),
colorizer_(rhs.colorizer_),
filter_factor_(rhs.filter_factor_),
mesh_size_(rhs.mesh_size_) {}
mesh_size_(rhs.mesh_size_)
{
std::cout << "raster_symbolizer: copy ctor called" << std::endl;
}
std::string const& get_mode() const
{

View file

@ -166,7 +166,7 @@ void agg_renderer<T>::process(markers_symbolizer const& sym,
detector_->has_placement(transformed_bbox))
{
svg_renderer.render(*ras_ptr, sl, renb, matrix, sym.get_opacity(), bbox);
if (/* DEBUG */ 0)
if (/* DEBUG */ 1)
{
debug_draw_box(buf, transformed_bbox, 0, 0, 0.0);
}

View file

@ -67,13 +67,13 @@ void agg_renderer<T>::process(raster_symbolizer const& sym,
if (raster_width > 0 && raster_height > 0)
{
double scale_factor = ext.width() / source->data_.width();
image_data_32 target_data(raster_width,raster_height);
raster target(target_ext, target_data);
reproject_raster(target, *source, prj_trans, err_offs_x, err_offs_y,
sym.get_mesh_size(),
sym.calculate_filter_factor(),
scale_factor_,
scale_factor,
sym.get_scaling());
composite(current_buffer_->data(), target.data_, sym.comp_op(), sym.get_opacity(), start_x, start_y, true);

View file

@ -112,12 +112,12 @@ namespace mapnik { namespace util {
typedef std::map<std::string, feature_type_style> style_cont;
typedef style_cont::value_type value_type;
style_cont const& styles = map_in.styles();
BOOST_FOREACH ( value_type const& kv, styles )
//style_cont const& styles = map_in.styles();
//BOOST_FOREACH ( value_type const& kv, styles )
{
feature_type_style const& style_in = kv.second;
feature_type_style style_out(style_in,true); // deep copy
map_out.insert_style(kv.first, style_out);
// feature_type_style const& style_in = kv.second;
//feature_type_style style_out(style_in,true); // deep copy
//map_out.insert_style(kv.first, style_out);
}
}

View file

@ -36,6 +36,7 @@
// boost
#include <boost/foreach.hpp>
#include <boost/concept_check.hpp>
//stl
#include <vector>
@ -363,7 +364,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
continue;
}
const std::vector<rule>& rules=(*style).get_rules();
const boost::ptr_vector<rule>& rules=(*style).get_rules();
bool active_rules=false;
BOOST_FOREACH(rule const& r, rules)

View file

@ -43,21 +43,28 @@ feature_type_style::feature_type_style()
{}
feature_type_style::feature_type_style(feature_type_style const& rhs, bool deep_copy)
: filter_mode_(rhs.filter_mode_),
:
filter_mode_(rhs.filter_mode_),
filters_(rhs.filters_),
direct_filters_(rhs.direct_filters_),
comp_op_(rhs.comp_op_),
scale_denom_validity_(-1),
opacity_(rhs.opacity_)
{
if (!deep_copy) {
if (!deep_copy)
{
//rules_= rhs.rules_.release();
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));
}
}
else
{
//rules::const_iterator it = rhs.rules_.begin(),
// end = rhs.rules_.end();
//for(; it != end; ++it)
//{
// rules_.push_back(rule(*it, deep_copy));
// }
}
}
@ -73,9 +80,9 @@ feature_type_style& feature_type_style::operator=(feature_type_style const& rhs)
return *this;
}
void feature_type_style::add_rule(rule const& rule)
void feature_type_style::add_rule(std::auto_ptr<rule> r)
{
rules_.push_back(rule);
rules_.push_back(r);
scale_denom_validity_ = -1;
}

View file

@ -412,10 +412,10 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
try
{
name = sty.get_attr<std::string>("name");
feature_type_style style;
std::auto_ptr<feature_type_style> style(new feature_type_style);
filter_mode_e filter_mode = sty.get_attr<filter_mode_e>("filter-mode", FILTER_ALL);
style.set_filter_mode(filter_mode);
style->set_filter_mode(filter_mode);
// compositing
optional<std::string> comp_op_name = sty.get_opt_attr<std::string>("comp-op");
@ -424,7 +424,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
optional<composite_mode_e> comp_op = comp_op_from_string(*comp_op_name);
if (comp_op)
{
style.set_comp_op(*comp_op);
style->set_comp_op(*comp_op);
}
else
{
@ -435,7 +435,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
optional<float> opacity = sty.get_opt_attr<float>("opacity");
if (opacity)
{
style.set_opacity(*opacity);
style->set_opacity(*opacity);
}
// image filters
@ -453,7 +453,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
bool result = boost::spirit::qi::phrase_parse(itr,end,
filter_grammar,
boost::spirit::qi::ascii::space,
style.image_filters());
style->image_filters());
if (!result || itr!=end)
{
throw config_error("failed to parse image-filters: '" + std::string(itr,end) + "'");
@ -473,7 +473,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
bool result = boost::spirit::qi::phrase_parse(itr,end,
filter_grammar,
boost::spirit::qi::ascii::space,
style.direct_image_filters());
style->direct_image_filters());
if (!result || itr!=end)
{
throw config_error("failed to parse direct-image-filters: '" + std::string(itr,end) + "'");
@ -488,12 +488,14 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
{
if (ruleIter->is("Rule"))
{
parse_rule(style, *ruleIter);
parse_rule(*style, *ruleIter);
}
}
map.insert_style(name, style);
} catch (const config_error & ex) {
}
catch (const config_error & ex)
{
ex.append_context(std::string("in style '") + name + "'", sty);
throw;
}
@ -728,97 +730,97 @@ void map_parser::parse_layer(Map & map, xml_node const& lay)
}
}
void map_parser::parse_rule(feature_type_style & style, xml_node const& r)
void map_parser::parse_rule(feature_type_style & style, xml_node const& node)
{
std::string name;
try
{
name = r.get_attr("name", std::string());
rule rule(name);
name = node.get_attr("name", std::string());
std::auto_ptr<rule> r(new rule(name));
xml_node const* child = r.get_opt_child("Filter");
xml_node const* child = node.get_opt_child("Filter");
if (child)
{
rule.set_filter(child->get_value<expression_ptr>());
r->set_filter(child->get_value<expression_ptr>());
}
if (r.has_child("ElseFilter"))
if (node.has_child("ElseFilter"))
{
rule.set_else(true);
r->set_else(true);
}
if (r.has_child("AlsoFilter"))
if (node.has_child("AlsoFilter"))
{
rule.set_also(true);
r->set_also(true);
}
child = r.get_opt_child("MinScaleDenominator");
child = node.get_opt_child("MinScaleDenominator");
if (child)
{
rule.set_min_scale(child->get_value<double>());
r->set_min_scale(child->get_value<double>());
}
child = r.get_opt_child("MaxScaleDenominator");
child = node.get_opt_child("MaxScaleDenominator");
if (child)
{
rule.set_max_scale(child->get_value<double>());
r->set_max_scale(child->get_value<double>());
}
xml_node::const_iterator symIter = r.begin();
xml_node::const_iterator endSym = r.end();
xml_node::const_iterator symIter = node.begin();
xml_node::const_iterator endSym = node.end();
for(;symIter != endSym; ++symIter)
{
if (symIter->is("PointSymbolizer"))
{
parse_point_symbolizer(rule, *symIter);
parse_point_symbolizer(*r, *symIter);
}
else if (symIter->is("LinePatternSymbolizer"))
{
parse_line_pattern_symbolizer(rule, *symIter);
parse_line_pattern_symbolizer(*r, *symIter);
}
else if (symIter->is("PolygonPatternSymbolizer"))
{
parse_polygon_pattern_symbolizer(rule, *symIter);
parse_polygon_pattern_symbolizer(*r, *symIter);
}
else if (symIter->is("TextSymbolizer"))
{
parse_text_symbolizer(rule, *symIter);
parse_text_symbolizer(*r, *symIter);
}
else if (symIter->is("ShieldSymbolizer"))
{
parse_shield_symbolizer(rule, *symIter);
parse_shield_symbolizer(*r, *symIter);
}
else if (symIter->is("LineSymbolizer"))
{
parse_line_symbolizer(rule, *symIter);
parse_line_symbolizer(*r, *symIter);
}
else if (symIter->is("PolygonSymbolizer"))
{
parse_polygon_symbolizer(rule, *symIter);
parse_polygon_symbolizer(*r, *symIter);
}
else if (symIter->is("BuildingSymbolizer"))
{
parse_building_symbolizer(rule, *symIter);
parse_building_symbolizer(*r, *symIter);
}
else if (symIter->is("RasterSymbolizer"))
{
parse_raster_symbolizer(rule, *symIter);
parse_raster_symbolizer(*r, *symIter);
}
else if (symIter->is("MarkersSymbolizer"))
{
parse_markers_symbolizer(rule, *symIter);
parse_markers_symbolizer(*r, *symIter);
}
}
style.add_rule(rule);
style.add_rule(r);
}
catch (const config_error & ex)
{
if (!name.empty())
{
ex.append_context(std::string("in rule '") + name + "'", r);
ex.append_context(std::string("in rule '") + name + "'", node);
}
throw;
}

View file

@ -31,6 +31,9 @@
#include <mapnik/config_error.hpp>
#include <mapnik/config.hpp> // for PROJ_ENVELOPE_POINTS
#include <boost/ptr_container/ptr_map.hpp>
#include <boost/assign/ptr_map_inserter.hpp>
// boost
#include <boost/make_shared.hpp>
@ -90,7 +93,7 @@ Map::Map(const Map& rhs)
buffer_size_(rhs.buffer_size_),
background_(rhs.background_),
background_image_(rhs.background_image_),
styles_(rhs.styles_),
//styles_(rhs.styles_),
metawriters_(rhs.metawriters_),
fontsets_(rhs.fontsets_),
layers_(rhs.layers_),
@ -109,7 +112,7 @@ Map& Map::operator=(const Map& rhs)
buffer_size_ = rhs.buffer_size_;
background_=rhs.background_;
background_image_=rhs.background_image_;
styles_=rhs.styles_;
//styles_=rhs.styles_;
metawriters_ = rhs.metawriters_;
fontsets_ = rhs.fontsets_;
layers_=rhs.layers_;
@ -120,12 +123,12 @@ Map& Map::operator=(const Map& rhs)
return *this;
}
std::map<std::string,feature_type_style> const& Map::styles() const
boost::ptr_map<std::string,feature_type_style> const& Map::styles() const
{
return styles_;
}
std::map<std::string,feature_type_style> & Map::styles()
boost::ptr_map<std::string,feature_type_style> & Map::styles()
{
return styles_;
}
@ -150,9 +153,11 @@ Map::const_style_iterator Map::end_styles() const
return styles_.end();
}
bool Map::insert_style(std::string const& name,feature_type_style const& style)
bool Map::insert_style(std::string const& name, std::auto_ptr<feature_type_style> style)
{
return styles_.insert(make_pair(name,style)).second;
//boost::assign::ptr_map_insert(styles_)(name,style);
styles_.insert(name,style);
return true; // FIXME
}
void Map::remove_style(std::string const& name)
@ -162,9 +167,9 @@ void Map::remove_style(std::string const& name)
boost::optional<feature_type_style const&> Map::find_style(std::string const& name) const
{
std::map<std::string,feature_type_style>::const_iterator itr = styles_.find(name);
boost::ptr_map<std::string,feature_type_style>::const_iterator itr = styles_.find(name);
if (itr != styles_.end())
return boost::optional<feature_type_style const&>(itr->second);
return boost::optional<feature_type_style const&>(*itr->second);
else
return boost::optional<feature_type_style const&>() ;
}
@ -634,13 +639,15 @@ void Map::init_metawriters()
Map::style_iterator styIter = begin_styles();
Map::style_iterator styEnd = end_styles();
for (; styIter!=styEnd; ++styIter) {
std::vector<rule>& rules = styIter->second.get_rules_nonconst();
std::vector<rule>::iterator ruleIter = rules.begin();
std::vector<rule>::iterator ruleEnd = rules.end();
for (; ruleIter!=ruleEnd; ++ruleIter) {
boost::ptr_vector<rule>& rules = styIter->second->get_rules_nonconst();
boost::ptr_vector<rule>::iterator ruleIter = rules.begin();
boost::ptr_vector<rule>::iterator ruleEnd = rules.end();
for (; ruleIter!=ruleEnd; ++ruleIter)
{
rule::symbolizers::iterator symIter = ruleIter->begin();
rule::symbolizers::iterator symEnd = ruleIter->end();
for (; symIter!=symEnd; ++symIter) {
for (; symIter!=symEnd; ++symIter)
{
boost::apply_visitor(d, *symIter);
}
}

View file

@ -530,7 +530,7 @@ void serialize_rule( ptree & style_node, const rule & r, bool explicit_defaults)
void serialize_style( ptree & map_node, Map::const_style_iterator style_it, bool explicit_defaults )
{
feature_type_style const& style = style_it->second;
feature_type_style const* style = style_it->second;
std::string const& name = style_it->first;
ptree & style_node = map_node.push_back(
@ -539,19 +539,19 @@ void serialize_style( ptree & map_node, Map::const_style_iterator style_it, bool
set_attr(style_node, "name", name);
feature_type_style dfl;
filter_mode_e filter_mode = style.get_filter_mode();
filter_mode_e filter_mode = style->get_filter_mode();
if (filter_mode != dfl.get_filter_mode() || explicit_defaults)
{
set_attr(style_node, "filter-mode", filter_mode);
}
double opacity = style.get_opacity();
double opacity = style->get_opacity();
if (opacity != dfl.get_opacity() || explicit_defaults)
{
set_attr(style_node, "opacity", opacity);
}
boost::optional<composite_mode_e> comp_op = style.comp_op();
boost::optional<composite_mode_e> comp_op = style->comp_op();
if (comp_op)
{
set_attr(style_node, "comp-op", *comp_op_to_string(*comp_op));
@ -561,8 +561,8 @@ void serialize_style( ptree & map_node, Map::const_style_iterator style_it, bool
set_attr(style_node, "comp-op", "src-over");
}
rules::const_iterator it = style.get_rules().begin();
rules::const_iterator end = style.get_rules().end();
rules::const_iterator it = style->get_rules().begin();
rules::const_iterator end = style->get_rules().end();
for (; it != end; ++it)
{
serialize_rule( style_node, * it , explicit_defaults);