simplify code

This commit is contained in:
Dane Springmeyer 2014-05-05 18:16:42 -07:00
commit d7bb97a22e
25 changed files with 220 additions and 298 deletions

View file

@ -26,6 +26,8 @@ clean:
@if test -e ".sconf_temp/"; then rm -r ".sconf_temp/"; fi
@find ./ -name "*.pyc" -exec rm {} \;
@find ./ -name "*.os" -exec rm {} \;
@find ./ -name "*.dylib" -exec rm {} \;
@find ./ -name "*.so" -exec rm {} \;
@find ./ -name "*.o" -exec rm {} \;
@find ./ -name "*.pyc" -exec rm {} \;
@if test -e "bindings/python/mapnik/paths.py"; then rm "bindings/python/mapnik/paths.py"; fi

View file

@ -30,40 +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::expression_grammar<std::string::const_iterator> expr_grammar;;
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::expression_grammar<std::string::const_iterator> expr_grammar;
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");
}

View file

@ -18,7 +18,7 @@ public:
std::string out;
for (std::size_t i=0;i<iterations_;++i) {
out.clear();
out = mapnik::save_to_string(im_,"png8:m=h");
out = mapnik::save_to_string(im_,"png8:m=h:z=1");
}
}
};

View file

@ -20,7 +20,7 @@ public:
{
std::string expected("./benchmark/data/multicolor-hextree-expected.png");
std::string actual("./benchmark/data/multicolor-hextree-actual.png");
mapnik::save_to_file(im_->data(),actual, "png8:m=h");
mapnik::save_to_file(im_->data(),actual, "png8:m=h:z=1");
return benchmark::compare_images(actual,expected);
}
void operator()() const
@ -28,7 +28,7 @@ public:
std::string out;
for (std::size_t i=0;i<iterations_;++i) {
out.clear();
out = mapnik::save_to_string(im_->data(),"png8:m=h");
out = mapnik::save_to_string(im_->data(),"png8:m=h:z=1");
}
}
};

View file

@ -26,31 +26,4 @@ public:
}
};
class test2 : public benchmark::test_case
{
std::string value_;
public:
test2(mapnik::parameters const& params)
: test_case(params),
value_("1.23456789") {}
bool validate() const
{
double result = 0;
mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
if (result != 1.23456789) return false;
result = 0;
mapnik::util::string2double(value_,result);
return (result == 1.23456789);
}
void operator()() const
{
for (std::size_t i=0;i<iterations_;++i) {
double result = 0;
mapnik::util::string2double(value_,result);
//mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
}
}
};
//BENCHMARK(test,"string->bool")
BENCHMARK(test2,"string->double")
BENCHMARK(test,"string->bool")

View file

@ -0,0 +1,31 @@
#include "bench_framework.hpp"
#include <mapnik/util/conversions.hpp>
class test : public benchmark::test_case
{
std::string value_;
public:
test(mapnik::parameters const& params)
: test_case(params),
value_("1.23456789") {}
bool validate() const
{
double result = 0;
if (!mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result)) return false;
if (result != 1.23456789) return false;
result = 0;
if (!mapnik::util::string2double(value_,result)) return false;
if (result != 1.23456789) return false;
return true;
}
void operator()() const
{
for (std::size_t i=0;i<iterations_;++i) {
double result = 0;
mapnik::util::string2double(value_,result);
mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
}
}
};
BENCHMARK(test,"string->double")

31
benchmark/test_to_int.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "bench_framework.hpp"
#include <mapnik/util/conversions.hpp>
class test : public benchmark::test_case
{
std::string value_;
public:
test(mapnik::parameters const& params)
: test_case(params),
value_("123456789") {}
bool validate() const
{
mapnik::value_integer result = 0;
if (!mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result)) return false;
if (result != 123456789) return false;
result = 0;
if (!mapnik::util::string2int(value_,result)) return false;
if (result != 123456789) return false;
return true;
}
void operator()() const
{
for (std::size_t i=0;i<iterations_;++i) {
mapnik::value_integer result = 0;
mapnik::util::string2int(value_,result);
mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result);
}
}
};
BENCHMARK(test,"string->int")

