Files
MapLibreParticleLab/src/mbgl/style/light.cpp.ejs

167 lines
5.4 KiB
Plaintext

<%
const properties = locals.properties;
-%>
// This file is generated. Do not edit.
#include <mbgl/style/light.hpp>
#include <mbgl/style/light_impl.hpp>
#include <mbgl/style/light_observer.hpp>
#include <mbgl/style/conversion/light.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/style/conversion/transition_options.hpp>
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/util/traits.hpp>
#include <mapbox/eternal.hpp>
#include <utility>
namespace mbgl {
namespace style {
static LightObserver nullObserver;
Light::Light(Immutable<Light::Impl> impl_) : impl(std::move(impl_)), observer(&nullObserver) {}
Light::Light() : Light(makeMutable<Impl>()) {}
Light::~Light() = default;
void Light::setObserver(LightObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
}
Mutable<Light::Impl> Light::mutableImpl() const {
return makeMutable<Impl>(*impl);
}
using namespace conversion;
namespace {
enum class Property : uint8_t {
<% for (const property of properties) { -%>
<%- camelize(property.name) %>,
<% } -%>
<% for (const property of properties) { -%>
<%- camelize(property.name) %>Transition,
<% } -%>
};
template <typename T>
constexpr uint8_t toUint8(T t) noexcept {
return uint8_t(mbgl::underlying_type(t));
}
MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>(
{<%- properties.map(p => `{"${p.name}", toUint8(Property::${camelize(p.name)})}`).join(',\n ') %>,
<%- properties.map(p => `{"${p.name}-transition", toUint8(Property::${camelize(p.name)}Transition)}`).join(',\n ') %>});
} // namespace
optional<Error> Light::setProperty(const std::string& name, const Convertible& value) {
const auto it = properties.find(name.c_str());
if (it == properties.end()) {
return Error { "light doesn't support this property" };
}
auto property = static_cast<Property>(it->second);
<%
const conversions = {};
for (const property of properties) {
const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven';
const convertTokens = property.name === 'icon-image' || property.name === 'text-field';
const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`;
conversions[conversion] = conversions[conversion] || [];
conversions[conversion].push(property);
}
-%>
<% for (const key in conversions) {
const properties = conversions[key];
%>
if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) {
Error error;
<%- key %>;
if (!typedValue) {
return error;
}
<% if (properties.length == 1) { %>
set<%- camelize(properties[0].name) %>(*typedValue);
return nullopt;
<% } else for (const property of properties) { %>
if (property == Property::<%- camelize(property.name) %>) {
set<%- camelize(property.name) %>(*typedValue);
return nullopt;
}
<% } %>
}
<% } %>
Error error;
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
if (!transition) {
return error;
}
<% for (const property of properties) { %>
if (property == Property::<%- camelize(property.name) %>Transition) {
set<%- camelize(property.name) %>Transition(*transition);
return nullopt;
}
<% } %>
return Error { "light doesn't support this property" };
}
StyleProperty Light::getProperty(const std::string& name) const {
const auto it = properties.find(name.c_str());
if (it == properties.end()) {
return {};
}
switch (static_cast<Property>(it->second)) {
<% for (const property of properties) { -%>
case Property::<%- camelize(property.name) %>:
return makeStyleProperty(get<%- camelize(property.name) %>());
<% } -%>
<% for (const property of properties) { -%>
case Property::<%- camelize(property.name) %>Transition:
return makeStyleProperty(get<%- camelize(property.name) %>Transition());
<% } -%>
}
return {};
}
<% for (const property of properties) { -%>
<%- evaluatedType(property) %> Light::getDefault<%- camelize(property.name) %>() {
return Light<%- camelize(property.name) %>::defaultValue();
}
<%- propertyValueType(property) %> Light::get<%- camelize(property.name) %>() const {
return impl->properties.template get<Light<%- camelize(property.name) %>>().value;
}
void Light::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> property) {
auto impl_ = mutableImpl();
impl_->properties.template get<Light<%- camelize(property.name) %>>().value = std::move(property);
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::set<%- camelize(property.name) %>Transition(const TransitionOptions& options) {
auto impl_ = mutableImpl();
impl_->properties.template get<Light<%- camelize(property.name) %>>().options = options;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::get<%- camelize(property.name) %>Transition() const {
return impl->properties.template get<Light<%- camelize(property.name) %>>().options;
}
<% } -%>
} // namespace style
} // namespace mbgl