diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-04-25 18:20:26 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-12 11:26:27 -0700 |
commit | c2a5894f2dbe9982830066ab9347b059e6e7d845 (patch) | |
tree | c09363c2025b80265de195969ee56cc64e567e70 /src/mbgl/style/light.cpp.ejs | |
parent | d3f23b83d42de8ef23ea1dbd8abfc6276009531f (diff) | |
download | qtlocation-mapboxgl-c2a5894f2dbe9982830066ab9347b059e6e7d845.tar.gz |
[core] Immutable Impls
Diffstat (limited to 'src/mbgl/style/light.cpp.ejs')
-rw-r--r-- | src/mbgl/style/light.cpp.ejs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/mbgl/style/light.cpp.ejs b/src/mbgl/style/light.cpp.ejs index c82c65c10c..454bad49d8 100644 --- a/src/mbgl/style/light.cpp.ejs +++ b/src/mbgl/style/light.cpp.ejs @@ -5,17 +5,29 @@ #include <mbgl/style/light.hpp> #include <mbgl/style/light_impl.hpp> +#include <mbgl/style/light_observer.hpp> #include <mbgl/style/light_properties.hpp> namespace mbgl { namespace style { +static LightObserver nullObserver; + Light::Light() - : impl(std::make_unique<Impl>()) { + : impl(makeMutable<Impl>()), + observer(&nullObserver) { } Light::~Light() = default; +void Light::setObserver(LightObserver* observer_) { + observer = observer_ ? observer_ : &nullObserver; +} + +Mutable<Light::Impl> Light::mutableImpl() const { + return makeMutable<Impl>(*impl); +} + <% for (const property of properties) { -%> <%- evaluatedType(property) %> Light::getDefault<%- camelize(property.name) %>() { return Light<%- camelize(property.name) %>::defaultValue(); @@ -26,13 +38,17 @@ Light::~Light() = default; } void Light::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> property) { - impl->properties.template get<Light<%- camelize(property.name) %>>().value = property; - impl->observer->onLightChanged(*this); + auto impl_ = mutableImpl(); + impl_->properties.template get<Light<%- camelize(property.name) %>>().value = property; + impl = std::move(impl_); + observer->onLightChanged(*this); } void Light::set<%- camelize(property.name) %>Transition(const TransitionOptions& transition) { - impl->properties.template get<Light<%- camelize(property.name) %>>().transition = transition; - impl->observer->onLightChanged(*this); + auto impl_ = mutableImpl(); + impl_->properties.template get<Light<%- camelize(property.name) %>>().transition = transition; + impl = std::move(impl_); + observer->onLightChanged(*this); } TransitionOptions Light::get<%- camelize(property.name) %>Transition() const { |