View file

@ -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

View file

@ -127,7 +127,7 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
{
typedef qi::rule<Iterator, expr_node(), space_type> rule_type;
explicit expression_grammar();
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__;

View file

@ -64,9 +64,9 @@ expr_node regex_replace_impl::operator() (T0 & node, T1 const& pattern, T2 const
}
template <typename Iterator>
expression_grammar<Iterator>::expression_grammar()
expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
: expression_grammar::base_type(expr),
tr_("utf-8"),
tr_(encoding),
unicode_(unicode_impl(tr_)),
regex_match_(regex_match_impl(tr_)),
regex_replace_(regex_replace_impl(tr_))

View file

@ -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
{

View file

@ -29,22 +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);
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

View file

@ -42,8 +42,8 @@ struct glyph_info;
struct glyph_position
{
glyph_position(glyph_info const& glyph, pixel_position const& pos, rotation const& rot)
: glyph(&glyph), pos(pos), rot(rot) { }
glyph_position(glyph_info const& _glyph, pixel_position const& _pos, rotation const& _rot)
: glyph(&_glyph), pos(_pos), rot(_rot) { }
glyph_info const* glyph;
pixel_position pos;
rotation rot;
@ -52,8 +52,8 @@ struct glyph_position
struct marker_info
{
marker_info() : marker(), transform() {}
marker_info(marker_ptr marker, agg::trans_affine const& transform) :
marker(marker), transform(transform) {}
marker_info(marker_ptr _marker, agg::trans_affine const& _transform) :
marker(_marker), transform(_transform) {}
marker_ptr marker;
agg::trans_affine transform;
};

View file

@ -24,6 +24,7 @@
#define MAPNIK_GEOMETRY_TO_WKB_HPP
// mapnik
#include <mapnik/std.hpp>
#include <mapnik/global.hpp>
#include <mapnik/geometry.hpp>
@ -141,7 +142,7 @@ wkb_buffer_ptr to_point_wkb( GeometryType const& g, wkbByteOrder byte_order)
{
assert(g.size() == 1);
std::size_t size = 1 + 4 + 8*2 ; // byteOrder + wkbType + Point
wkb_buffer_ptr wkb(new wkb_buffer(size));
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
wkb_stream ss(wkb->buffer(), wkb->size());
ss.write(reinterpret_cast<char*>(&byte_order),1);
int type = static_cast<int>(mapnik::geometry_type::types::Point);
@ -161,7 +162,7 @@ wkb_buffer_ptr to_line_string_wkb( GeometryType const& g, wkbByteOrder byte_orde
unsigned num_points = g.size();
assert(num_points > 1);
std::size_t size = 1 + 4 + 4 + 8*2*num_points ; // byteOrder + wkbType + numPoints + Point*numPoints
wkb_buffer_ptr wkb(new wkb_buffer(size));
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
wkb_stream ss(wkb->buffer(), wkb->size());
ss.write(reinterpret_cast<char*>(&byte_order),1);
int type = static_cast<int>(mapnik::geometry_type::types::LineString);
@ -209,7 +210,7 @@ wkb_buffer_ptr to_polygon_wkb( GeometryType const& g, wkbByteOrder byte_order)
}
}
unsigned num_rings = rings.size();
wkb_buffer_ptr wkb(new wkb_buffer(size));
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
wkb_stream ss(wkb->buffer(), wkb->size());
ss.write(reinterpret_cast<char*>(&byte_order),1);
int type = static_cast<int>(mapnik::geometry_type::types::Polygon);
@ -281,7 +282,7 @@ wkb_buffer_ptr to_wkb(geometry_container const& paths, wkbByteOrder byte_order )
wkb_cont.push_back(std::move(wkb));
}
wkb_buffer_ptr multi_wkb( new wkb_buffer(multi_size));
wkb_buffer_ptr multi_wkb = std::make_unique<wkb_buffer>(multi_size);
wkb_stream ss(multi_wkb->buffer(), multi_wkb->size());
ss.write(reinterpret_cast<char*>(&byte_order),1);
multi_type = collection ? 7 : multi_type + 3;

View file

@ -188,7 +188,7 @@ struct do_xml_attribute_cast<mapnik::expression_ptr>
else
{
mapnik::expression_ptr expr = parse_expression(source);
tree.expr_cache_.insert(std::move(std::make_pair(source,expr)));
tree.expr_cache_.insert(std::make_pair(source,expr));
return expr;
}
}

