summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/layer.cpp.ejs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/layers/layer.cpp.ejs')
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs87
1 files changed, 57 insertions, 30 deletions
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
index 0cd9a82d75..775288264f 100644
--- a/src/mbgl/style/layers/layer.cpp.ejs
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -3,8 +3,6 @@
const layoutProperties = locals.layoutProperties;
const paintProperties = locals.paintProperties;
-%>
-// clang-format off
-
// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`.
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp>
@@ -190,24 +188,42 @@ 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 {
+namespace {
+
+enum class Property : uint8_t {
<% for (const property of paintProperties) { -%>
- <%- camelize(property.name) %>,
+ <%- camelize(property.name) %>,
<% } -%>
<% for (const property of paintProperties) { -%>
- <%- camelize(property.name) %>Transition,
+ <%- camelize(property.name) %>Transition,
+<% } -%>
+<% for (const property of layoutProperties) { -%>
+ <%- camelize(property.name) %>,
<% } -%>
- };
+};
- MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({
- <%- paintProperties.map(p => `{ "${p.name}", mbgl::underlying_type(Property::${camelize(p.name)}) }`).join(',\n ') %>,
- <%- paintProperties.map(p => `{ "${p.name}-transition", mbgl::underlying_type(Property::${camelize(p.name)}Transition) }`).join(',\n ') %>
- });
+template <typename T>
+constexpr uint8_t toUint8(T t) noexcept {
+ return uint8_t(mbgl::underlying_type(t));
+}
- const auto it = properties.find(name.c_str());
- if (it == properties.end()) {
- return Error { "layer doesn't support this property" };
+MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>(
+ {<%- paintProperties.map(p => `{"${p.name}", toUint8(Property::${camelize(p.name)})}`).join(',\n ') %>,
+<% if (!layoutProperties.length) { -%>
+ <%- paintProperties.map(p => `{"${p.name}-transition", toUint8(Property::${camelize(p.name)}Transition)}`).join(',\n ') %>});
+<% } else { -%>
+ <%- paintProperties.map(p => `{"${p.name}-transition", toUint8(Property::${camelize(p.name)}Transition)}`).join(',\n ') %>,
+ <%- layoutProperties.map(p => `{"${p.name}", toUint8(Property::${camelize(p.name)})}`).join(',\n ') %>});
+<% } -%>
+
+<% const lastPaintProperty = paintProperties[paintProperties.length - 1]; -%>
+<%-`constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::${camelize(lastPaintProperty.name)}Transition);` %>
+} // namespace
+
+optional<Error> <%- camelize(type) %>Layer::setPaintProperty(const std::string& name, const Convertible& value) {
+ const auto it = layerProperties.find(name.c_str());
+ if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) {
+ return Error{"layer doesn't support this property"};
}
auto property = static_cast<Property>(it->second);
@@ -248,14 +264,36 @@ optional<Error> <%- camelize(type) %>Layer::setPaintProperty(const std::string&
if (!transition) {
return error;
}
- <% for (const property of paintProperties) { %>
+<% for (const property of paintProperties) { %>
if (property == Property::<%- camelize(property.name) %>Transition) {
set<%- camelize(property.name) %>Transition(*transition);
return nullopt;
}
- <% } %>
+<% } %>
+ return Error{"layer doesn't support this property"};
+}
- return Error { "layer doesn't support this property" };
+StyleProperty <%- camelize(type) %>Layer::getProperty(const std::string& name) const {
+ const auto it = layerProperties.find(name.c_str());
+ if (it == layerProperties.end()) {
+ return {};
+ }
+
+ switch (static_cast<Property>(it->second)) {
+<% for (const property of paintProperties) { -%>
+ case Property::<%- camelize(property.name) %>:
+ return makeStyleProperty(get<%- camelize(property.name) %>());
+<% } -%>
+<% for (const property of paintProperties) { -%>
+ case Property::<%- camelize(property.name) %>Transition:
+ return makeStyleProperty(get<%- camelize(property.name) %>Transition());
+<% } -%>
+<% for (const property of layoutProperties) { -%>
+ case Property::<%- camelize(property.name) %>:
+ return makeStyleProperty(get<%- camelize(property.name) %>());
+<% } -%>
+ }
+ return {};
}
optional<Error> <%- camelize(type) %>Layer::setLayoutProperty(const std::string& name, const Convertible& value) {
@@ -263,17 +301,8 @@ optional<Error> <%- camelize(type) %>Layer::setLayoutProperty(const std::string&
return Layer::setVisibility(value);
}
<% if (layoutProperties.length) { -%>
- enum class Property {
-<% 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}", mbgl::underlying_type(Property::${camelize(p.name)}) }`).join(',\n ') %>
- });
-
- const auto it = properties.find(name.c_str());
- if (it == properties.end()) {
+ const auto it = layerProperties.find(name.c_str());
+ if (it == layerProperties.end() || it->second <= lastPaintPropertyIndex) {
return Error { "layer doesn't support this property" };
}
@@ -319,5 +348,3 @@ Mutable<Layer::Impl> <%- camelize(type) %>Layer::mutableBaseImpl() const {
} // namespace style
} // namespace mbgl
-
-// clang-format on