From 87abf93da35b153de0f0bb4187d1baad954a4a65 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 14 Jun 2017 13:53:32 +0200 Subject: [PATCH] move `name_to_int` into separate header for re-use. --- include/mapnik/util/name_to_int.hpp | 30 +++++++++++++++++++++++++ src/load_map.cpp | 35 +++++++++++++---------------- 2 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 include/mapnik/util/name_to_int.hpp diff --git a/include/mapnik/util/name_to_int.hpp b/include/mapnik/util/name_to_int.hpp new file mode 100644 index 000000000..096a1f085 --- /dev/null +++ b/include/mapnik/util/name_to_int.hpp @@ -0,0 +1,30 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2017 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +namespace mapnik { namespace util { + +constexpr unsigned name_to_int(const char *str, int off = 0) +{ + return !str[off] ? 5381 : (name_to_int(str, off + 1) * 33) ^ static_cast(str[off]); +} + +}} diff --git a/src/load_map.cpp b/src/load_map.cpp index 20727fcdb..6db669709 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -81,11 +82,7 @@ using boost::tokenizer; namespace mapnik { using boost::optional; - -constexpr unsigned name2int(const char *str, int off = 0) -{ - return !str[off] ? 5381 : (name2int(str, off+1)*33) ^ static_cast(str[off]); -} +using util::name_to_int; class map_parser : util::noncopyable { @@ -852,57 +849,57 @@ void map_parser::parse_symbolizers(rule & rule, xml_node const & node) rule.reserve(node.size()); for (auto const& sym_node : node) { - switch (name2int(sym_node.name().c_str())) + switch (name_to_int(sym_node.name().c_str())) { - case name2int("PointSymbolizer"): + case name_to_int("PointSymbolizer"): parse_point_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("LinePatternSymbolizer"): + case name_to_int("LinePatternSymbolizer"): parse_line_pattern_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("PolygonPatternSymbolizer"): + case name_to_int("PolygonPatternSymbolizer"): parse_polygon_pattern_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("TextSymbolizer"): + case name_to_int("TextSymbolizer"): parse_text_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("ShieldSymbolizer"): + case name_to_int("ShieldSymbolizer"): parse_shield_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("LineSymbolizer"): + case name_to_int("LineSymbolizer"): parse_line_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("PolygonSymbolizer"): + case name_to_int("PolygonSymbolizer"): parse_polygon_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("BuildingSymbolizer"): + case name_to_int("BuildingSymbolizer"): parse_building_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("RasterSymbolizer"): + case name_to_int("RasterSymbolizer"): parse_raster_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("MarkersSymbolizer"): + case name_to_int("MarkersSymbolizer"): parse_markers_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("GroupSymbolizer"): + case name_to_int("GroupSymbolizer"): parse_group_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("DebugSymbolizer"): + case name_to_int("DebugSymbolizer"): parse_debug_symbolizer(rule, sym_node); sym_node.set_processed(true); break; - case name2int("DotSymbolizer"): + case name_to_int("DotSymbolizer"): parse_dot_symbolizer(rule, sym_node); sym_node.set_processed(true); break;