diff options
Diffstat (limited to 'src/mbgl/style/layers/layer.cpp.ejs')
-rw-r--r-- | src/mbgl/style/layers/layer.cpp.ejs | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index e34386fc20..fcae615fe0 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -14,7 +14,8 @@ #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion_impl.hpp> -#include <mbgl/util/fnv_hash.hpp> + +#include <mapbox/eternal.hpp> namespace mbgl { namespace style { @@ -170,8 +171,7 @@ TransitionOptions <%- camelize(type) %>Layer::get<%- camelize(property.name) %>T using namespace conversion; optional<Error> <%- camelize(type) %>Layer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { <% for (const property of paintProperties) { -%> <%- camelize(property.name) %>, <% } -%> @@ -180,26 +180,18 @@ optional<Error> <%- camelize(type) %>Layer::setPaintProperty(const std::string& <% } -%> }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - <% for (const property of paintProperties) { -%> -case util::hashFNV1a("<%- property.name %>"): - if (name == "<%- property.name %>") { - property = Property::<%- camelize(property.name) %>; - } - break; - case util::hashFNV1a("<%- property.name %>-transition"): - if (name == "<%- property.name %>-transition") { - property = Property::<%- camelize(property.name) %>Transition; - } - break; - <% } %> - } + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({ + <%- paintProperties.map(p => `{ "${p.name}", static_cast<uint8_t>(Property::${camelize(p.name)}) }`).join(',\n ') %>, + <%- paintProperties.map(p => `{ "${p.name}-transition", static_cast<uint8_t>(Property::${camelize(p.name)}Transition) }`).join(',\n ') %> + }); - if (property == Property::Unknown) { + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast<Property>(it->second); + <% const paintConversions = {}; for (const property of paintProperties) { @@ -250,29 +242,23 @@ optional<Error> <%- camelize(type) %>Layer::setLayoutProperty(const std::string& if (name == "visibility") { return Layer::setVisibility(value); } - +<% if (layoutProperties.length) { -%> enum class Property { - Unknown, <% for (const property of layoutProperties) { -%> <%- camelize(property.name) %>, <% } -%> }; + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({ + <%- layoutProperties.map(p => `{ "${p.name}", static_cast<uint8_t>(Property::${camelize(p.name)}) }`).join(',\n ') %> + }); - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - <% for (const property of layoutProperties) { %> - case util::hashFNV1a("<%- property.name %>"): - if (name == "<%- property.name %>") { - property = Property::<%- camelize(property.name) %>; - } - break; - <% } %> - } - - if (property == Property::Unknown) { + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast<Property>(it->second); + <% const layoutConversions = {}; for (const property of layoutProperties) { @@ -303,7 +289,7 @@ optional<Error> <%- camelize(type) %>Layer::setLayoutProperty(const std::string& <% } %> } <% } %> - +<% } /* if (layoutProperties.length) */ %> return Error { "layer doesn't support this property" }; } |