more generic expressions in enum

support expressions in halo-comp-op symbolizer property
This commit is contained in:
artemp 2014-06-27 16:08:00 +01:00
parent aa9966ed88
commit 19b38c2ed9
3 changed files with 11 additions and 33 deletions

View file

@ -51,8 +51,6 @@
// boost
#include <boost/variant/variant_fwd.hpp>
#include <boost/concept_check.hpp>
// agg
#include "agg_pixfmt_rgba.h"
namespace agg { struct trans_affine; }
@ -132,7 +130,8 @@ enum class property_types : std::uint8_t
target_dash_array,
target_colorizer,
target_repeat_key,
target_group_symbolizer_properties
target_group_symbolizer_properties,
target_halo_comp_op
};
inline bool operator==(symbolizer_base const& lhs, symbolizer_base const& rhs)
@ -174,7 +173,9 @@ struct expression_result
typedef T result_type;
static result_type convert(value_type const& val)
{
return static_cast<T>(val.convert<value_integer>());
auto result = comp_op_from_string(val.to_string());
if (result) return static_cast<result_type>(*result);
return result_type(0);
}
};
@ -188,18 +189,6 @@ struct expression_result<T,false>
}
};
template <>
struct expression_result<agg::comp_op_e,true>
{
typedef agg::comp_op_e result_type;
static result_type convert(value_type const& val)
{
auto result = comp_op_from_string(val.to_string());
if (result) return static_cast<result_type>(*result);
return agg::comp_op_src_over;
}
};
// enum
template <typename T, bool is_enum = true>

View file

@ -862,7 +862,7 @@ struct set_symbolizer_property_impl
}
catch (config_error const&)
{
// try parser as an expression
// try parsing as an expression
optional<expression_ptr> val = node.get_opt_attr<expression_ptr>(name);
if (val) put(sym, key, *val);
}
@ -878,13 +878,14 @@ struct set_symbolizer_property_impl<Symbolizer, composite_mode_e>
std::string const& name = std::get<0>(get_meta(key));
try
{
optional<std::string> comp_op_name = node.get_opt_attr<std::string>("comp-op");
optional<std::string> comp_op_name = node.get_opt_attr<std::string>(name);
if (comp_op_name)
{
optional<composite_mode_e> comp_op = comp_op_from_string(*comp_op_name);
if (comp_op)
{
put(sym, keys::comp_op, *comp_op);
put(sym, key, *comp_op);
}
else
{
@ -1203,19 +1204,7 @@ void map_parser::parse_text_symbolizer(rule & rule, xml_node const& node)
text_symbolizer text_symbol;
parse_symbolizer_base(text_symbol, node);
// halo-comp-op
optional<std::string> comp_op_name = node.get_opt_attr<std::string>("halo-comp-op");
if (comp_op_name)
{
optional<composite_mode_e> halo_comp_op = comp_op_from_string(*comp_op_name);
if (halo_comp_op)
{
put(text_symbol, keys::halo_comp_op, *halo_comp_op);
}
else
{
throw config_error("failed to parse halo-comp-op: '" + *comp_op_name + "'");
}
}
set_symbolizer_property<symbolizer_base,composite_mode_e>(text_symbol, keys::halo_comp_op, node);
put<text_placements_ptr>(text_symbol, keys::text_placements_, placement_finder);
optional<halo_rasterizer_e> halo_rasterizer_ = node.get_opt_attr<halo_rasterizer_e>("halo-rasterizer");

View file

@ -98,7 +98,7 @@ static const property_meta_type key_meta[to_integral(keys::MAX_SYMBOLIZER_KEY)]
property_meta_type{ "largest-box-only", false, nullptr, property_types::target_bool },
property_meta_type{ "minimum-path-length", false, nullptr, property_types::target_double },
property_meta_type{ "halo-comp-op", enumeration_wrapper(src_over),
[](enumeration_wrapper e) { return *comp_op_to_string(composite_mode_e(e.value)); }, property_types::target_comp_op},
[](enumeration_wrapper e) { return *comp_op_to_string(composite_mode_e(e.value)); }, property_types::target_halo_comp_op},
};
property_meta_type const& get_meta(mapnik::keys key)