1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
// 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 {
Anchor,
Color,
Intensity,
Position,
AnchorTransition,
ColorTransition,
IntensityTransition,
PositionTransition,
};
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>(
{{"anchor", toUint8(Property::Anchor)},
{"color", toUint8(Property::Color)},
{"intensity", toUint8(Property::Intensity)},
{"position", toUint8(Property::Position)},
{"anchor-transition", toUint8(Property::AnchorTransition)},
{"color-transition", toUint8(Property::ColorTransition)},
{"intensity-transition", toUint8(Property::IntensityTransition)},
{"position-transition", toUint8(Property::PositionTransition)}});
} // 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);
if (property == Property::Anchor) {
Error error;
optional<PropertyValue<LightAnchorType>> typedValue = convert<PropertyValue<LightAnchorType>>(value, error, false, false);
if (!typedValue) {
return error;
}
setAnchor(*typedValue);
return nullopt;
}
if (property == Property::Color) {
Error error;
optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false);
if (!typedValue) {
return error;
}
setColor(*typedValue);
return nullopt;
}
if (property == Property::Intensity) {
Error error;
optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false);
if (!typedValue) {
return error;
}
setIntensity(*typedValue);
return nullopt;
}
if (property == Property::Position) {
Error error;
optional<PropertyValue<Position>> typedValue = convert<PropertyValue<Position>>(value, error, false, false);
if (!typedValue) {
return error;
}
setPosition(*typedValue);
return nullopt;
}
Error error;
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
if (!transition) {
return error;
}
if (property == Property::AnchorTransition) {
setAnchorTransition(*transition);
return nullopt;
}
if (property == Property::ColorTransition) {
setColorTransition(*transition);
return nullopt;
}
if (property == Property::IntensityTransition) {
setIntensityTransition(*transition);
return nullopt;
}
if (property == Property::PositionTransition) {
setPositionTransition(*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)) {
case Property::Anchor:
return makeStyleProperty(getAnchor());
case Property::Color:
return makeStyleProperty(getColor());
case Property::Intensity:
return makeStyleProperty(getIntensity());
case Property::Position:
return makeStyleProperty(getPosition());
case Property::AnchorTransition:
return makeStyleProperty(getAnchorTransition());
case Property::ColorTransition:
return makeStyleProperty(getColorTransition());
case Property::IntensityTransition:
return makeStyleProperty(getIntensityTransition());
case Property::PositionTransition:
return makeStyleProperty(getPositionTransition());
}
return {};
}
LightAnchorType Light::getDefaultAnchor() {
return LightAnchor::defaultValue();
}
PropertyValue<LightAnchorType> Light::getAnchor() const {
return impl->properties.template get<LightAnchor>().value;
}
void Light::setAnchor(PropertyValue<LightAnchorType> property) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightAnchor>().value = std::move(property);
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setAnchorTransition(const TransitionOptions& options) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightAnchor>().options = options;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getAnchorTransition() const {
return impl->properties.template get<LightAnchor>().options;
}
Color Light::getDefaultColor() {
return LightColor::defaultValue();
}
PropertyValue<Color> Light::getColor() const {
return impl->properties.template get<LightColor>().value;
}
void Light::setColor(PropertyValue<Color> property) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightColor>().value = std::move(property);
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setColorTransition(const TransitionOptions& options) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightColor>().options = options;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getColorTransition() const {
return impl->properties.template get<LightColor>().options;
}
float Light::getDefaultIntensity() {
return LightIntensity::defaultValue();
}
PropertyValue<float> Light::getIntensity() const {
return impl->properties.template get<LightIntensity>().value;
}
void Light::setIntensity(PropertyValue<float> property) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightIntensity>().value = std::move(property);
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setIntensityTransition(const TransitionOptions& options) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightIntensity>().options = options;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getIntensityTransition() const {
return impl->properties.template get<LightIntensity>().options;
}
Position Light::getDefaultPosition() {
return LightPosition::defaultValue();
}
PropertyValue<Position> Light::getPosition() const {
return impl->properties.template get<LightPosition>().value;
}
void Light::setPosition(PropertyValue<Position> property) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightPosition>().value = std::move(property);
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setPositionTransition(const TransitionOptions& options) {
auto impl_ = mutableImpl();
impl_->properties.template get<LightPosition>().options = options;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getPositionTransition() const {
return impl->properties.template get<LightPosition>().options;
}
} // namespace style
} // namespace mbgl
|