<% const properties = locals.properties; -%> // This file is generated. Do not edit. #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { namespace style { static LightObserver nullObserver; Light::Light(Immutable impl_) : impl(std::move(impl_)), observer(&nullObserver) {} Light::Light() : Light(makeMutable()) {} Light::~Light() = default; void Light::setObserver(LightObserver* observer_) { observer = observer_ ? observer_ : &nullObserver; } Mutable Light::mutableImpl() const { return makeMutable(*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 constexpr uint8_t toUint8(T t) noexcept { return uint8_t(mbgl::underlying_type(t)); } MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map( {<%- 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 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(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 transition = convert(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(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>().value; } void Light::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> property) { auto impl_ = mutableImpl(); impl_->properties.template get>().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>().options = options; impl = std::move(impl_); observer->onLightChanged(*this); } TransitionOptions Light::get<%- camelize(property.name) %>Transition() const { return impl->properties.template get>().options; } <% } -%> } // namespace style } // namespace mbgl