more explicit conversions to the target variant type
This commit is contained in:
parent
3c86ab77c4
commit
2864d90460
9 changed files with 45 additions and 26 deletions
|
@ -51,6 +51,10 @@ struct value_holder : value_holder_base
|
|||
value_holder()
|
||||
: value_holder_base() {}
|
||||
|
||||
// C-string -> std::string
|
||||
value_holder(char const* str)
|
||||
: value_holder(std::string(str)) {}
|
||||
|
||||
// perfect forwarding
|
||||
template <typename T>
|
||||
value_holder(T && obj)
|
||||
|
|
|
@ -101,7 +101,7 @@ struct strict_value : value_base_type
|
|||
strict_value() = default;
|
||||
|
||||
strict_value(const char* val)
|
||||
: value_base_type(val) {}
|
||||
: value_base_type(std::string(val)) {}
|
||||
|
||||
template <typename T>
|
||||
strict_value(T const& obj)
|
||||
|
|
|
@ -55,7 +55,7 @@ struct do_xml_attribute_cast
|
|||
{
|
||||
static inline boost::optional<T> xml_attribute_cast_impl(xml_tree const& /*tree*/, std::string const& /*source*/)
|
||||
{
|
||||
std::string err_msg("No conversion from std::string to");
|
||||
std::string err_msg("No conversion from std::string to ");
|
||||
err_msg += std::string(typeid(T).name());
|
||||
throw std::runtime_error(err_msg);
|
||||
}
|
||||
|
@ -74,6 +74,19 @@ struct do_xml_attribute_cast<mapnik::boolean_type>
|
|||
}
|
||||
};
|
||||
|
||||
// specialization for mapnik::value_bool
|
||||
template <>
|
||||
struct do_xml_attribute_cast<mapnik::value_bool>
|
||||
{
|
||||
static inline boost::optional<mapnik::value_bool> xml_attribute_cast_impl(xml_tree const& /*tree*/, std::string const& source)
|
||||
{
|
||||
bool result;
|
||||
if (mapnik::util::string2bool(source, result))
|
||||
return boost::optional<mapnik::value_bool>(result);
|
||||
return boost::optional<mapnik::value_bool>();
|
||||
}
|
||||
};
|
||||
|
||||
// specialization for int
|
||||
template <>
|
||||
struct do_xml_attribute_cast<int>
|
||||
|
|
|
@ -479,7 +479,7 @@ postgis_datasource::postgis_datasource(parameters const& params)
|
|||
// Finally, add unique metadata to layer descriptor
|
||||
mapnik::parameters & extra_params = desc_.get_extra_parameters();
|
||||
// explicitly make copies of values due to https://github.com/mapnik/mapnik/issues/2651
|
||||
extra_params["srid"] = srid_;
|
||||
extra_params["srid"] = mapnik::value_integer(srid_);
|
||||
if (!key_field_.empty())
|
||||
{
|
||||
extra_params["key_field"] = key_field_;
|
||||
|
|
|
@ -200,7 +200,7 @@ void map_parser::parse_map(Map & map, xml_node const& node, std::string const& b
|
|||
{
|
||||
map.set_background(*bgcolor);
|
||||
}
|
||||
|
||||
|
||||
optional<std::string> image_filename = map_node.get_opt_attr<std::string>("background-image");
|
||||
if (image_filename)
|
||||
{
|
||||
|
@ -891,7 +891,7 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const& nod
|
|||
{
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::simplify_tolerance, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::smooth, node);
|
||||
set_symbolizer_property<symbolizer_base,boolean_type>(sym, keys::clip, node);
|
||||
set_symbolizer_property<symbolizer_base,value_bool>(sym, keys::clip, node);
|
||||
set_symbolizer_property<symbolizer_base,composite_mode_e>(sym, keys::comp_op, node);
|
||||
set_symbolizer_property<symbolizer_base,transform_type>(sym, keys::geometry_transform, node);
|
||||
set_symbolizer_property<symbolizer_base,simplify_algorithm_e>(sym, keys::simplify_algorithm, node);
|
||||
|
@ -907,8 +907,8 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & node)
|
|||
point_symbolizer sym;
|
||||
parse_symbolizer_base(sym, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::opacity, node);
|
||||
set_symbolizer_property<symbolizer_base,boolean_type>(sym, keys::allow_overlap, node);
|
||||
set_symbolizer_property<symbolizer_base,boolean_type>(sym, keys::ignore_placement, node);
|
||||
set_symbolizer_property<symbolizer_base,value_bool>(sym, keys::allow_overlap, node);
|
||||
set_symbolizer_property<symbolizer_base,value_bool>(sym, keys::ignore_placement, node);
|
||||
set_symbolizer_property<symbolizer_base,point_placement_enum>(sym, keys::point_placement_type, node);
|
||||
set_symbolizer_property<symbolizer_base,transform_type>(sym, keys::image_transform, node);
|
||||
if (file && !file->empty())
|
||||
|
@ -1011,9 +1011,9 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& node)
|
|||
set_symbolizer_property<symbolizer_base,double>(sym, keys::offset, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::width, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::height, node);
|
||||
set_symbolizer_property<symbolizer_base,boolean_type>(sym, keys::allow_overlap, node);
|
||||
set_symbolizer_property<symbolizer_base,boolean_type>(sym, keys::avoid_edges, node);
|
||||
set_symbolizer_property<symbolizer_base,boolean_type>(sym, keys::ignore_placement, node);
|
||||
set_symbolizer_property<symbolizer_base,value_bool>(sym, keys::allow_overlap, node);
|
||||
set_symbolizer_property<symbolizer_base,value_bool>(sym, keys::avoid_edges, node);
|
||||
set_symbolizer_property<symbolizer_base,value_bool>(sym, keys::ignore_placement, node);
|
||||
set_symbolizer_property<symbolizer_base,color>(sym, keys::fill, node);
|
||||
set_symbolizer_property<symbolizer_base,transform_type>(sym, keys::image_transform, node);
|
||||
set_symbolizer_property<symbolizer_base,marker_placement_enum>(sym, keys::markers_placement_type, node);
|
||||
|
@ -1172,7 +1172,7 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& node)
|
|||
set_symbolizer_property<symbolizer_base,double>(sym, keys::shield_dx, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::shield_dy, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::opacity, node);
|
||||
set_symbolizer_property<symbolizer_base,mapnik::boolean_type>(sym, keys::unlock_image, node);
|
||||
set_symbolizer_property<symbolizer_base,value_bool>(sym, keys::unlock_image, node);
|
||||
|
||||
std::string file = node.get_attr<std::string>("file");
|
||||
if (file.empty())
|
||||
|
@ -1343,7 +1343,7 @@ void map_parser::parse_raster_symbolizer(rule & rule, xml_node const & node)
|
|||
|
||||
// premultiplied status of image
|
||||
optional<mapnik::boolean_type> premultiplied = node.get_opt_attr<mapnik::boolean_type>("premultiplied");
|
||||
if (premultiplied) put(raster_sym, keys::premultiplied, *premultiplied);
|
||||
if (premultiplied) put(raster_sym, keys::premultiplied, bool(*premultiplied));
|
||||
|
||||
bool found_colorizer = false;
|
||||
for ( auto const& css : node)
|
||||
|
|
|
@ -75,9 +75,9 @@ node_ptr layout_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
|
|||
if (xml.has_attribute("text-ratio")) set_property_from_xml<double>(n->text_ratio, "text-ratio", xml);
|
||||
if (xml.has_attribute("wrap-width")) set_property_from_xml<double>(n->wrap_width, "wrap-width", xml);
|
||||
if (xml.has_attribute("wrap-character")) set_property_from_xml<std::string>(n->wrap_char, "wrap-character", xml);
|
||||
if (xml.has_attribute("wrap-before")) set_property_from_xml<mapnik::boolean_type>(n->wrap_before, "wrap-before", xml);
|
||||
if (xml.has_attribute("repeat-wrap-character")) set_property_from_xml<mapnik::boolean_type>(n->repeat_wrap_char, "repeat-wrap-character", xml);
|
||||
if (xml.has_attribute("rotate-displacement")) set_property_from_xml<mapnik::boolean_type>(n->rotate_displacement, "rotate-displacement", xml);
|
||||
if (xml.has_attribute("wrap-before")) set_property_from_xml<mapnik::value_bool>(n->wrap_before, "wrap-before", xml);
|
||||
if (xml.has_attribute("repeat-wrap-character")) set_property_from_xml<mapnik::value_bool>(n->repeat_wrap_char, "repeat-wrap-character", xml);
|
||||
if (xml.has_attribute("rotate-displacement")) set_property_from_xml<mapnik::value_bool>(n->rotate_displacement, "rotate-displacement", xml);
|
||||
if (xml.has_attribute("orientation")) set_property_from_xml<double>(n->orientation, "orientation", xml);
|
||||
if (xml.has_attribute("horizontal-alignment")) set_property_from_xml<horizontal_alignment_e>(n->halign, "horizontal-alignment", xml);
|
||||
if (xml.has_attribute("vertical-alignment")) set_property_from_xml<vertical_alignment_e>(n->valign, "vertical-alignment", xml);
|
||||
|
|
|
@ -103,9 +103,9 @@ void text_symbolizer_properties::text_properties_from_xml(xml_node const& node)
|
|||
set_property_from_xml<value_double>(expressions.label_position_tolerance, "label-position-tolerance", node);
|
||||
set_property_from_xml<value_double>(expressions.minimum_padding, "minimum-padding", node);
|
||||
set_property_from_xml<value_double>(expressions.minimum_path_length, "minimum-path-length", node);
|
||||
set_property_from_xml<boolean_type>(expressions.avoid_edges, "avoid-edges", node);
|
||||
set_property_from_xml<boolean_type>(expressions.allow_overlap, "allow-overlap", node);
|
||||
set_property_from_xml<boolean_type>(expressions.largest_bbox_only, "largest-bbox-only", node);
|
||||
set_property_from_xml<value_bool>(expressions.avoid_edges, "avoid-edges", node);
|
||||
set_property_from_xml<value_bool>(expressions.allow_overlap, "allow-overlap", node);
|
||||
set_property_from_xml<value_bool>(expressions.largest_bbox_only, "largest-bbox-only", node);
|
||||
set_property_from_xml<value_double>(expressions.max_char_angle_delta, "max-char-angle-delta", node);
|
||||
set_property_from_xml<text_upright_e>(expressions.upright, "upright", node);
|
||||
}
|
||||
|
@ -215,9 +215,9 @@ void text_layout_properties::from_xml(xml_node const &node, fontset_map const& f
|
|||
set_property_from_xml<double>(text_ratio, "text-ratio", node);
|
||||
set_property_from_xml<double>(wrap_width, "wrap-width", node);
|
||||
set_property_from_xml<std::string>(wrap_char, "wrap-character", node);
|
||||
set_property_from_xml<boolean_type>(wrap_before, "wrap-before", node);
|
||||
set_property_from_xml<boolean_type>(repeat_wrap_char, "repeat-wrap-character", node);
|
||||
set_property_from_xml<boolean_type>(rotate_displacement, "rotate-displacement", node);
|
||||
set_property_from_xml<value_bool>(wrap_before, "wrap-before", node);
|
||||
set_property_from_xml<value_bool>(repeat_wrap_char, "repeat-wrap-character", node);
|
||||
set_property_from_xml<value_bool>(rotate_displacement, "rotate-displacement", node);
|
||||
set_property_from_xml<double>(orientation, "orientation", node);
|
||||
set_property_from_xml<vertical_alignment_e>(valign, "vertical-alignment", node);
|
||||
set_property_from_xml<horizontal_alignment_e>(halign, "horizontal-alignment", node);
|
||||
|
|
|
@ -69,6 +69,7 @@ DEFINE_NAME_TRAIT( double, "double")
|
|||
DEFINE_NAME_TRAIT( float, "float")
|
||||
DEFINE_NAME_TRAIT( unsigned, "unsigned")
|
||||
DEFINE_NAME_TRAIT( int, "int")
|
||||
DEFINE_NAME_TRAIT( bool, "bool")
|
||||
DEFINE_NAME_TRAIT( boolean_type, "boolean_type")
|
||||
#ifdef BIGINT
|
||||
DEFINE_NAME_TRAIT( mapnik::value_integer, "long long" )
|
||||
|
@ -411,6 +412,7 @@ std::string xml_node::line_to_string() const
|
|||
#define compile_get_value(T) template T xml_node::get_value<T>() const
|
||||
|
||||
compile_get_opt_attr(boolean_type);
|
||||
compile_get_opt_attr(mapnik::value_bool);
|
||||
compile_get_opt_attr(std::string);
|
||||
compile_get_opt_attr(int);
|
||||
compile_get_opt_attr(unsigned);
|
||||
|
|
|
@ -352,23 +352,23 @@ void pgsql2sqlite(Connection conn,
|
|||
break;
|
||||
}
|
||||
case 23:
|
||||
output_rec.push_back(sqlite::value_type(int4net(buf)));
|
||||
output_rec.emplace_back(int4net(buf));
|
||||
break;
|
||||
case 21:
|
||||
output_rec.push_back(sqlite::value_type(int2net(buf)));
|
||||
output_rec.emplace_back(int(int2net(buf)));
|
||||
break;
|
||||
case 700:
|
||||
{
|
||||
float val;
|
||||
float4net(val,buf);
|
||||
output_rec.push_back(sqlite::value_type(val));
|
||||
output_rec.emplace_back(double(val));
|
||||
break;
|
||||
}
|
||||
case 701:
|
||||
{
|
||||
double val;
|
||||
float8net(val,buf);
|
||||
output_rec.push_back(sqlite::value_type(val));
|
||||
output_rec.emplace_back(val);
|
||||
break;
|
||||
}
|
||||
case 1700:
|
||||
|
@ -377,7 +377,7 @@ void pgsql2sqlite(Connection conn,
|
|||
double val;
|
||||
if (mapnik::util::string2double(str,val))
|
||||
{
|
||||
output_rec.push_back(sqlite::value_type(val));
|
||||
output_rec.emplace_back(val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue