add UDL via operator"" _case

This commit is contained in:
Artem Pavlenko 2017-11-06 10:31:53 +01:00
parent 1a338bb924
commit 743c14d3ff
3 changed files with 98 additions and 91 deletions

View file

@ -27,4 +27,9 @@ constexpr unsigned name_to_int(const char *str, unsigned off = 0)
return !str[off] ? 5381 : (name_to_int(str, off + 1) * 33) ^ static_cast<unsigned>(str[off]); return !str[off] ? 5381 : (name_to_int(str, off + 1) * 33) ^ static_cast<unsigned>(str[off]);
} }
constexpr unsigned operator"" _case(char const* str, std::size_t)
{
return name_to_int(str);
}
}} }}

View file

@ -83,6 +83,7 @@ namespace mapnik
{ {
using boost::optional; using boost::optional;
using util::name_to_int; using util::name_to_int;
using util::operator"" _case;
class map_parser : util::noncopyable class map_parser : util::noncopyable
{ {
@ -859,55 +860,55 @@ void map_parser::parse_symbolizers(rule & rule, xml_node const & node)
{ {
switch (name_to_int(sym_node.name().c_str())) switch (name_to_int(sym_node.name().c_str()))
{ {
case name_to_int("PointSymbolizer"): case "PointSymbolizer"_case:
parse_point_symbolizer(rule, sym_node); parse_point_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("LinePatternSymbolizer"): case "LinePatternSymbolizer"_case:
parse_line_pattern_symbolizer(rule, sym_node); parse_line_pattern_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("PolygonPatternSymbolizer"): case "PolygonPatternSymbolizer"_case:
parse_polygon_pattern_symbolizer(rule, sym_node); parse_polygon_pattern_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("TextSymbolizer"): case "TextSymbolizer"_case:
parse_text_symbolizer(rule, sym_node); parse_text_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("ShieldSymbolizer"): case "ShieldSymbolizer"_case:
parse_shield_symbolizer(rule, sym_node); parse_shield_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("LineSymbolizer"): case "LineSymbolizer"_case:
parse_line_symbolizer(rule, sym_node); parse_line_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("PolygonSymbolizer"): case "PolygonSymbolizer"_case:
parse_polygon_symbolizer(rule, sym_node); parse_polygon_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("BuildingSymbolizer"): case "BuildingSymbolizer"_case:
parse_building_symbolizer(rule, sym_node); parse_building_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("RasterSymbolizer"): case "RasterSymbolizer"_case:
parse_raster_symbolizer(rule, sym_node); parse_raster_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("MarkersSymbolizer"): case "MarkersSymbolizer"_case:
parse_markers_symbolizer(rule, sym_node); parse_markers_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("GroupSymbolizer"): case "GroupSymbolizer"_case:
parse_group_symbolizer(rule, sym_node); parse_group_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("DebugSymbolizer"): case "DebugSymbolizer"_case:
parse_debug_symbolizer(rule, sym_node); parse_debug_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;
case name_to_int("DotSymbolizer"): case "DotSymbolizer"_case:
parse_dot_symbolizer(rule, sym_node); parse_dot_symbolizer(rule, sym_node);
sym_node.set_processed(true); sym_node.set_processed(true);
break; break;

View file

@ -58,6 +58,7 @@
namespace mapnik { namespace svg { namespace mapnik { namespace svg {
using util::name_to_int; using util::name_to_int;
using util::operator"" _case;
struct viewbox struct viewbox
{ {
@ -103,59 +104,59 @@ void parse_attr(svg_parser& parser, char const* name, char const* value);
namespace { namespace {
static std::array<unsigned, 7> const unsupported_elements static std::array<unsigned, 7> const unsupported_elements
{ {name_to_int("symbol"), { {"symbol"_case,
name_to_int("marker"), "marker"_case,
name_to_int("view"), "view"_case,
name_to_int("text"), "text"_case,
name_to_int("switch"), "switch"_case,
name_to_int("image"), "image"_case,
name_to_int("a")} "a"_case}
}; };
#if 0 // disable to reduce verbosity #if 0 // disable to reduce verbosity
static std::array<unsigned, 43> const unsupported_attributes static std::array<unsigned, 43> const unsupported_attributes
{ {name_to_int("alignment-baseline"), { {"alignment-baseline"_case,
name_to_int("baseline-shift"), "baseline-shift"_case,
name_to_int("clip"), "clip"_case,
name_to_int("clip-path"), "clip-path"_case,
name_to_int("clip-rule"), "clip-rule"_case,
name_to_int("color-interpolation"), "color-interpolation"_case,
name_to_int("color-interpolation-filters"), "color-interpolation-filters"_case,
name_to_int("color-profile"), "color-profile"_case,
name_to_int("color-rendering"), "color-rendering"_case,
name_to_int("cursor"), "cursor"_case,
name_to_int("direction"), "direction"_case,
name_to_int("dominant-baseline"), "dominant-baseline"_case,
name_to_int("enable-background"), "enable-background"_case,
name_to_int("filter"), "filter"_case,
name_to_int("flood-color"), "flood-color"_case,
name_to_int("flood-opacity"), "flood-opacity"_case,
name_to_int("font-family"), "font-family"_case,
name_to_int("font-size"), "font-size"_case,
name_to_int("font-size-adjust"), "font-size-adjust"_case,
name_to_int("font-stretch"), "font-stretch"_case,
name_to_int("font-style"), "font-style"_case,
name_to_int("font-variant"), "font-variant"_case,
name_to_int("font-weight"), "font-weight"_case,
name_to_int("glyph-orientation-horizontal"), "glyph-orientation-horizontal"_case,
name_to_int("glyph-orientation-vertical"), "glyph-orientation-vertical"_case,
name_to_int("image-rendering"), "image-rendering"_case,
name_to_int("kerning"), "kerning"_case,
name_to_int("letter-spacing"), "letter-spacing"_case,
name_to_int("lighting-color"), "lighting-color"_case,
name_to_int("marker-end"), "marker-end"_case,
name_to_int("marker-mid"), "marker-mid"_case,
name_to_int("marker-start"), "marker-start"_case,
name_to_int("mask"), "mask"_case,
name_to_int("overflow"), "overflow"_case,
name_to_int("pointer-events"), "pointer-events"_case,
name_to_int("shape-rendering"), "shape-rendering"_case,
name_to_int("text-anchor"), "text-anchor"_case,
name_to_int("text-decoration"), "text-decoration"_case,
name_to_int("text-rendering"), "text-rendering"_case,
name_to_int("unicode-bidi"), "unicode-bidi"_case,
name_to_int("word-spacing"), "word-spacing"_case,
name_to_int("writing-mode")} "writing-mode"_case}
}; };
#endif #endif
@ -374,7 +375,7 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node<char> const* node)
{ {
switch(name_to_int(name)) switch(name_to_int(name))
{ {
case name_to_int("defs"): case "defs"_case:
{ {
if (node->first_node() != nullptr) if (node->first_node() != nullptr)
{ {
@ -384,13 +385,13 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node<char> const* node)
} }
// the gradient tags *should* be in defs, but illustrator seems not to put them in there so // the gradient tags *should* be in defs, but illustrator seems not to put them in there so
// accept them anywhere // accept them anywhere
case name_to_int("linearGradient"): case "linearGradient"_case:
parse_linear_gradient(parser, node); parse_linear_gradient(parser, node);
break; break;
case name_to_int("radialGradient"): case "radialGradient"_case:
parse_radial_gradient(parser, node); parse_radial_gradient(parser, node);
break; break;
case name_to_int("symbol"): case "symbol"_case:
parse_id(parser, node); parse_id(parser, node);
//parse_dimensions(parser, node); //parse_dimensions(parser, node);
break; break;
@ -400,7 +401,7 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node<char> const* node)
{ {
switch (name_to_int(name)) switch (name_to_int(name))
{ {
case name_to_int("g"): case "g"_case:
if (node->first_node() != nullptr) if (node->first_node() != nullptr)
{ {
parser.path_.push_attr(); parser.path_.push_attr();
@ -408,7 +409,7 @@ void traverse_tree(svg_parser & parser, rapidxml::xml_node<char> const* node)
parse_attr(parser, node); parse_attr(parser, node);
} }
break; break;
case name_to_int("use"): case "use"_case:
parser.path_.push_attr(); parser.path_.push_attr();
parse_id(parser, node); parse_id(parser, node);
parse_attr(parser, node); parse_attr(parser, node);
@ -487,35 +488,35 @@ void parse_element(svg_parser & parser, char const* name, rapidxml::xml_node<cha
{ {
switch (name_to_int(name)) switch (name_to_int(name))
{ {
case name_to_int("path"): case "path"_case:
parser.path_.transform().multiply(parser.viewbox_tr_); parser.path_.transform().multiply(parser.viewbox_tr_);
parse_path(parser, node); parse_path(parser, node);
break; break;
case name_to_int("polygon"): case "polygon"_case:
parser.path_.transform().multiply(parser.viewbox_tr_); parser.path_.transform().multiply(parser.viewbox_tr_);
parse_polygon(parser, node); parse_polygon(parser, node);
break; break;
case name_to_int("polyline"): case "polyline"_case:
parser.path_.transform().multiply(parser.viewbox_tr_); parser.path_.transform().multiply(parser.viewbox_tr_);
parse_polyline(parser, node); parse_polyline(parser, node);
break; break;
case name_to_int("line"): case "line"_case:
parser.path_.transform().multiply(parser.viewbox_tr_); parser.path_.transform().multiply(parser.viewbox_tr_);
parse_line(parser, node); parse_line(parser, node);
break; break;
case name_to_int("rect"): case "rect"_case:
parser.path_.transform().multiply(parser.viewbox_tr_); parser.path_.transform().multiply(parser.viewbox_tr_);
parse_rect(parser, node); parse_rect(parser, node);
break; break;
case name_to_int("circle"): case "circle"_case:
parser.path_.transform().multiply(parser.viewbox_tr_); parser.path_.transform().multiply(parser.viewbox_tr_);
parse_circle(parser, node); parse_circle(parser, node);
break; break;
case name_to_int("ellipse"): case "ellipse"_case:
parser.path_.transform().multiply(parser.viewbox_tr_); parser.path_.transform().multiply(parser.viewbox_tr_);
parse_ellipse(parser, node); parse_ellipse(parser, node);
break; break;
case name_to_int("svg"): case "svg"_case:
parse_dimensions(parser, node); parse_dimensions(parser, node);
break; break;
default: default:
@ -630,32 +631,32 @@ void parse_attr(svg_parser & parser, char const* name, char const* value )
{ {
switch (name_to_int(name)) switch (name_to_int(name))
{ {
case name_to_int("transform"): case "transform"_case:
parse_transform(parser, value); parse_transform(parser, value);
break; break;
case name_to_int("fill"): case "fill"_case:
parse_fill(parser, value); parse_fill(parser, value);
break; break;
case name_to_int("fill-opacity"): case "fill-opacity"_case:
parser.path_.fill_opacity(parse_double(parser.err_handler(), value)); parser.path_.fill_opacity(parse_double(parser.err_handler(), value));
break; break;
case name_to_int("fill-rule"): case "fill-rule"_case:
if (std::strcmp(value, "evenodd") == 0) if (std::strcmp(value, "evenodd") == 0)
{ {
parser.path_.even_odd(true); parser.path_.even_odd(true);
} }
break; break;
case name_to_int("stroke"): case "stroke"_case:
parse_stroke(parser, value); parse_stroke(parser, value);
break; break;
case name_to_int("stroke-width"): case "stroke-width"_case:
bool percent; bool percent;
parser.path_.stroke_width(parse_svg_value(parser.err_handler(), value, percent)); parser.path_.stroke_width(parse_svg_value(parser.err_handler(), value, percent));
break; break;
case name_to_int("stroke-opacity"): case "stroke-opacity"_case:
parser.path_.stroke_opacity(parse_double(parser.err_handler(), value)); parser.path_.stroke_opacity(parse_double(parser.err_handler(), value));
break; break;
case name_to_int("stroke-linecap"): case "stroke-linecap"_case:
if(std::strcmp(value, "butt") == 0) if(std::strcmp(value, "butt") == 0)
parser.path_.line_cap(agg::butt_cap); parser.path_.line_cap(agg::butt_cap);
else if(std::strcmp(value, "round") == 0) else if(std::strcmp(value, "round") == 0)
@ -663,7 +664,7 @@ void parse_attr(svg_parser & parser, char const* name, char const* value )
else if(std::strcmp(value, "square") == 0) else if(std::strcmp(value, "square") == 0)
parser.path_.line_cap(agg::square_cap); parser.path_.line_cap(agg::square_cap);
break; break;
case name_to_int("stroke-linejoin"): case "stroke-linejoin"_case:
if (std::strcmp(value, "miter") == 0) if (std::strcmp(value, "miter") == 0)
parser.path_.line_join(agg::miter_join); parser.path_.line_join(agg::miter_join);
else if (std::strcmp(value, "round") == 0) else if (std::strcmp(value, "round") == 0)
@ -671,22 +672,22 @@ void parse_attr(svg_parser & parser, char const* name, char const* value )
else if (std::strcmp(value, "bevel") == 0) else if (std::strcmp(value, "bevel") == 0)
parser.path_.line_join(agg::bevel_join); parser.path_.line_join(agg::bevel_join);
break; break;
case name_to_int("stroke-miterlimit"): case "stroke-miterlimit"_case:
parser.path_.miter_limit(parse_double(parser.err_handler(),value)); parser.path_.miter_limit(parse_double(parser.err_handler(),value));
break; break;
case name_to_int("stroke-dasharray"): case "stroke-dasharray"_case:
parse_stroke_dash(parser, value); parse_stroke_dash(parser, value);
break; break;
case name_to_int("stroke-dashoffset"): case "stroke-dashoffset"_case:
parser.path_.dash_offset(parse_double(parser.err_handler(), value)); parser.path_.dash_offset(parse_double(parser.err_handler(), value));
break; break;
case name_to_int("opacity"): case "opacity"_case:
parser.path_.opacity(parse_double(parser.err_handler(), value)); parser.path_.opacity(parse_double(parser.err_handler(), value));
break; break;
case name_to_int("visibility"): case "visibility"_case:
parser.path_.visibility(std::strcmp(value, "hidden") != 0); parser.path_.visibility(std::strcmp(value, "hidden") != 0);
break; break;
case name_to_int("display"): case "display"_case:
if (std::strcmp(value, "none") == 0) if (std::strcmp(value, "none") == 0)
{ {
parser.path_.display(false); parser.path_.display(false);