ENUM_FROM_STRING macro to keep things tidy and scalable

This commit is contained in:
artemp 2014-06-30 17:41:33 +01:00
parent 79fa672843
commit 2271e7413c
2 changed files with 21 additions and 37 deletions

View file

@ -277,43 +277,26 @@ struct enum_traits<composite_mode_e>
}
};
template <>
struct enum_traits<line_join_enum>
{
typedef boost::optional<line_join_enum> result_type;
static result_type from_string(std::string const& str)
{
enumeration<line_join_enum,line_join_enum_MAX> e;
try
{
e.from_string(str);
return result_type(line_join_enum(e));
}
catch (...)
{
return result_type();
}
}
};
#define ENUM_FROM_STRING( e ) \
template <> struct enum_traits<e> { \
typedef boost::optional<e> result_type; \
static result_type from_string(std::string const& str) \
{ \
enumeration<e, e ## _MAX> enum_; \
try \
{ \
enum_.from_string(str); \
return result_type(e(enum_)); \
} \
catch (...) \
{ \
return result_type(); \
} \
} \
};\
template <>
struct enum_traits<line_cap_enum>
{
typedef boost::optional<line_cap_enum> result_type;
static result_type from_string(std::string const& str)
{
enumeration<line_cap_enum,line_cap_enum_MAX> e;
try
{
e.from_string(str);
return result_type(line_cap_enum(e));
}
catch (...)
{
return result_type();
}
}
};
ENUM_FROM_STRING( line_join_enum )
ENUM_FROM_STRING( line_cap_enum )
// enum
template <typename T, bool is_enum = true>

View file

@ -891,12 +891,13 @@ struct set_symbolizer_property_impl<Symbolizer, T, true>
{
optional<expression_ptr> val = node.get_opt_attr<expression_ptr>(name);
if (val) put(sym, key, *val);
else MAPNIK_LOG_ERROR(Symbolizer) << " failed to parse:" << name;
}
}
}
catch (config_error const& ex)
{
MAPNIK_LOG_ERROR(composite_mode_e) << ex.what();
MAPNIK_LOG_ERROR(Symbolizer) << ex.what();
}
}
};