View file

@ -46,7 +46,7 @@ color parse_color(std::string const& str,
c);
if (result && (first == last))
{
return std::move(c);
return c;
}
else
{

View file

@ -36,12 +36,6 @@ namespace mapnik
expression_ptr parse_expression(std::string const& str, std::string const& encoding)
{
static const expression_grammar<std::string::const_iterator> g;
return parse_expression(str, g);
}
expression_ptr parse_expression(std::string const& str,
mapnik::expression_grammar<std::string::const_iterator> const& g)
{
boost::spirit::standard_wide::space_type space;
auto node = std::make_shared<expr_node>();
std::string::const_iterator itr = str.begin();

View file

@ -293,14 +293,13 @@ void map_parser::parse_map(Map & map, xml_node const& pt, std::string const& bas
unsigned i = 0;
bool success = false;
int n[3];
for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tokens.begin();
beg != tokens.end(); ++beg)
for (auto const& beg : tokens)
{
std::string item = mapnik::util::trim_copy(*beg);
std::string item = mapnik::util::trim_copy(beg);
if (!mapnik::util::string2int(item,n[i]))
{
throw config_error(std::string("Invalid version string encountered: '")
+ *beg + "' in '" + *min_version_string + "'");
+ beg + "' in '" + *min_version_string + "'");
}
if (i==2)
{
@ -340,89 +339,75 @@ void map_parser::parse_map_include(Map & map, xml_node const& include)
{
try
{
xml_node::const_iterator itr = include.begin();
xml_node::const_iterator end = include.end();
for (; itr != end; ++itr)
for (auto const& n : include)
{
if (itr->is_text()) continue;
if (itr->is("Include"))
if (n.is_text()) continue;
if (n.is("Include"))
{
parse_map_include(map, *itr);
parse_map_include(map, n);
}
else if (itr->is("Style"))
else if (n.is("Style"))
{
parse_style(map, *itr);
parse_style(map, n);
}
else if (itr->is("Layer"))
else if (n.is("Layer"))
{
parse_layer(map, *itr);
parse_layer(map, n);
}
else if (itr->is("FontSet"))
else if (n.is("FontSet"))
{
parse_fontset(map, *itr);
parse_fontset(map, n);
}
else if (itr->is("FileSource"))
else if (n.is("FileSource"))
{
std::string name = itr->get_attr<std::string>("name");
std::string value = itr->get_text();
file_sources_[std::move(name)] = std::move(value);
file_sources_[n.get_attr<std::string>("name")] = n.get_text();
}
else if (itr->is("Datasource"))
else if (n.is("Datasource"))
{
std::string name = itr->get_attr("name", std::string("Unnamed"));
std::string name = n.get_attr("name", std::string("Unnamed"));
parameters params;
xml_node::const_iterator paramIter = itr->begin();
xml_node::const_iterator endParam = itr->end();
for (; paramIter != endParam; ++paramIter)
for (auto const& p: n)
{
if (paramIter->is("Parameter"))
if (p.is("Parameter"))
{
std::string param_name = paramIter->get_attr<std::string>("name");
std::string value = paramIter->get_text();
params[std::move(param_name)] = std::move(value);
params[p.get_attr<std::string>("name")] = p.get_text();
}
}
datasource_templates_[name] = std::move(params);
datasource_templates_[std::move(name)] = std::move(params);
}
else if (itr->is("Parameters"))
else if (n.is("Parameters"))
{
parameters & params = map.get_extra_parameters();
xml_node::const_iterator paramIter = itr->begin();
xml_node::const_iterator endParam = itr->end();
for (; paramIter != endParam; ++paramIter)
for (auto const& p: n)
{
if (paramIter->is("Parameter"))
if (p.is("Parameter"))
{
std::string name = paramIter->get_attr<std::string>("name");
bool is_string = true;
boost::optional<std::string> type = paramIter->get_opt_attr<std::string>("type");
boost::optional<std::string> type = p.get_opt_attr<std::string>("type");
if (type)
{
if (*type == "int")
{
is_string = false;
mapnik::value_integer value = paramIter->get_value<mapnik::value_integer>();
params[std::move(name)] = std::move(value);
params[p.get_attr<std::string>("name")] = p.get_value<mapnik::value_integer>();
}
else if (*type == "float")
{
is_string = false;
double value = paramIter->get_value<mapnik::value_double>();
params[std::move(name)] = std::move(value);
params[p.get_attr<std::string>("name")] = p.get_value<mapnik::value_double>();
}
}
if (is_string)
{
std::string value = paramIter->get_text();
params[std::move(name)] = std::move(value);
params[p.get_attr<std::string>("name")] = p.get_text();
}
}
}
}
}
} catch (config_error const& ex) {
}
catch (config_error const& ex)
{
ex.append_context(include);
throw;
}
@ -509,15 +494,12 @@ void map_parser::parse_fontset(Map & map, xml_node const& fset)
{
name = fset.get_attr<std::string>("name");
font_set fontset(name);
xml_node::const_iterator itr = fset.begin();
xml_node::const_iterator end = fset.end();
bool success = false;
for (; itr != end; ++itr)
for (auto const& n: fset)
{
if (itr->is("Font"))
if (n.is("Font"))
{
if (parse_font(fontset, *itr))
if (parse_font(fontset, n))
{
success = true;
}
@ -534,7 +516,7 @@ void map_parser::parse_fontset(Map & map, xml_node const& fset)
// XXX Hack because map object isn't accessible by text_symbolizer
// when it's parsed
fontsets_.insert(std::move(std::make_pair(name, fontset)));
fontsets_.insert(std::make_pair(name, fontset));
}
catch (config_error const& ex)
{
@ -662,15 +644,12 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
}
}
xml_node::const_iterator child = node.begin();
xml_node::const_iterator end = node.end();
for(; child != end; ++child)
for (auto const& child: node)
{
if (child->is("StyleName"))
if (child.is("StyleName"))
{
std::string style_name = child->get_text();
std::string style_name = child.get_text();
if (style_name.empty())
{
std::string ss("StyleName is empty in Layer: '");
@ -689,14 +668,14 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
lyr.add_style(style_name);
}
}
else if (child->is("Datasource"))
else if (child.is("Datasource"))
{
parameters params;
optional<std::string> base = child->get_opt_attr<std::string>("base");
optional<std::string> base = child.get_opt_attr<std::string>("base");
if(base)
{
std::map<std::string,parameters>::const_iterator base_itr = datasource_templates_.find(*base);
if (base_itr!=datasource_templates_.end())
if (base_itr != datasource_templates_.end())
{
params = base_itr->second;
}
@ -707,26 +686,24 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
}
}
xml_node::const_iterator paramIter = child->begin();
xml_node::const_iterator endParam = child->end();
for (; paramIter != endParam; ++paramIter)
for (auto const& n : child)
{
if (paramIter->is("Parameter"))
if (n.is("Parameter"))
{
std::string param_name = paramIter->get_attr<std::string>("name");
std::string value = paramIter->get_text();
params[param_name] = value;
params[n.get_attr<std::string>("name")] = n.get_text();
}
}
boost::optional<std::string> base_param = params.get<std::string>("base");
boost::optional<std::string> file_param = params.get<std::string>("file");
if (base_param){
if (base_param)
{
params["base"] = ensure_relative_to_xml(base_param);
}
else if (file_param){
else if (file_param)
{
params["file"] = ensure_relative_to_xml(file_param);
}
@ -908,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))
{
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
@ -976,12 +946,7 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym)
if (image_transform_wkt)
{
mapnik::transform_list_ptr tl = std::make_shared<mapnik::transform_list>();
if (!mapnik::parse_transform(*tl, *image_transform_wkt))
{
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);
@ -1053,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))
{
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");
@ -1154,7 +1114,7 @@ void map_parser::parse_polygon_pattern_symbolizer(rule & rule,
if(base)
{
std::map<std::string,std::string>::iterator itr = file_sources_.find(*base);
std::map<std::string,std::string>::const_iterator itr = file_sources_.find(*base);
if (itr!=file_sources_.end())
{
file = itr->second + "/" + file;
@ -1221,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))
{
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));
@ -1244,7 +1199,8 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym)
{
text_placements_ptr placement_finder;
optional<std::string> placement_type = sym.get_opt_attr<std::string>("placement-type");
if (placement_type) {
if (placement_type)
{
placement_finder = placements::registry::instance().from_xml(*placement_type, sym, fontsets_);
} else {
placement_finder = std::make_shared<text_placements_dummy>();
@ -1261,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))
{
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
@ -1632,7 +1583,8 @@ bool map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc,
colorizer_mode default_mode =
node.get_attr<colorizer_mode>("default-mode", COLORIZER_LINEAR);
if(default_mode == COLORIZER_INHERIT) {
if(default_mode == COLORIZER_INHERIT)
{
throw config_error("RasterColorizer mode must not be INHERIT. ");
}
rc->set_default_mode(default_mode);
@ -1649,47 +1601,44 @@ bool map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc,
optional<float> eps = node.get_opt_attr<float>("epsilon");
if (eps)
{
if(*eps < 0) {
if(*eps < 0)
{
throw config_error("RasterColorizer epsilon must be > 0. ");
}
rc->set_epsilon(*eps);
}
xml_node::const_iterator stopIter = node.begin();
xml_node::const_iterator endStop = node.end();
float maximumValue = -std::numeric_limits<float>::max();
for(; stopIter != endStop; ++stopIter)
for (auto const& n : node)
{
if (stopIter->is("stop"))
if (n.is("stop"))
{
found_stops = true;
// colour is optional.
optional<color> stopcolor = stopIter->get_opt_attr<color>("color");
if (!stopcolor) {
optional<color> stopcolor = n.get_opt_attr<color>("color");
if (!stopcolor)
{
*stopcolor = *default_color;
}
// mode default to INHERIT
colorizer_mode mode =
stopIter->get_attr<colorizer_mode>("mode", COLORIZER_INHERIT);
colorizer_mode mode = n.get_attr<colorizer_mode>("mode", COLORIZER_INHERIT);
// value is required, and it must be bigger than the previous
optional<float> value =
stopIter->get_opt_attr<float>("value");
optional<float> value = n.get_opt_attr<float>("value");
if(!value) {
if(!value)
{
throw config_error("stop tag missing value");
}
if(value < maximumValue) {
if(value < maximumValue)
{
throw config_error("stop tag values must be in ascending order");
}
maximumValue = *value;
optional<std::string> label =
stopIter->get_opt_attr<std::string>("label");
optional<std::string> label = n.get_opt_attr<std::string>("label");
//append the stop
colorizer_stop tmpStop;
@ -1697,7 +1646,9 @@ bool map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc,
tmpStop.set_mode(mode);
tmpStop.set_value(*value);
if (label)
{
tmpStop.set_label(*label);
}
rc->add_stop(tmpStop);
}

View file

@ -140,12 +140,12 @@ Map::const_style_iterator Map::end_styles() const
// TODO(dane) - only kept for python bindings, can we avoid needing?
bool Map::insert_style(std::string const& name,feature_type_style const& style)
{
return styles_.insert(std::move(make_pair(name,style))).second;
return styles_.insert(make_pair(name,style)).second;
}
bool Map::insert_style(std::string const& name,feature_type_style && style)
{
return styles_.insert(std::move(make_pair(name,std::move(style)))).second;
return styles_.insert(make_pair(name, std::move(style))).second;
}
void Map::remove_style(std::string const& name)
@ -168,7 +168,7 @@ bool Map::insert_fontset(std::string const& name, font_set const& fontset)
{
throw mapnik::config_error("Fontset name must match the name used to reference it on the map");
}
return fontsets_.insert(std::move(make_pair(name, fontset))).second;
return fontsets_.insert(make_pair(name, fontset)).second;
}
bool Map::insert_fontset(std::string const& name, font_set && fontset)
@ -177,7 +177,7 @@ bool Map::insert_fontset(std::string const& name, font_set && fontset)
{
throw mapnik::config_error("Fontset name must match the name used to reference it on the map");
}
return fontsets_.insert(std::move(make_pair(name, std::move(fontset)))).second;
return fontsets_.insert(make_pair(name, std::move(fontset))).second;
}
boost::optional<font_set const&> Map::find_fontset(std::string const& name) const

View file

@ -31,30 +31,22 @@
// boost
#include <boost/variant.hpp>
// stl
#include <stdexcept>
namespace mapnik {
path_expression_ptr parse_path(std::string const& str)
{
static const 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;
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
{

View file

@ -23,48 +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>();
static const transform_expression_grammar_string gte;
if (!parse_transform(*tl, str, gte))
{
tl.reset();
}
return tl;
}
bool parse_transform(transform_list& tl,
std::string const& str)
{
static const transform_expression_grammar_string gte;
return parse_transform(tl, str, gte);
}
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

View file

@ -576,19 +576,33 @@ private:
switch (type)
{
case wkbPoint: s << "Point"; break;
case wkbLineString: s << "LineString"; break;
case wkbPolygon: s << "Polygon"; break;
case wkbMultiPoint: s << "MultiPoint"; break;
case wkbMultiLineString: s << "MultiLineString"; break;
case wkbMultiPolygon: s << "MultiPolygon"; break;
case wkbGeometryCollection: s << "GeometryCollection"; break;
case wkbPointZ: s << "PointZ"; break;
case wkbLineStringZ: s << "LineStringZ"; break;
case wkbPolygonZ: s << "PolygonZ"; break;
case wkbPointM: s << "PointM"; break;
case wkbPointZM: s << "PointZM"; break;
case wkbMultiPoint: s << "MultiPoint"; break;
case wkbMultiPointZ: s << "MultiPointZ"; break;
case wkbMultiPointM: s << "MultiPointM"; break;
case wkbMultiPointZM: s << "MultiPointZM"; break;
case wkbLineString: s << "LineString"; break;
case wkbLineStringZ: s << "LineStringZ"; break;
case wkbLineStringM: s << "LineStringM"; break;
case wkbLineStringZM: s << "LineStringZM"; break;
case wkbMultiLineString: s << "MultiLineString"; break;
case wkbMultiLineStringZ: s << "MultiLineStringZ"; break;
case wkbMultiLineStringM: s << "MultiLineStringM"; break;
case wkbMultiLineStringZM: s << "MultiLineStringZM"; break;
case wkbPolygon: s << "Polygon"; break;
case wkbPolygonZ: s << "PolygonZ"; break;
case wkbPolygonM: s << "PolygonM"; break;
case wkbPolygonZM: s << "PolygonZM"; break;
case wkbMultiPolygon: s << "MultiPolygon"; break;
case wkbMultiPolygonZ: s << "MultiPolygonZ"; break;
case wkbMultiPolygonM: s << "MultiPolygonM"; break;
case wkbMultiPolygonZM: s << "MultiPolygonZM"; break;
case wkbGeometryCollection: s << "GeometryCollection"; break;
case wkbGeometryCollectionZ: s << "GeometryCollectionZ"; break;
case wkbGeometryCollectionM: s << "GeometryCollectionM"; break;
case wkbGeometryCollectionZM: s << "GeometryCollectionZM"; break;
default: s << "wkbUnknown(" << type << ")"; break;
}

View file

@ -228,7 +228,7 @@ xml_node &xml_node::add_child(std::string && name, unsigned line, bool is_text)
void xml_node::add_attribute(const char * name, const char * value)
{
attributes_.insert(std::move(std::make_pair(name,std::move(xml_attribute(value)))));
attributes_.insert(std::make_pair(name,xml_attribute(value)));
}
xml_node::attribute_map const& xml_node::get_attributes() const

View file

@ -2,7 +2,7 @@
<Map minimum-version="0.7.2">
<Style name="some_style">
<Rule>
<LineSymbolizer stroke-width="foobar"/>
<LineSymbolizer stroke-width="foobar 2"/>
</Rule>
</Style>
</Map>

View file

@ -68,17 +68,6 @@ wkbs = [
[ 0, "LINESTRING EMPTY", '010200000000000000'],
[ 0, "MULTILINESTRING EMPTY", '010500000000000000'],
[ 0, "Polygon EMPTY", '010300000000000000'],
[ 0, "MULTIPOLYGON EMPTY", '010600000000000000'],
[ 0, "TRIANGLE EMPTY", '011100000000000000'],
[ 0, "CircularString EMPTY", '010800000000000000'],
[ 0, "CurvePolygon EMPTY", '010A00000000000000'],
[ 0, "CompoundCurve EMPTY", '010900000000000000'],
[ 0, "MultiCurve EMPTY", '010B00000000000000'],
[ 0, "MultiSurface EMPTY", '010C00000000000000'],
[ 0, "PolyhedralSurface EMPTY", '010F00000000000000'],
[ 0, "TIN EMPTY", '011000000000000000'],
[ 0, "GEOMETRYCOLLECTION EMPTY", '010700000000000000'],
[ 2, "GEOMETRYCOLLECTION(MULTILINESTRING((10 10,20 20,10 40),(40 40,30 30,40 20,30 10)),LINESTRING EMPTY)", '010700000002000000010500000002000000010200000003000000000000000000244000000000000024400000000000003440000000000000344000000000000024400000000000004440010200000004000000000000000000444000000000000044400000000000003e400000000000003e40000000000000444000000000000034400000000000003e400000000000002440010200000000000000'
],
@ -88,10 +77,22 @@ wkbs = [
[ 1, "GEOMETRYCOLLECTION(POINT EMPTY,MULTIPOINT(0 0))", '010700000002000000010400000000000000010400000001000000010100000000000000000000000000000000000000'],
[ 0, "LINESTRING EMPTY", '010200000000000000' ],
[ 1, "Point(0 0)", '010100000000000000000000000000000000000000' ],
# a few bogus inputs
[ 0, "", '' ],
[ 0, "00", '01' ],
[ 0, "0000", '0104' ],
# unsupported types
[ 0, "MULTIPOLYGON EMPTY", '010600000000000000'],
[ 0, "TRIANGLE EMPTY", '011100000000000000'],
[ 0, "CircularString EMPTY", '010800000000000000'],
[ 0, "CurvePolygon EMPTY", '010A00000000000000'],
[ 0, "CompoundCurve EMPTY", '010900000000000000'],
[ 0, "MultiCurve EMPTY", '010B00000000000000'],
[ 0, "MultiSurface EMPTY", '010C00000000000000'],
[ 0, "PolyhedralSurface EMPTY", '010F00000000000000'],
[ 0, "TIN EMPTY", '011000000000000000'],
# TODO - a few bogus inputs
# enable if we start range checking to avoid crashing on invalid input?
# https://github.com/mapnik/mapnik/issues/2236
#[ 0, "", '' ],
#[ 0, "00", '01' ],
#[ 0, "0000", '0104' ],
]
def test_path_geo_interface():