[core] Immutable Impls

This commit is contained in:
John Firebaugh
2017-04-25 18:20:26 -07:00
parent d3f23b83d4
commit c2a5894f2d
124 changed files with 2592 additions and 1487 deletions

View File

@@ -224,6 +224,8 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/render_symbol_layer.hpp
src/mbgl/renderer/render_tile.cpp
src/mbgl/renderer/render_tile.hpp
src/mbgl/renderer/style_diff.cpp
src/mbgl/renderer/style_diff.hpp
src/mbgl/renderer/symbol_bucket.cpp
src/mbgl/renderer/symbol_bucket.hpp
src/mbgl/renderer/tile_parameters.hpp
@@ -341,8 +343,6 @@ set(MBGL_CORE_FILES
src/mbgl/style/source_observer.hpp
src/mbgl/style/style.cpp
src/mbgl/style/style.hpp
src/mbgl/style/tile_source_impl.cpp
src/mbgl/style/tile_source_impl.hpp
src/mbgl/style/types.cpp
src/mbgl/style/update_batch.hpp
@@ -510,6 +510,7 @@ set(MBGL_CORE_FILES
include/mbgl/util/geometry.hpp
include/mbgl/util/ignore.hpp
include/mbgl/util/image.hpp
include/mbgl/util/immutable.hpp
include/mbgl/util/indexed_tuple.hpp
include/mbgl/util/interpolate.hpp
include/mbgl/util/logging.hpp
@@ -559,6 +560,7 @@ set(MBGL_CORE_FILES
src/mbgl/util/io.cpp
src/mbgl/util/io.hpp
src/mbgl/util/logging.cpp
src/mbgl/util/longest_common_subsequence.hpp
src/mbgl/util/mapbox.cpp
src/mbgl/util/mapbox.hpp
src/mbgl/util/mat2.cpp

View File

@@ -2,6 +2,7 @@
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/any.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/style/layer_type.hpp>
#include <mbgl/style/types.hpp>
@@ -19,6 +20,7 @@ class RasterLayer;
class BackgroundLayer;
class CustomLayer;
class FillExtrusionLayer;
class LayerObserver;
/**
* The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style
@@ -38,15 +40,6 @@ class FillExtrusionLayer;
*/
class Layer : public mbgl::util::noncopyable {
public:
class Impl;
protected:
const LayerType type;
Layer(LayerType, std::unique_ptr<Impl>);
public:
virtual ~Layer();
// Check whether this layer is of the given subtype.
@@ -78,7 +71,7 @@ public:
//
template <class V>
auto accept(V&& visitor) {
switch (type) {
switch (getType()) {
case LayerType::Fill:
return visitor(*as<FillLayer>());
case LayerType::Line:
@@ -98,20 +91,30 @@ public:
}
}
LayerType getType() const;
const std::string& getID() const;
// Visibility
VisibilityType getVisibility() const;
void setVisibility(VisibilityType);
virtual void setVisibility(VisibilityType) = 0;
// Zoom range
float getMinZoom() const;
void setMinZoom(float) const;
float getMaxZoom() const;
void setMaxZoom(float) const;
virtual void setMinZoom(float) = 0;
virtual void setMaxZoom(float) = 0;
// Private implementation
const std::unique_ptr<Impl> baseImpl;
class Impl;
Immutable<Impl> baseImpl;
Layer(Immutable<Impl>);
// Create a layer, copying all properties except id and paint properties from this layer.
virtual std::unique_ptr<Layer> cloneRef(const std::string& id) const = 0;
LayerObserver* observer = nullptr;
void setObserver(LayerObserver*);
// For use in SDK bindings, which store a reference to a platform-native peer
// object here, so that separately-obtained references to this object share

View File

@@ -19,6 +19,13 @@ public:
BackgroundLayer(const std::string& layerID);
~BackgroundLayer() final;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Paint properties
static PropertyValue<Color> getDefaultBackgroundColor();
@@ -42,15 +49,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
BackgroundLayer(const Impl&);
BackgroundLayer(const BackgroundLayer&) = delete;
Mutable<Impl> mutableImpl() const;
BackgroundLayer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<BackgroundLayer>() const {
return type == LayerType::Background;
return getType() == LayerType::Background;
}
} // namespace style

View File

@@ -27,6 +27,13 @@ public:
void setFilter(const Filter&);
const Filter& getFilter() const;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Paint properties
static DataDrivenPropertyValue<float> getDefaultCircleRadius();
@@ -92,15 +99,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
CircleLayer(const Impl&);
CircleLayer(const CircleLayer&) = delete;
Mutable<Impl> mutableImpl() const;
CircleLayer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<CircleLayer>() const {
return type == LayerType::Circle;
return getType() == LayerType::Circle;
}
} // namespace style

View File

@@ -55,12 +55,21 @@ public:
void* context);
~CustomLayer() final;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Private implementation
class Impl;
Impl* impl;
const Impl& impl() const;
Mutable<Impl> mutableImpl() const;
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
CustomLayer(const Impl&);
CustomLayer(const CustomLayer&) = delete;
};

View File

@@ -27,6 +27,13 @@ public:
void setFilter(const Filter&);
const Filter& getFilter() const;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Paint properties
static PropertyValue<float> getDefaultFillExtrusionOpacity();
@@ -74,15 +81,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
FillExtrusionLayer(const Impl&);
FillExtrusionLayer(const FillExtrusionLayer&) = delete;
Mutable<Impl> mutableImpl() const;
FillExtrusionLayer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<FillExtrusionLayer>() const {
return type == LayerType::FillExtrusion;
return getType() == LayerType::FillExtrusion;
}
} // namespace style

View File

@@ -27,6 +27,13 @@ public:
void setFilter(const Filter&);
const Filter& getFilter() const;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Paint properties
static PropertyValue<bool> getDefaultFillAntialias();
@@ -74,15 +81,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
FillLayer(const Impl&);
FillLayer(const FillLayer&) = delete;
Mutable<Impl> mutableImpl() const;
FillLayer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<FillLayer>() const {
return type == LayerType::Fill;
return getType() == LayerType::Fill;
}
} // namespace style

View File

@@ -44,6 +44,13 @@ public:
<% } -%>
<% } -%>
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
<% if (layoutProperties.length) { -%>
// Layout properties
@@ -67,15 +74,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
<%- camelize(type) %>Layer(const Impl&);
<%- camelize(type) %>Layer(const <%- camelize(type) %>Layer&) = delete;
Mutable<Impl> mutableImpl() const;
<%- camelize(type) %>Layer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<<%- camelize(type) %>Layer>() const {
return type == LayerType::<%- camelize(type) %>;
return getType() == LayerType::<%- camelize(type) %>;
}
} // namespace style

View File

@@ -29,6 +29,13 @@ public:
void setFilter(const Filter&);
const Filter& getFilter() const;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Layout properties
static PropertyValue<LineCapType> getDefaultLineCap();
@@ -112,15 +119,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
LineLayer(const Impl&);
LineLayer(const LineLayer&) = delete;
Mutable<Impl> mutableImpl() const;
LineLayer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<LineLayer>() const {
return type == LayerType::Line;
return getType() == LayerType::Line;
}
} // namespace style

View File

@@ -22,6 +22,13 @@ public:
// Source
const std::string& getSourceID() const;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Paint properties
static PropertyValue<float> getDefaultRasterOpacity();
@@ -69,15 +76,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
RasterLayer(const Impl&);
RasterLayer(const RasterLayer&) = delete;
Mutable<Impl> mutableImpl() const;
RasterLayer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<RasterLayer>() const {
return type == LayerType::Raster;
return getType() == LayerType::Raster;
}
} // namespace style

View File

@@ -29,6 +29,13 @@ public:
void setFilter(const Filter&);
const Filter& getFilter() const;
// Visibility
void setVisibility(VisibilityType) final;
// Zoom range
void setMinZoom(float) final;
void setMaxZoom(float) final;
// Layout properties
static PropertyValue<SymbolPlacementType> getDefaultSymbolPlacement();
@@ -256,15 +263,16 @@ public:
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
SymbolLayer(const Impl&);
SymbolLayer(const SymbolLayer&) = delete;
Mutable<Impl> mutableImpl() const;
SymbolLayer(Immutable<Impl>);
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
};
template <>
inline bool Layer::is<SymbolLayer>() const {
return type == LayerType::Symbol;
return getType() == LayerType::Symbol;
}
} // namespace style

View File

@@ -1,20 +1,19 @@
// This file is generated. Do not edit.
#pragma once
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
#include <memory>
#include <mbgl/util/immutable.hpp>
namespace mbgl {
namespace style {
class LightObserver;
class Light {
public:
class Impl;
Light();
~Light();
@@ -42,7 +41,12 @@ public:
void setIntensityTransition(const TransitionOptions&);
TransitionOptions getIntensityTransition() const;
std::shared_ptr<Impl> impl;
class Impl;
Immutable<Impl> impl;
Mutable<Impl> mutableImpl() const;
LightObserver* observer = nullptr;
void setObserver(LightObserver*);
};
} // namespace style

View File

@@ -4,20 +4,19 @@
// This file is generated. Do not edit.
#pragma once
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
#include <memory>
#include <mbgl/util/immutable.hpp>
namespace mbgl {
namespace style {
class LightObserver;
class Light {
public:
class Impl;
Light();
~Light();
@@ -29,7 +28,12 @@ public:
TransitionOptions get<%- camelize(property.name) %>Transition() const;
<% } -%>
std::shared_ptr<Impl> impl;
class Impl;
Immutable<Impl> impl;
Mutable<Impl> mutableImpl() const;
LightObserver* observer = nullptr;
void setObserver(LightObserver*);
};
} // namespace style

View File

@@ -1,19 +1,25 @@
#pragma once
#include <mbgl/util/feature.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/any.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/style/types.hpp>
#include <memory>
#include <string>
#include <vector>
namespace mbgl {
class FileSource;
namespace style {
class VectorSource;
class RasterSource;
class GeoJSONSource;
class SourceObserver;
/**
* The runtime representation of a [source](https://www.mapbox.com/mapbox-gl-style-spec/#sources) from the Mapbox Style
* Specification.
@@ -49,21 +55,28 @@ public:
return is<T>() ? reinterpret_cast<const T*>(this) : nullptr;
}
SourceType getType() const;
const std::string& getID() const;
optional<std::string> getAttribution() const;
// Private implementation
class Impl;
const std::unique_ptr<Impl> baseImpl;
Immutable<Impl> baseImpl;
Source(Immutable<Impl>);
void setObserver(SourceObserver*);
SourceObserver* observer = nullptr;
virtual void loadDescription(FileSource&) = 0;
void dumpDebugLogs() const;
bool loaded = false;
// For use in SDK bindings, which store a reference to a platform-native peer
// object here, so that separately-obtained references to this object share
// identical platform-native peers.
any peer;
protected:
const SourceType type;
Source(SourceType, std::unique_ptr<Impl>);
};
} // namespace style

View File

@@ -5,6 +5,9 @@
#include <mbgl/util/optional.hpp>
namespace mbgl {
class AsyncRequest;
namespace style {
struct GeoJSONOptions {
@@ -22,21 +25,26 @@ struct GeoJSONOptions {
class GeoJSONSource : public Source {
public:
GeoJSONSource(const std::string& id, const GeoJSONOptions& = {});
~GeoJSONSource() final;
void setURL(const std::string& url);
void setGeoJSON(const GeoJSON&);
optional<std::string> getURL() const;
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
void loadDescription(FileSource&) final;
private:
optional<std::string> url;
std::unique_ptr<AsyncRequest> req;
};
template <>
inline bool Source::is<GeoJSONSource>() const {
return type == SourceType::GeoJSON;
return getType() == SourceType::GeoJSON;
}
} // namespace style

View File

@@ -5,23 +5,34 @@
#include <mbgl/util/variant.hpp>
namespace mbgl {
class AsyncRequest;
namespace style {
class RasterSource : public Source {
public:
RasterSource(std::string id, variant<std::string, Tileset> urlOrTileset, uint16_t tileSize);
~RasterSource() final;
const variant<std::string, Tileset>& getURLOrTileset() const;
optional<std::string> getURL() const;
// Private implementation
uint16_t getTileSize() const;
class Impl;
Impl* const impl;
const Impl& impl() const;
void loadDescription(FileSource&) final;
private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
};
template <>
inline bool Source::is<RasterSource>() const {
return type == SourceType::Raster;
return getType() == SourceType::Raster;
}
} // namespace style

View File

@@ -5,23 +5,32 @@
#include <mbgl/util/variant.hpp>
namespace mbgl {
class AsyncRequest;
namespace style {
class VectorSource : public Source {
public:
VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset);
~VectorSource() final;
const variant<std::string, Tileset>& getURLOrTileset() const;
optional<std::string> getURL() const;
// Private implementation
class Impl;
Impl* const impl;
const Impl& impl() const;
void loadDescription(FileSource&) final;
private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
};
template <>
inline bool Source::is<VectorSource>() const {
return type == SourceType::Vector;
return getType() == SourceType::Vector;
}
} // namespace style

View File

@@ -0,0 +1,127 @@
#pragma once
#include <memory>
namespace mbgl {
/**
* `Mutable<T>` is a non-nullable uniquely owning reference to a `T`. It can be efficiently converted
* to `Immutable<T>`.
*
* The lifecycle of `Mutable<T>` and `Immutable<T>` is as follows:
*
* 1. Create a `Mutable<T>` using `makeMutable(...)`
* 2. Mutate it freely
* 3. When you're ready to freeze its state and enable safe cross-thread sharing, move assign or
* move construct it to `Immutable<T>`
*
* The reason that `Mutable<T>` exists, rather than simply using a `std::unique_ptr<T>`, is to take advantage
* of the underlying single-allocation optimization provided by `std::make_shared`.
*/
template <class T>
class Mutable {
public:
Mutable(Mutable&&) = default;
Mutable& operator=(Mutable&&) = default;
Mutable(const Mutable&) = delete;
Mutable& operator=(const Mutable&) = delete;
T* get() { return ptr.get(); }
T* operator->() { return ptr.get(); }
T& operator*() { return *ptr; }
private:
Mutable(std::shared_ptr<T>&& s)
: ptr(std::move(s)) {}
std::shared_ptr<T> ptr;
template <class S> friend class Immutable;
template <class S, class... Args> friend Mutable<S> makeMutable(Args&&...);
};
template <class T, class... Args>
Mutable<T> makeMutable(Args&&... args) {
return Mutable<T>(std::make_shared<T>(std::forward<Args>(args)...));
}
/**
* `Immutable<T>` is a non-nullable shared reference to a `const T`. Construction requires
* a transfer of unique ownership from a `Mutable<T>`; once constructed it has the same behavior
* as `std::shared_ptr<const T>` but with better indication of intent.
*
* Normally one should not share state between threads because it's difficult to verify the
* absence of read/write data races. `Immutable` provides a guarantee that no writes are
* possible, and instances therefore can be freely transferred and shared between threads.
*/
template <class T>
class Immutable {
public:
template <class S>
Immutable(Mutable<S>&& s)
: ptr(std::const_pointer_cast<const S>(std::move(s.ptr))) {}
template <class S>
Immutable(Immutable<S>&& s)
: ptr(std::move(s.ptr)) {}
template <class S>
Immutable(const Immutable<S>& s)
: ptr(s.ptr) {}
template <class S>
Immutable& operator=(Mutable<S>&& s) {
ptr = std::const_pointer_cast<const S>(std::move(s.ptr));
return *this;
}
template <class S>
Immutable& operator=(Immutable<S>&& s) {
ptr = std::move(s.ptr);
return *this;
}
template <class S>
Immutable& operator=(const Immutable<S>& s) {
ptr = s.ptr;
return *this;
}
const T* get() const { return ptr.get(); }
const T* operator->() const { return ptr.get(); }
const T& operator*() const { return *ptr; }
friend bool operator==(const Immutable<T>& lhs, const Immutable<T>& rhs) {
return lhs.ptr == rhs.ptr;
}
friend bool operator!=(const Immutable<T>& lhs, const Immutable<T>& rhs) {
return lhs.ptr != rhs.ptr;
}
private:
Immutable(std::shared_ptr<const T>&& s)
: ptr(std::move(s)) {}
std::shared_ptr<const T> ptr;
template <class S> friend class Immutable;
template <class S> friend class EnableImmutableFromThis;
template <class S, class U> friend Immutable<S> staticImmutableCast(const Immutable<U>&);
};
template <class T>
class EnableImmutableFromThis : public std::enable_shared_from_this<const T> {
public:
Immutable<T> immutableFromThis() const {
return Immutable<T>(this->shared_from_this());
}
};
template <class S, class U>
Immutable<S> staticImmutableCast(const Immutable<U>& u) {
return Immutable<S>(std::static_pointer_cast<const S>(u.ptr));
}
} // namespace mbgl

View File

@@ -18,6 +18,11 @@ public:
Scheme scheme = Scheme::XYZ;
// TileJSON also includes center, zoom, and bounds, but they are not used by mbgl.
friend bool operator==(const Tileset& lhs, const Tileset& rhs) {
return std::tie(lhs.tiles, lhs.zoomRange, lhs.attribution, lhs.scheme)
== std::tie(rhs.tiles, rhs.zoomRange, rhs.attribution, rhs.scheme);
}
};
} // namespace mbgl

View File

@@ -5,8 +5,9 @@
#include <mbgl/storage/response.hpp>
#include <mbgl/storage/http_file_source.hpp>
#include <mbgl/style/parser.hpp>
#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/tile_source_impl.hpp>
#include <mbgl/style/sources/vector_source.hpp>
#include <mbgl/style/sources/raster_source.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/tileset.hpp>
#include <mbgl/text/glyph.hpp>
@@ -19,6 +20,8 @@
namespace mbgl {
using namespace style;
OfflineDownload::OfflineDownload(int64_t id_,
OfflineRegionDefinition&& definition_,
OfflineDatabase& offlineDatabase_,
@@ -71,15 +74,9 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
result.requiredResourceCountIsPrecise = true;
for (const auto& source : parser.sources) {
SourceType type = source->baseImpl->type;
switch (type) {
case SourceType::Vector:
case SourceType::Raster: {
auto* tileSource = static_cast<style::TileSourceImpl*>(source->baseImpl.get());
const variant<std::string, Tileset>& urlOrTileset = tileSource->getURLOrTileset();
const uint16_t tileSize = tileSource->getTileSize();
SourceType type = source->getType();
auto handleTiledSource = [&] (const variant<std::string, Tileset>& urlOrTileset, const uint16_t tileSize) {
if (urlOrTileset.is<Tileset>()) {
result.requiredResourceCount +=
definition.tileCover(type, tileSize, urlOrTileset.get<Tileset>().zoomRange).size();
@@ -98,11 +95,23 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
result.requiredResourceCountIsPrecise = false;
}
}
};
switch (type) {
case SourceType::Vector: {
const auto& vectorSource = *source->as<VectorSource>();
handleTiledSource(vectorSource.getURLOrTileset(), util::tileSize);
break;
}
case SourceType::Raster: {
const auto& rasterSource = *source->as<RasterSource>();
handleTiledSource(rasterSource.getURLOrTileset(), rasterSource.getTileSize());
break;
}
case SourceType::GeoJSON: {
auto* geojsonSource = source->as<style::GeoJSONSource>();
auto* geojsonSource = source->as<GeoJSONSource>();
if (geojsonSource->getURL()) {
result.requiredResourceCount += 1;
}
@@ -137,16 +146,9 @@ void OfflineDownload::activateDownload() {
parser.parse(*styleResponse.data);
for (const auto& source : parser.sources) {
SourceType type = source->baseImpl->type;
switch (type) {
case SourceType::Vector:
case SourceType::Raster: {
const style::TileSourceImpl* tileSource =
static_cast<style::TileSourceImpl*>(source->baseImpl.get());
const variant<std::string, Tileset>& urlOrTileset = tileSource->getURLOrTileset();
const uint16_t tileSize = tileSource->getTileSize();
SourceType type = source->getType();
auto handleTiledSource = [&] (const variant<std::string, Tileset>& urlOrTileset, const uint16_t tileSize) {
if (urlOrTileset.is<Tileset>()) {
queueTiles(type, tileSize, urlOrTileset.get<Tileset>());
} else {
@@ -169,12 +171,23 @@ void OfflineDownload::activateDownload() {
}
});
}
};
switch (type) {
case SourceType::Vector: {
const auto& vectorSource = *source->as<VectorSource>();
handleTiledSource(vectorSource.getURLOrTileset(), util::tileSize);
break;
}
case SourceType::Raster: {
const auto& rasterSource = *source->as<RasterSource>();
handleTiledSource(rasterSource.getURLOrTileset(), rasterSource.getTileSize());
break;
}
case SourceType::GeoJSON: {
auto* geojsonSource =
static_cast<style::GeoJSONSource::Impl*>(source->baseImpl.get());
const auto* geojsonSource = static_cast<const GeoJSONSource*>(source.get());
if (geojsonSource->getURL()) {
queueResource(Resource::source(*geojsonSource->getURL()));

View File

@@ -7,19 +7,23 @@ namespace mbgl {
using namespace style;
AnnotationSource::AnnotationSource()
: Source(SourceType::Annotations, std::make_unique<Impl>(*this)) {
: Source(makeMutable<Impl>()) {
}
AnnotationSource::Impl::Impl(Source& base_)
: Source::Impl(SourceType::Annotations, AnnotationManager::SourceID, base_) {
AnnotationSource::Impl::Impl()
: Source::Impl(SourceType::Annotations, AnnotationManager::SourceID) {
}
void AnnotationSource::Impl::loadDescription(FileSource&) {
void AnnotationSource::loadDescription(FileSource&) {
loaded = true;
}
optional<std::string> AnnotationSource::Impl::getAttribution() const {
return {};
}
std::unique_ptr<RenderSource> AnnotationSource::Impl::createRenderSource() const {
return std::make_unique<RenderAnnotationSource>(*this);
return std::make_unique<RenderAnnotationSource>(staticImmutableCast<AnnotationSource::Impl>(immutableFromThis()));
}
} // namespace mbgl

View File

@@ -10,13 +10,19 @@ public:
AnnotationSource();
class Impl;
const Impl& impl() const;
private:
void loadDescription(FileSource&) final;
Mutable<Impl> mutableImpl() const;
};
class AnnotationSource::Impl : public style::Source::Impl {
public:
Impl(Source&);
Impl();
void loadDescription(FileSource&) final;
optional<std::string> getAttribution() const final;
std::unique_ptr<RenderSource> createRenderSource() const final;
};

View File

@@ -9,11 +9,15 @@ namespace mbgl {
using namespace style;
RenderAnnotationSource::RenderAnnotationSource(const AnnotationSource::Impl& impl_)
RenderAnnotationSource::RenderAnnotationSource(Immutable<AnnotationSource::Impl> impl_)
: RenderSource(impl_) {
tilePyramid.setObserver(this);
}
const AnnotationSource::Impl& RenderAnnotationSource::impl() const {
return static_cast<const AnnotationSource::Impl&>(*baseImpl);
}
bool RenderAnnotationSource::isLoaded() const {
return tilePyramid.isLoaded();
}

View File

@@ -8,7 +8,7 @@ namespace mbgl {
class RenderAnnotationSource : public RenderSource {
public:
RenderAnnotationSource(const AnnotationSource::Impl&);
RenderAnnotationSource(Immutable<AnnotationSource::Impl>);
bool isLoaded() const final;
@@ -47,6 +47,8 @@ public:
void dumpDebugLogs() const final;
private:
const AnnotationSource::Impl& impl() const;
TilePyramid tilePyramid;
};

View File

@@ -61,7 +61,7 @@ static int16_t getAdditionalQueryRadius(const RenderedQueryOptions& queryOptions
// Determine the additional radius needed factoring in property functions
float additionalRadius = 0;
auto getQueryRadius = [&](const RenderLayer& layer) {
auto bucket = tile.getBucket(layer);
auto bucket = tile.getBucket(*layer.baseImpl);
if (bucket) {
additionalRadius = std::max(additionalRadius, bucket->getQueryRadius(layer) * pixelsToTileUnits);
}

View File

@@ -50,11 +50,11 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
mode(parameters.mode),
tileSize(util::tileSize * overscaling),
tilePixelRatio(float(util::EXTENT) / tileSize),
textSize(layers.at(0)->as<RenderSymbolLayer>()->impl->layout.unevaluated.get<TextSize>()),
iconSize(layers.at(0)->as<RenderSymbolLayer>()->impl->layout.unevaluated.get<IconSize>())
textSize(layers.at(0)->as<RenderSymbolLayer>()->impl().layout.unevaluated.get<TextSize>()),
iconSize(layers.at(0)->as<RenderSymbolLayer>()->impl().layout.unevaluated.get<IconSize>())
{
const SymbolLayer::Impl& leader = *layers.at(0)->as<RenderSymbolLayer>()->impl;
const SymbolLayer::Impl& leader = layers.at(0)->as<RenderSymbolLayer>()->impl();
layout = leader.layout.evaluate(PropertyEvaluationParameters(zoom));

View File

@@ -402,7 +402,7 @@ void Map::Impl::loadStyleJSON(const std::string& json) {
map.setPitch(map.getDefaultPitch());
}
onUpdate(Update::Classes | Update::AnnotationStyle);
onUpdate(Update::AnnotationStyle);
}
std::string Map::getStyleURL() const {
@@ -919,7 +919,7 @@ void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& be
BackendScope guard(impl->backend);
impl->style->addLayer(std::move(layer), before);
impl->onUpdate(Update::Classes);
impl->onUpdate(Update::Repaint);
}
std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {

View File

@@ -8,7 +8,6 @@ enum class Update {
Nothing = 0,
Repaint = 1 << 0,
Classes = 1 << 2,
RecalculateStyle = 1 << 3,
AnnotationStyle = 1 << 6,
AnnotationData = 1 << 7
};

View File

@@ -19,13 +19,13 @@ std::string layoutKey(const RenderLayer& layer) {
writer.StartArray();
writer.Uint(static_cast<uint32_t>(layer.type));
writer.String(layer.baseImpl.source);
writer.String(layer.baseImpl.sourceLayer);
writer.Double(layer.baseImpl.minZoom);
writer.Double(layer.baseImpl.maxZoom);
writer.Uint(static_cast<uint32_t>(layer.baseImpl.visibility));
stringify(writer, layer.baseImpl.filter);
layer.baseImpl.stringifyLayout(writer);
writer.String(layer.baseImpl->source);
writer.String(layer.baseImpl->sourceLayer);
writer.Double(layer.baseImpl->minZoom);
writer.Double(layer.baseImpl->maxZoom);
writer.Uint(static_cast<uint32_t>(layer.baseImpl->visibility));
stringify(writer, layer.baseImpl->filter);
layer.baseImpl->stringifyLayout(writer);
writer.EndArray();
return s.GetString();

View File

@@ -144,7 +144,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp
spriteAtlas = style.spriteAtlas.get();
lineAtlas = style.lineAtlas.get();
evaluatedLight = style.getRenderLight()->getEvaluated();
evaluatedLight = style.getRenderLight().getEvaluated();
RenderData renderData = style.getRenderData(frame.debugOptions, state.getAngle());
const std::vector<RenderItem>& order = renderData.order;
@@ -180,7 +180,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp
for (const auto& item : order) {
for (const auto& tileRef : item.tiles) {
const auto& bucket = tileRef.get().tile.getBucket(item.layer);
const auto& bucket = tileRef.get().tile.getBucket(*item.layer.baseImpl);
if (bucket && bucket->needsUpload()) {
bucket->upload(context);
}
@@ -309,7 +309,7 @@ void Painter::renderPass(PaintParameters& parameters,
MBGL_DEBUG_GROUP(context, "background");
renderBackground(parameters, *layer.as<RenderBackgroundLayer>());
} else if (layer.is<RenderCustomLayer>()) {
MBGL_DEBUG_GROUP(context, layer.baseImpl.id + " - custom");
MBGL_DEBUG_GROUP(context, layer.baseImpl->id + " - custom");
// Reset GL state to a known state so the CustomLayer always has a clean slate.
context.vertexArrayObject = 0;
@@ -317,7 +317,7 @@ void Painter::renderPass(PaintParameters& parameters,
context.setStencilMode(gl::StencilMode::disabled());
context.setColorMode(colorModeForRenderPass());
layer.as<RenderCustomLayer>()->impl->render(state);
layer.as<RenderCustomLayer>()->impl().render(state);
// Reset the view back to our original one, just in case the CustomLayer changed
// the viewport or Framebuffer.
@@ -339,8 +339,8 @@ void Painter::renderPass(PaintParameters& parameters,
for (auto& tileRef : item.tiles) {
auto& tile = tileRef.get();
MBGL_DEBUG_GROUP(context, layer.baseImpl.id + " - " + util::toString(tile.id));
auto bucket = tile.tile.getBucket(layer);
MBGL_DEBUG_GROUP(context, layer.baseImpl->id + " - " + util::toString(tile.id));
auto bucket = tile.tile.getBucket(*layer.baseImpl);
bucket->render(*this, parameters, layer, tile);
}
@@ -366,8 +366,8 @@ void Painter::renderPass(PaintParameters& parameters,
} else {
for (auto& tileRef : item.tiles) {
auto& tile = tileRef.get();
MBGL_DEBUG_GROUP(context, layer.baseImpl.id + " - " + util::toString(tile.id));
auto bucket = tile.tile.getBucket(layer);
MBGL_DEBUG_GROUP(context, layer.baseImpl->id + " - " + util::toString(tile.id));
auto bucket = tile.tile.getBucket(*layer.baseImpl);
bucket->render(*this, parameters, layer, tile);
}
}

View File

@@ -4,9 +4,12 @@
namespace mbgl {
RenderBackgroundLayer::RenderBackgroundLayer(const style::BackgroundLayer::Impl& _impl)
: RenderLayer(style::LayerType::Background, _impl),
impl(&_impl) {
RenderBackgroundLayer::RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl> _impl)
: RenderLayer(style::LayerType::Background, _impl) {
}
const style::BackgroundLayer::Impl& RenderBackgroundLayer::impl() const {
return static_cast<const style::BackgroundLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderBackgroundLayer::clone() const {
@@ -20,7 +23,7 @@ std::unique_ptr<Bucket> RenderBackgroundLayer::createBucket(const BucketParamete
}
void RenderBackgroundLayer::cascade(const CascadeParameters &parameters) {
unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated));
unevaluated = impl().cascading.cascade(parameters, std::move(unevaluated));
}
void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters &parameters) {

View File

@@ -8,8 +8,7 @@ namespace mbgl {
class RenderBackgroundLayer: public RenderLayer {
public:
RenderBackgroundLayer(const style::BackgroundLayer::Impl&);
RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl>);
~RenderBackgroundLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -24,7 +23,7 @@ public:
style::BackgroundPaintProperties::Unevaluated unevaluated;
style::BackgroundPaintProperties::Evaluated evaluated;
const style::BackgroundLayer::Impl* const impl;
const style::BackgroundLayer::Impl& impl() const;
};
template <>

View File

@@ -7,9 +7,12 @@
namespace mbgl {
RenderCircleLayer::RenderCircleLayer(const style::CircleLayer::Impl& _impl)
: RenderLayer(style::LayerType::Circle, _impl),
impl(&_impl) {
RenderCircleLayer::RenderCircleLayer(Immutable<style::CircleLayer::Impl> _impl)
: RenderLayer(style::LayerType::Circle, _impl) {
}
const style::CircleLayer::Impl& RenderCircleLayer::impl() const {
return static_cast<const style::CircleLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderCircleLayer::clone() const {
@@ -21,7 +24,7 @@ std::unique_ptr<Bucket> RenderCircleLayer::createBucket(const BucketParameters&
}
void RenderCircleLayer::cascade(const CascadeParameters& parameters) {
unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated));
unevaluated = impl().cascading.cascade(parameters, std::move(unevaluated));
}
void RenderCircleLayer::evaluate(const PropertyEvaluationParameters& parameters) {

View File

@@ -8,8 +8,7 @@ namespace mbgl {
class RenderCircleLayer: public RenderLayer {
public:
RenderCircleLayer(const style::CircleLayer::Impl&);
RenderCircleLayer(Immutable<style::CircleLayer::Impl>);
~RenderCircleLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -31,7 +30,7 @@ public:
style::CirclePaintProperties::Unevaluated unevaluated;
style::CirclePaintProperties::Evaluated evaluated;
const style::CircleLayer::Impl* const impl;
const style::CircleLayer::Impl& impl() const;
};
template <>

View File

@@ -4,9 +4,12 @@
namespace mbgl {
RenderCustomLayer::RenderCustomLayer(const style::CustomLayer::Impl& _impl)
: RenderLayer(style::LayerType::Custom, _impl),
impl(&_impl) {
RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl)
: RenderLayer(style::LayerType::Custom, _impl) {
}
const style::CustomLayer::Impl& RenderCustomLayer::impl() const {
return static_cast<const style::CustomLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderCustomLayer::clone() const {

View File

@@ -7,8 +7,7 @@ namespace mbgl {
class RenderCustomLayer: public RenderLayer {
public:
RenderCustomLayer(const style::CustomLayer::Impl&);
RenderCustomLayer(Immutable<style::CustomLayer::Impl>);
~RenderCustomLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -19,7 +18,7 @@ public:
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const final;
const style::CustomLayer::Impl* const impl;
const style::CustomLayer::Impl& impl() const;
};
template <>

View File

@@ -7,9 +7,12 @@
namespace mbgl {
RenderFillExtrusionLayer::RenderFillExtrusionLayer(const style::FillExtrusionLayer::Impl& _impl)
: RenderLayer(style::LayerType::FillExtrusion, _impl),
impl(&_impl) {
RenderFillExtrusionLayer::RenderFillExtrusionLayer(Immutable<style::FillExtrusionLayer::Impl> _impl)
: RenderLayer(style::LayerType::FillExtrusion, _impl) {
}
const style::FillExtrusionLayer::Impl& RenderFillExtrusionLayer::impl() const {
return static_cast<const style::FillExtrusionLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderFillExtrusionLayer::clone() const {
@@ -21,7 +24,7 @@ std::unique_ptr<Bucket> RenderFillExtrusionLayer::createBucket(const BucketParam
}
void RenderFillExtrusionLayer::cascade(const CascadeParameters& parameters) {
unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated));
unevaluated = impl().cascading.cascade(parameters, std::move(unevaluated));
}
void RenderFillExtrusionLayer::evaluate(const PropertyEvaluationParameters& parameters) {

View File

@@ -8,8 +8,7 @@ namespace mbgl {
class RenderFillExtrusionLayer: public RenderLayer {
public:
RenderFillExtrusionLayer(const style::FillExtrusionLayer::Impl&);
RenderFillExtrusionLayer(Immutable<style::FillExtrusionLayer::Impl>);
~RenderFillExtrusionLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -31,7 +30,7 @@ public:
style::FillExtrusionPaintProperties::Unevaluated unevaluated;
style::FillExtrusionPaintProperties::Evaluated evaluated;
const style::FillExtrusionLayer::Impl* const impl;
const style::FillExtrusionLayer::Impl& impl() const;
};
template <>

View File

@@ -7,9 +7,12 @@
namespace mbgl {
RenderFillLayer::RenderFillLayer(const style::FillLayer::Impl& _impl)
: RenderLayer(style::LayerType::Fill, _impl),
impl(&_impl) {
RenderFillLayer::RenderFillLayer(Immutable<style::FillLayer::Impl> _impl)
: RenderLayer(style::LayerType::Fill, _impl) {
}
const style::FillLayer::Impl& RenderFillLayer::impl() const {
return static_cast<const style::FillLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderFillLayer::clone() const {
@@ -21,7 +24,7 @@ std::unique_ptr<Bucket> RenderFillLayer::createBucket(const BucketParameters& pa
}
void RenderFillLayer::cascade(const CascadeParameters& parameters) {
unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated));
unevaluated = impl().cascading.cascade(parameters, std::move(unevaluated));
}
void RenderFillLayer::evaluate(const PropertyEvaluationParameters& parameters) {

View File

@@ -8,8 +8,7 @@ namespace mbgl {
class RenderFillLayer: public RenderLayer {
public:
RenderFillLayer(const style::FillLayer::Impl&);
RenderFillLayer(Immutable<style::FillLayer::Impl>);
~RenderFillLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -31,7 +30,7 @@ public:
style::FillPaintProperties::Unevaluated unevaluated;
style::FillPaintProperties::Evaluated evaluated;
const style::FillLayer::Impl* const impl;
const style::FillLayer::Impl& impl() const;
};
template <>

View File

@@ -3,12 +3,17 @@
namespace mbgl {
RenderLayer::RenderLayer(style::LayerType type_, const style::Layer::Impl& baseImpl_)
: type(type_), baseImpl(baseImpl_) {
RenderLayer::RenderLayer(style::LayerType type_, Immutable<style::Layer::Impl> baseImpl_)
: type(type_),
baseImpl(baseImpl_) {
}
void RenderLayer::setImpl(Immutable<style::Layer::Impl> impl) {
baseImpl = impl;
}
const std::string& RenderLayer::getID() const {
return baseImpl.id;
return baseImpl->id;
}
bool RenderLayer::hasRenderPass(RenderPass pass) const {
@@ -17,9 +22,9 @@ bool RenderLayer::hasRenderPass(RenderPass pass) const {
bool RenderLayer::needsRendering(float zoom) const {
return passes != RenderPass::None
&& baseImpl.visibility != style::VisibilityType::None
&& baseImpl.minZoom <= zoom
&& baseImpl.maxZoom >= zoom;
&& baseImpl->visibility != style::VisibilityType::None
&& baseImpl->minZoom <= zoom
&& baseImpl->maxZoom >= zoom;
}
} // namespace mbgl

View File

@@ -16,14 +16,12 @@ class CascadeParameters;
class PropertyEvaluationParameters;
class RenderLayer {
protected:
RenderLayer(style::LayerType, const style::Layer::Impl&);
RenderLayer(style::LayerType, Immutable<style::Layer::Impl>);
const style::LayerType type;
public:
virtual ~RenderLayer() = default;
// Create an identical copy of this layer.
@@ -73,11 +71,12 @@ public:
virtual std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const = 0;
// Private implementation
const style::Layer::Impl& baseImpl;
Immutable<style::Layer::Impl> baseImpl;
void setImpl(Immutable<style::Layer::Impl>);
friend std::string layoutKey(const RenderLayer&);
protected:
protected:
// Stores what render passes this layer is currently enabled for. This depends on the
// evaluated StyleProperties object and is updated accordingly.
RenderPass passes = RenderPass::None;

View File

@@ -2,17 +2,8 @@
namespace mbgl {
RenderLight::RenderLight(std::shared_ptr<const style::Light::Impl> impl_)
: impl(std::move(impl_)) {
}
RenderLight::RenderLight(std::shared_ptr<const style::Light::Impl> impl_, const TransitioningLight transitioning_)
: impl(std::move(impl_))
, transitioning(transitioning_) {
}
std::unique_ptr<RenderLight> RenderLight::copy(std::shared_ptr<const style::Light::Impl> impl_) const {
return std::make_unique<RenderLight>(std::move(impl_), transitioning);
RenderLight::RenderLight(Immutable<style::Light::Impl> impl_)
: impl(std::move(impl_)) {
}
void RenderLight::transition(const CascadeParameters& parameters) {

View File

@@ -74,14 +74,7 @@ using EvaluatedLight = Evaluated<style::LightProperties>;
class RenderLight {
public:
RenderLight(std::shared_ptr<const style::Light::Impl>);
// Creates a copy intitalized with previous transitioning light
RenderLight(std::shared_ptr<const style::Light::Impl>, const TransitioningLight);
// creates a copy initialized with previous transitioning
// values
std::unique_ptr<RenderLight> copy(std::shared_ptr<const style::Light::Impl>) const;
RenderLight(Immutable<style::Light::Impl>);
void transition(const CascadeParameters&);
void evaluate(const PropertyEvaluationParameters&);
@@ -89,10 +82,9 @@ public:
const EvaluatedLight& getEvaluated() const;
const std::shared_ptr<const style::Light::Impl> impl;
Immutable<style::Light::Impl> impl;
private:
TransitioningLight transitioning;
EvaluatedLight evaluated;
};

View File

@@ -7,9 +7,12 @@
namespace mbgl {
RenderLineLayer::RenderLineLayer(const style::LineLayer::Impl& _impl)
: RenderLayer(style::LayerType::Line, _impl),
impl(&_impl) {
RenderLineLayer::RenderLineLayer(Immutable<style::LineLayer::Impl> _impl)
: RenderLayer(style::LayerType::Line, _impl) {
}
const style::LineLayer::Impl& RenderLineLayer::impl() const {
return static_cast<const style::LineLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderLineLayer::clone() const {
@@ -17,11 +20,11 @@ std::unique_ptr<RenderLayer> RenderLineLayer::clone() const {
}
std::unique_ptr<Bucket> RenderLineLayer::createBucket(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers) const {
return std::make_unique<LineBucket>(parameters, layers, impl->layout);
return std::make_unique<LineBucket>(parameters, layers, impl().layout);
}
void RenderLineLayer::cascade(const CascadeParameters& parameters) {
unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated));
unevaluated = impl().cascading.cascade(parameters, std::move(unevaluated));
}
void RenderLineLayer::evaluate(const PropertyEvaluationParameters& parameters) {

View File

@@ -8,8 +8,7 @@ namespace mbgl {
class RenderLineLayer: public RenderLayer {
public:
RenderLineLayer(const style::LineLayer::Impl&);
RenderLineLayer(Immutable<style::LineLayer::Impl>);
~RenderLineLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -31,14 +30,13 @@ public:
style::LinePaintProperties::Unevaluated unevaluated;
style::LinePaintProperties::Evaluated evaluated;
const style::LineLayer::Impl* const impl;
const style::LineLayer::Impl& impl() const;
// Special case
float dashLineWidth = 1;
private:
float getLineWidth(const GeometryTileFeature&, const float) const;
};
template <>

View File

@@ -4,9 +4,12 @@
namespace mbgl {
RenderRasterLayer::RenderRasterLayer(const style::RasterLayer::Impl& _impl)
: RenderLayer(style::LayerType::Raster, _impl),
impl(&_impl) {
RenderRasterLayer::RenderRasterLayer(Immutable<style::RasterLayer::Impl> _impl)
: RenderLayer(style::LayerType::Raster, _impl) {
}
const style::RasterLayer::Impl& RenderRasterLayer::impl() const {
return static_cast<const style::RasterLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderRasterLayer::clone() const {
@@ -19,7 +22,7 @@ std::unique_ptr<Bucket> RenderRasterLayer::createBucket(const BucketParameters&,
}
void RenderRasterLayer::cascade(const CascadeParameters& parameters) {
unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated));
unevaluated = impl().cascading.cascade(parameters, std::move(unevaluated));
}
void RenderRasterLayer::evaluate(const PropertyEvaluationParameters& parameters) {

View File

@@ -8,8 +8,7 @@ namespace mbgl {
class RenderRasterLayer: public RenderLayer {
public:
RenderRasterLayer(const style::RasterLayer::Impl&);
RenderRasterLayer(Immutable<style::RasterLayer::Impl>);
~RenderRasterLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -24,7 +23,7 @@ public:
style::RasterPaintProperties::Unevaluated unevaluated;
style::RasterPaintProperties::Evaluated evaluated;
const style::RasterLayer::Impl* const impl;
const style::RasterLayer::Impl& impl() const;
};
template <>

View File

@@ -6,7 +6,7 @@ namespace mbgl {
static RenderSourceObserver nullObserver;
RenderSource::RenderSource(const style::Source::Impl& impl)
RenderSource::RenderSource(Immutable<style::Source::Impl> impl)
: baseImpl(impl),
observer(&nullObserver) {
}
@@ -15,6 +15,10 @@ void RenderSource::setObserver(RenderSourceObserver* observer_) {
observer = observer_;
}
void RenderSource::setImpl(Immutable<style::Source::Impl> impl) {
baseImpl = impl;
}
void RenderSource::onTileChanged(Tile& tile) {
observer->onTileChanged(*this, tile.id);
}

View File

@@ -29,7 +29,7 @@ class ClipIDGenerator;
class RenderSource : protected TileObserver {
public:
RenderSource(const style::Source::Impl&);
RenderSource(Immutable<style::Source::Impl>);
~RenderSource() override = default;
virtual bool isLoaded() const = 0;
@@ -71,7 +71,9 @@ public:
void setObserver(RenderSourceObserver*);
const style::Source::Impl& baseImpl;
Immutable<style::Source::Impl> baseImpl;
void setImpl(Immutable<style::Source::Impl>);
bool enabled = false;
protected:

View File

@@ -8,9 +8,12 @@
namespace mbgl {
RenderSymbolLayer::RenderSymbolLayer(const style::SymbolLayer::Impl& _impl)
: RenderLayer(style::LayerType::Symbol, _impl),
impl(&_impl) {
RenderSymbolLayer::RenderSymbolLayer(Immutable<style::SymbolLayer::Impl> _impl)
: RenderLayer(style::LayerType::Symbol, _impl) {
}
const style::SymbolLayer::Impl& RenderSymbolLayer::impl() const {
return static_cast<const style::SymbolLayer::Impl&>(*baseImpl);
}
std::unique_ptr<RenderLayer> RenderSymbolLayer::clone() const {
@@ -35,7 +38,7 @@ std::unique_ptr<SymbolLayout> RenderSymbolLayer::createLayout(const BucketParame
}
void RenderSymbolLayer::cascade(const CascadeParameters& parameters) {
unevaluated = impl->cascading.cascade(parameters, std::move(unevaluated));
unevaluated = impl().cascading.cascade(parameters, std::move(unevaluated));
}
void RenderSymbolLayer::evaluate(const PropertyEvaluationParameters& parameters) {

View File

@@ -61,7 +61,7 @@ class GeometryTileLayer;
class RenderSymbolLayer: public RenderLayer {
public:
RenderSymbolLayer(const style::SymbolLayer::Impl&);
RenderSymbolLayer(Immutable<style::SymbolLayer::Impl>);
~RenderSymbolLayer() final = default;
std::unique_ptr<RenderLayer> clone() const override;
@@ -87,7 +87,7 @@ public:
float iconSize = 1.0f;
float textSize = 16.0f;
const style::SymbolLayer::Impl* const impl;
const style::SymbolLayer::Impl& impl() const;
};
template <>

View File

@@ -9,12 +9,15 @@ namespace mbgl {
using namespace style;
RenderGeoJSONSource::RenderGeoJSONSource(const style::GeoJSONSource::Impl& impl_)
: RenderSource(impl_),
impl(impl_) {
RenderGeoJSONSource::RenderGeoJSONSource(Immutable<style::GeoJSONSource::Impl> impl_)
: RenderSource(impl_) {
tilePyramid.setObserver(this);
}
const style::GeoJSONSource::Impl& RenderGeoJSONSource::impl() const {
return static_cast<const style::GeoJSONSource::Impl&>(*baseImpl);
}
bool RenderGeoJSONSource::isLoaded() const {
return tilePyramid.isLoaded();
}
@@ -37,7 +40,7 @@ std::map<UnwrappedTileID, RenderTile>& RenderGeoJSONSource::getRenderTiles() {
}
void RenderGeoJSONSource::updateTiles(const TileParameters& parameters) {
GeoJSONData* data_ = impl.getData();
GeoJSONData* data_ = impl().getData();
if (!data_) {
return;
@@ -55,9 +58,9 @@ void RenderGeoJSONSource::updateTiles(const TileParameters& parameters) {
tilePyramid.updateTiles(parameters,
SourceType::GeoJSON,
util::tileSize,
impl.getZoomRange(),
impl().getZoomRange(),
[&] (const OverscaledTileID& tileID) {
return std::make_unique<GeoJSONTile>(tileID, impl.id, parameters, data->getTile(tileID.canonical));
return std::make_unique<GeoJSONTile>(tileID, impl().id, parameters, data->getTile(tileID.canonical));
});
}

View File

@@ -12,7 +12,7 @@ class GeoJSONData;
class RenderGeoJSONSource : public RenderSource {
public:
RenderGeoJSONSource(const style::GeoJSONSource::Impl&);
RenderGeoJSONSource(Immutable<style::GeoJSONSource::Impl>);
bool isLoaded() const final;
@@ -51,7 +51,8 @@ public:
void dumpDebugLogs() const final;
private:
const style::GeoJSONSource::Impl& impl;
const style::GeoJSONSource::Impl& impl() const;
TilePyramid tilePyramid;
style::GeoJSONData* data;
};

View File

@@ -6,12 +6,15 @@ namespace mbgl {
using namespace style;
RenderRasterSource::RenderRasterSource(const style::RasterSource::Impl& impl_)
: RenderSource(impl_),
impl(impl_) {
RenderRasterSource::RenderRasterSource(Immutable<style::RasterSource::Impl> impl_)
: RenderSource(impl_) {
tilePyramid.setObserver(this);
}
const style::RasterSource::Impl& RenderRasterSource::impl() const {
return static_cast<const style::RasterSource::Impl&>(*baseImpl);
}
bool RenderRasterSource::isLoaded() const {
return tilePyramid.isLoaded();
}
@@ -33,7 +36,7 @@ std::map<UnwrappedTileID, RenderTile>& RenderRasterSource::getRenderTiles() {
}
void RenderRasterSource::updateTiles(const TileParameters& parameters) {
optional<Tileset> tileset = impl.getTileset();
optional<Tileset> tileset = impl().getTileset();
if (!tileset) {
return;
@@ -46,7 +49,7 @@ void RenderRasterSource::updateTiles(const TileParameters& parameters) {
tilePyramid.updateTiles(parameters,
SourceType::Raster,
impl.getTileSize(),
impl().getTileSize(),
tileset->zoomRange,
[&] (const OverscaledTileID& tileID) {
return std::make_unique<RasterTile>(tileID, parameters, *tileset);

View File

@@ -8,7 +8,7 @@ namespace mbgl {
class RenderRasterSource : public RenderSource {
public:
RenderRasterSource(const style::RasterSource::Impl&);
RenderRasterSource(Immutable<style::RasterSource::Impl>);
bool isLoaded() const final;
@@ -47,7 +47,8 @@ public:
void dumpDebugLogs() const final;
private:
const style::RasterSource::Impl& impl;
const style::RasterSource::Impl& impl() const;
TilePyramid tilePyramid;
optional<std::vector<std::string>> tileURLTemplates;
};

View File

@@ -9,12 +9,15 @@ namespace mbgl {
using namespace style;
RenderVectorSource::RenderVectorSource(const style::VectorSource::Impl& impl_)
: RenderSource(impl_),
impl(impl_) {
RenderVectorSource::RenderVectorSource(Immutable<style::VectorSource::Impl> impl_)
: RenderSource(impl_) {
tilePyramid.setObserver(this);
}
const style::VectorSource::Impl& RenderVectorSource::impl() const {
return static_cast<const style::VectorSource::Impl&>(*baseImpl);
}
bool RenderVectorSource::isLoaded() const {
return tilePyramid.isLoaded();
}
@@ -37,7 +40,7 @@ std::map<UnwrappedTileID, RenderTile>& RenderVectorSource::getRenderTiles() {
}
void RenderVectorSource::updateTiles(const TileParameters& parameters) {
optional<Tileset> tileset = impl.getTileset();
optional<Tileset> tileset = impl().getTileset();
if (!tileset) {
return;
@@ -53,7 +56,7 @@ void RenderVectorSource::updateTiles(const TileParameters& parameters) {
util::tileSize,
tileset->zoomRange,
[&] (const OverscaledTileID& tileID) {
return std::make_unique<VectorTile>(tileID, impl.id, parameters, *tileset);
return std::make_unique<VectorTile>(tileID, impl().id, parameters, *tileset);
});
}

View File

@@ -8,7 +8,7 @@ namespace mbgl {
class RenderVectorSource : public RenderSource {
public:
RenderVectorSource(const style::VectorSource::Impl&);
RenderVectorSource(Immutable<style::VectorSource::Impl>);
bool isLoaded() const final;
@@ -47,7 +47,8 @@ public:
void dumpDebugLogs() const final;
private:
const style::VectorSource::Impl& impl;
const style::VectorSource::Impl& impl() const;
TilePyramid tilePyramid;
optional<std::vector<std::string>> tileURLTemplates;
};

View File

@@ -0,0 +1,56 @@
#include <mbgl/renderer/style_diff.hpp>
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/longest_common_subsequence.hpp>
namespace mbgl {
template <class T>
StyleDifference<T> diff(const std::vector<T>& a, const std::vector<T>& b) {
std::vector<T> lcs;
auto eq = [] (const T& lhs, const T& rhs) {
return std::tie(lhs->id, lhs->type)
== std::tie(rhs->id, rhs->type);
};
longest_common_subsequence(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(lcs), eq);
auto aIt = a.begin();
auto bIt = b.begin();
auto lIt = lcs.begin();
StyleDifference<T> result;
while (aIt != a.end() || bIt != b.end()) {
if (aIt != a.end() && (lIt == lcs.end() || !eq(*lIt, *aIt))) {
result.removed.emplace((*aIt)->id, *aIt);
aIt++;
} else if (bIt != b.end() && (lIt == lcs.end() || !eq(*lIt, *bIt))) {
result.added.emplace((*bIt)->id, *bIt);
bIt++;
} else {
if (aIt->get() != bIt->get()) {
result.changed.emplace((*bIt)->id, *bIt);
}
aIt++;
bIt++;
lIt++;
}
}
return result;
}
SourceDifference diffSources(const std::vector<ImmutableSource>& a,
const std::vector<ImmutableSource>& b) {
return diff(a, b);
}
LayerDifference diffLayers(const std::vector<ImmutableLayer>& a,
const std::vector<ImmutableLayer>& b) {
return diff(a, b);
}
} // namespace mbgl

View File

@@ -0,0 +1,30 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/util/variant.hpp>
#include <unordered_map>
namespace mbgl {
template <class T>
class StyleDifference {
public:
std::unordered_map<std::string, T> added;
std::unordered_map<std::string, T> removed;
std::unordered_map<std::string, T> changed;
};
using ImmutableSource = Immutable<style::Source::Impl>;
using SourceDifference = StyleDifference<ImmutableSource>;
SourceDifference diffSources(const std::vector<ImmutableSource>&,
const std::vector<ImmutableSource>&);
using ImmutableLayer = Immutable<style::Layer::Impl>;
using LayerDifference = StyleDifference<ImmutableLayer>;
LayerDifference diffLayers(const std::vector<ImmutableLayer>&,
const std::vector<ImmutableLayer>&);
} // namespace mbgl

View File

@@ -1,16 +1,23 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layer_type.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
Layer::Layer(LayerType type_, std::unique_ptr<Impl> baseImpl_)
: type(type_), baseImpl(std::move(baseImpl_)) {
static LayerObserver nullObserver;
Layer::Layer(Immutable<Impl> impl)
: baseImpl(std::move(impl)),
observer(&nullObserver) {
}
Layer::~Layer() = default;
LayerType Layer::getType() const {
return baseImpl->type;
}
const std::string& Layer::getID() const {
return baseImpl->id;
}
@@ -19,27 +26,16 @@ VisibilityType Layer::getVisibility() const {
return baseImpl->visibility;
}
void Layer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
baseImpl->visibility = value;
baseImpl->observer->onLayerVisibilityChanged(*this);
}
float Layer::getMinZoom() const {
return baseImpl->minZoom;
}
void Layer::setMinZoom(float minZoom) const {
baseImpl->minZoom = minZoom;
}
float Layer::getMaxZoom() const {
return baseImpl->maxZoom;
}
void Layer::setMaxZoom(float maxZoom) const {
baseImpl->maxZoom = maxZoom;
void Layer::setObserver(LayerObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
}
} // namespace style

View File

@@ -3,8 +3,10 @@
namespace mbgl {
namespace style {
void Layer::Impl::setObserver(LayerObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
Layer::Impl::Impl(LayerType type_, std::string layerID, std::string sourceID)
: type(type_),
id(std::move(layerID)),
source(std::move(sourceID)) {
}
} // namespace style

View File

@@ -3,13 +3,10 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/layer_observer.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <memory>
#include <string>
#include <limits>
@@ -30,24 +27,19 @@ namespace style {
* Members that are public in `FooLayer::Impl` are part of the internal API for "foo" layers.
* Members that are private in `FooLayer::Impl` are internal to "foo" layers.
*/
class Layer::Impl {
class Layer::Impl : public EnableImmutableFromThis<Layer::Impl> {
public:
Impl(LayerType, std::string layerID, std::string sourceID);
virtual ~Impl() = default;
// Create an identical copy of this layer.
virtual std::unique_ptr<Layer> clone() const = 0;
// Create a layer, copying all properties except id and paint properties from this layer.
virtual std::unique_ptr<Layer> cloneRef(const std::string& id) const = 0;
Impl& operator=(const Impl&) = delete;
// Utility function for automatic layer grouping.
virtual void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const = 0;
virtual std::unique_ptr<RenderLayer> createRenderLayer() const = 0;
void setObserver(LayerObserver*);
public:
const LayerType type;
std::string id;
std::string source;
std::string sourceLayer;
@@ -56,13 +48,8 @@ public:
float maxZoom = std::numeric_limits<float>::infinity();
VisibilityType visibility = VisibilityType::Visible;
LayerObserver nullObserver;
LayerObserver* observer = &nullObserver;
protected:
Impl() = default;
Impl(const Impl&) = default;
Impl& operator=(const Impl&) = delete;
};
} // namespace style

View File

@@ -3,38 +3,65 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
BackgroundLayer::BackgroundLayer(const std::string& layerID)
: Layer(LayerType::Background, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
: Layer(makeMutable<Impl>(LayerType::Background, layerID, std::string())) {
}
BackgroundLayer::BackgroundLayer(const Impl& other)
: Layer(LayerType::Background, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
BackgroundLayer::BackgroundLayer(Immutable<Impl> impl_)
: Layer(std::move(impl_)) {
}
BackgroundLayer::~BackgroundLayer() = default;
std::unique_ptr<Layer> BackgroundLayer::Impl::clone() const {
return std::make_unique<BackgroundLayer>(*this);
const BackgroundLayer::Impl& BackgroundLayer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
std::unique_ptr<Layer> BackgroundLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<BackgroundLayer>(*this);
result->impl->id = id_;
result->impl->cascading = BackgroundPaintProperties::Cascading();
return std::move(result);
Mutable<BackgroundLayer::Impl> BackgroundLayer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> BackgroundLayer::cloneRef(const std::string& id_) const {
auto impl_ = mutableImpl();
impl_->id = id_;
impl_->cascading = BackgroundPaintProperties::Cascading();
return std::make_unique<BackgroundLayer>(std::move(impl_));
}
void BackgroundLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Visibility
void BackgroundLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void BackgroundLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void BackgroundLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
// Layout properties
@@ -45,22 +72,26 @@ PropertyValue<Color> BackgroundLayer::getDefaultBackgroundColor() {
}
PropertyValue<Color> BackgroundLayer::getBackgroundColor(const optional<std::string>& klass) const {
return impl->cascading.template get<BackgroundColor>().get(klass);
return impl().cascading.template get<BackgroundColor>().get(klass);
}
void BackgroundLayer::setBackgroundColor(PropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getBackgroundColor(klass))
return;
impl->cascading.template get<BackgroundColor>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<BackgroundColor>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void BackgroundLayer::setBackgroundColorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<BackgroundColor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<BackgroundColor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions BackgroundLayer::getBackgroundColorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<BackgroundColor>().getTransition(klass);
return impl().cascading.template get<BackgroundColor>().getTransition(klass);
}
PropertyValue<std::string> BackgroundLayer::getDefaultBackgroundPattern() {
@@ -68,22 +99,26 @@ PropertyValue<std::string> BackgroundLayer::getDefaultBackgroundPattern() {
}
PropertyValue<std::string> BackgroundLayer::getBackgroundPattern(const optional<std::string>& klass) const {
return impl->cascading.template get<BackgroundPattern>().get(klass);
return impl().cascading.template get<BackgroundPattern>().get(klass);
}
void BackgroundLayer::setBackgroundPattern(PropertyValue<std::string> value, const optional<std::string>& klass) {
if (value == getBackgroundPattern(klass))
return;
impl->cascading.template get<BackgroundPattern>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<BackgroundPattern>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void BackgroundLayer::setBackgroundPatternTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<BackgroundPattern>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<BackgroundPattern>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions BackgroundLayer::getBackgroundPatternTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<BackgroundPattern>().getTransition(klass);
return impl().cascading.template get<BackgroundPattern>().getTransition(klass);
}
PropertyValue<float> BackgroundLayer::getDefaultBackgroundOpacity() {
@@ -91,22 +126,26 @@ PropertyValue<float> BackgroundLayer::getDefaultBackgroundOpacity() {
}
PropertyValue<float> BackgroundLayer::getBackgroundOpacity(const optional<std::string>& klass) const {
return impl->cascading.template get<BackgroundOpacity>().get(klass);
return impl().cascading.template get<BackgroundOpacity>().get(klass);
}
void BackgroundLayer::setBackgroundOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getBackgroundOpacity(klass))
return;
impl->cascading.template get<BackgroundOpacity>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<BackgroundOpacity>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void BackgroundLayer::setBackgroundOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<BackgroundOpacity>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<BackgroundOpacity>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions BackgroundLayer::getBackgroundOpacityTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<BackgroundOpacity>().getTransition(klass);
return impl().cascading.template get<BackgroundOpacity>().getTransition(klass);
}
} // namespace style

View File

@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> BackgroundLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderBackgroundLayer>(*this);
return std::make_unique<RenderBackgroundLayer>(staticImmutableCast<BackgroundLayer::Impl>(immutableFromThis()));
}
} // namespace style

View File

@@ -9,8 +9,8 @@ namespace style {
class BackgroundLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
using Layer::Impl::Impl;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const override;

View File

@@ -3,33 +3,34 @@
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/circle_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
CircleLayer::CircleLayer(const std::string& layerID, const std::string& sourceID)
: Layer(LayerType::Circle, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
impl->source = sourceID;
: Layer(makeMutable<Impl>(LayerType::Circle, layerID, sourceID)) {
}
CircleLayer::CircleLayer(const Impl& other)
: Layer(LayerType::Circle, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
CircleLayer::CircleLayer(Immutable<Impl> impl_)
: Layer(std::move(impl_)) {
}
CircleLayer::~CircleLayer() = default;
std::unique_ptr<Layer> CircleLayer::Impl::clone() const {
return std::make_unique<CircleLayer>(*this);
const CircleLayer::Impl& CircleLayer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
std::unique_ptr<Layer> CircleLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<CircleLayer>(*this);
result->impl->id = id_;
result->impl->cascading = CirclePaintProperties::Cascading();
return std::move(result);
Mutable<CircleLayer::Impl> CircleLayer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> CircleLayer::cloneRef(const std::string& id_) const {
auto impl_ = mutableImpl();
impl_->id = id_;
impl_->cascading = CirclePaintProperties::Cascading();
return std::make_unique<CircleLayer>(std::move(impl_));
}
void CircleLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
@@ -38,26 +39,55 @@ void CircleLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffe
// Source
const std::string& CircleLayer::getSourceID() const {
return impl->source;
return impl().source;
}
void CircleLayer::setSourceLayer(const std::string& sourceLayer) {
impl->sourceLayer = sourceLayer;
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& CircleLayer::getSourceLayer() const {
return impl->sourceLayer;
return impl().sourceLayer;
}
// Filter
void CircleLayer::setFilter(const Filter& filter) {
impl->filter = filter;
impl->observer->onLayerFilterChanged(*this);
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerFilterChanged(*this);
}
const Filter& CircleLayer::getFilter() const {
return impl->filter;
return impl().filter;
}
// Visibility
void CircleLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void CircleLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void CircleLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
// Layout properties
@@ -70,26 +100,30 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleRadius() {
}
DataDrivenPropertyValue<float> CircleLayer::getCircleRadius(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleRadius>().get(klass);
return impl().cascading.template get<CircleRadius>().get(klass);
}
void CircleLayer::setCircleRadius(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleRadius(klass))
return;
impl->cascading.template get<CircleRadius>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleRadius>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void CircleLayer::setCircleRadiusTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleRadius>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleRadius>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleRadiusTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleRadius>().getTransition(klass);
return impl().cascading.template get<CircleRadius>().getTransition(klass);
}
DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleColor() {
@@ -97,26 +131,30 @@ DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleColor() {
}
DataDrivenPropertyValue<Color> CircleLayer::getCircleColor(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleColor>().get(klass);
return impl().cascading.template get<CircleColor>().get(klass);
}
void CircleLayer::setCircleColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getCircleColor(klass))
return;
impl->cascading.template get<CircleColor>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleColor>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void CircleLayer::setCircleColorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleColor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleColor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleColorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleColor>().getTransition(klass);
return impl().cascading.template get<CircleColor>().getTransition(klass);
}
DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleBlur() {
@@ -124,26 +162,30 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleBlur() {
}
DataDrivenPropertyValue<float> CircleLayer::getCircleBlur(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleBlur>().get(klass);
return impl().cascading.template get<CircleBlur>().get(klass);
}
void CircleLayer::setCircleBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleBlur(klass))
return;
impl->cascading.template get<CircleBlur>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleBlur>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void CircleLayer::setCircleBlurTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleBlur>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleBlur>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleBlurTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleBlur>().getTransition(klass);
return impl().cascading.template get<CircleBlur>().getTransition(klass);
}
DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleOpacity() {
@@ -151,26 +193,30 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleOpacity() {
}
DataDrivenPropertyValue<float> CircleLayer::getCircleOpacity(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleOpacity>().get(klass);
return impl().cascading.template get<CircleOpacity>().get(klass);
}
void CircleLayer::setCircleOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleOpacity(klass))
return;
impl->cascading.template get<CircleOpacity>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleOpacity>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void CircleLayer::setCircleOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleOpacity>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleOpacity>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleOpacityTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleOpacity>().getTransition(klass);
return impl().cascading.template get<CircleOpacity>().getTransition(klass);
}
PropertyValue<std::array<float, 2>> CircleLayer::getDefaultCircleTranslate() {
@@ -178,22 +224,26 @@ PropertyValue<std::array<float, 2>> CircleLayer::getDefaultCircleTranslate() {
}
PropertyValue<std::array<float, 2>> CircleLayer::getCircleTranslate(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleTranslate>().get(klass);
return impl().cascading.template get<CircleTranslate>().get(klass);
}
void CircleLayer::setCircleTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) {
if (value == getCircleTranslate(klass))
return;
impl->cascading.template get<CircleTranslate>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleTranslate>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void CircleLayer::setCircleTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleTranslate>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleTranslate>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleTranslateTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleTranslate>().getTransition(klass);
return impl().cascading.template get<CircleTranslate>().getTransition(klass);
}
PropertyValue<TranslateAnchorType> CircleLayer::getDefaultCircleTranslateAnchor() {
@@ -201,22 +251,26 @@ PropertyValue<TranslateAnchorType> CircleLayer::getDefaultCircleTranslateAnchor(
}
PropertyValue<TranslateAnchorType> CircleLayer::getCircleTranslateAnchor(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleTranslateAnchor>().get(klass);
return impl().cascading.template get<CircleTranslateAnchor>().get(klass);
}
void CircleLayer::setCircleTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) {
if (value == getCircleTranslateAnchor(klass))
return;
impl->cascading.template get<CircleTranslateAnchor>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleTranslateAnchor>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void CircleLayer::setCircleTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleTranslateAnchor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleTranslateAnchor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleTranslateAnchorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleTranslateAnchor>().getTransition(klass);
return impl().cascading.template get<CircleTranslateAnchor>().getTransition(klass);
}
PropertyValue<CirclePitchScaleType> CircleLayer::getDefaultCirclePitchScale() {
@@ -224,22 +278,26 @@ PropertyValue<CirclePitchScaleType> CircleLayer::getDefaultCirclePitchScale() {
}
PropertyValue<CirclePitchScaleType> CircleLayer::getCirclePitchScale(const optional<std::string>& klass) const {
return impl->cascading.template get<CirclePitchScale>().get(klass);
return impl().cascading.template get<CirclePitchScale>().get(klass);
}
void CircleLayer::setCirclePitchScale(PropertyValue<CirclePitchScaleType> value, const optional<std::string>& klass) {
if (value == getCirclePitchScale(klass))
return;
impl->cascading.template get<CirclePitchScale>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<CirclePitchScale>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void CircleLayer::setCirclePitchScaleTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CirclePitchScale>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CirclePitchScale>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCirclePitchScaleTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CirclePitchScale>().getTransition(klass);
return impl().cascading.template get<CirclePitchScale>().getTransition(klass);
}
DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeWidth() {
@@ -247,26 +305,30 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeWidth() {
}
DataDrivenPropertyValue<float> CircleLayer::getCircleStrokeWidth(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleStrokeWidth>().get(klass);
return impl().cascading.template get<CircleStrokeWidth>().get(klass);
}
void CircleLayer::setCircleStrokeWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleStrokeWidth(klass))
return;
impl->cascading.template get<CircleStrokeWidth>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleStrokeWidth>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void CircleLayer::setCircleStrokeWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleStrokeWidth>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleStrokeWidth>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleStrokeWidthTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleStrokeWidth>().getTransition(klass);
return impl().cascading.template get<CircleStrokeWidth>().getTransition(klass);
}
DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleStrokeColor() {
@@ -274,26 +336,30 @@ DataDrivenPropertyValue<Color> CircleLayer::getDefaultCircleStrokeColor() {
}
DataDrivenPropertyValue<Color> CircleLayer::getCircleStrokeColor(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleStrokeColor>().get(klass);
return impl().cascading.template get<CircleStrokeColor>().get(klass);
}
void CircleLayer::setCircleStrokeColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getCircleStrokeColor(klass))
return;
impl->cascading.template get<CircleStrokeColor>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleStrokeColor>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void CircleLayer::setCircleStrokeColorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleStrokeColor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleStrokeColor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleStrokeColorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleStrokeColor>().getTransition(klass);
return impl().cascading.template get<CircleStrokeColor>().getTransition(klass);
}
DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeOpacity() {
@@ -301,26 +367,30 @@ DataDrivenPropertyValue<float> CircleLayer::getDefaultCircleStrokeOpacity() {
}
DataDrivenPropertyValue<float> CircleLayer::getCircleStrokeOpacity(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleStrokeOpacity>().get(klass);
return impl().cascading.template get<CircleStrokeOpacity>().get(klass);
}
void CircleLayer::setCircleStrokeOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getCircleStrokeOpacity(klass))
return;
impl->cascading.template get<CircleStrokeOpacity>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleStrokeOpacity>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void CircleLayer::setCircleStrokeOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<CircleStrokeOpacity>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<CircleStrokeOpacity>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions CircleLayer::getCircleStrokeOpacityTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<CircleStrokeOpacity>().getTransition(klass);
return impl().cascading.template get<CircleStrokeOpacity>().getTransition(klass);
}
} // namespace style

View File

@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> CircleLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderCircleLayer>(*this);
return std::make_unique<RenderCircleLayer>(staticImmutableCast<CircleLayer::Impl>(immutableFromThis()));
}
} // namespace style

View File

@@ -9,8 +9,8 @@ namespace style {
class CircleLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
using Layer::Impl::Impl;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const override;

View File

@@ -1,6 +1,6 @@
#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/style/layers/custom_layer_impl.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
@@ -10,21 +10,52 @@ CustomLayer::CustomLayer(const std::string& layerID,
CustomLayerRenderFunction render,
CustomLayerDeinitializeFunction deinit,
void* context)
: Layer(LayerType::Custom, std::make_unique<Impl>(layerID, init, render, deinit, context))
, impl(static_cast<Impl*>(baseImpl.get())) {
Log::Info(Event::General, "New custom layer: %s", layerID.c_str());
}
CustomLayer::CustomLayer(const Impl& other)
: Layer(LayerType::Custom, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
: Layer(makeMutable<Impl>(layerID, init, render, deinit, context)) {
}
CustomLayer::~CustomLayer() = default;
const CustomLayer::Impl& CustomLayer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
Mutable<CustomLayer::Impl> CustomLayer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> CustomLayer::cloneRef(const std::string&) const {
assert(false);
return nullptr;
}
// Visibility
void CustomLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void CustomLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void CustomLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
template <>
bool Layer::is<CustomLayer>() const {
return type == LayerType::Custom;
return getType() == LayerType::Custom;
}
} // namespace style

View File

@@ -2,52 +2,36 @@
#include <mbgl/renderer/render_custom_layer.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/util/logging.hpp>
namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> CustomLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderCustomLayer>(*this);
return std::make_unique<RenderCustomLayer>(staticImmutableCast<CustomLayer::Impl>(immutableFromThis()));
}
CustomLayer::Impl::Impl(const std::string& id_,
CustomLayerInitializeFunction initializeFn_,
CustomLayerRenderFunction renderFn_,
CustomLayerDeinitializeFunction deinitializeFn_,
void* context_) {
void* context_)
: Layer::Impl(LayerType::Custom, id_, std::string()) {
Log::Info(Event::General, "New custom layer Impl: %s", id_.c_str());
id = id_;
initializeFn = initializeFn_;
renderFn = renderFn_;
deinitializeFn = deinitializeFn_;
context = context_;
}
CustomLayer::Impl::Impl(const CustomLayer::Impl &other)
: Layer::Impl(other) {
id = other.id;
// Don't copy anything else.
}
CustomLayer::Impl::~Impl() = default;
std::unique_ptr<Layer> CustomLayer::Impl::clone() const {
return std::make_unique<CustomLayer>(*this);
}
std::unique_ptr<Layer> CustomLayer::Impl::cloneRef(const std::string&) const {
assert(false);
return std::make_unique<CustomLayer>(*this);
}
void CustomLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
void CustomLayer::Impl::initialize() {
void CustomLayer::Impl::initialize() const {
assert(initializeFn);
initializeFn(context);
}
void CustomLayer::Impl::deinitialize() {
void CustomLayer::Impl::deinitialize() const {
if (deinitializeFn) {
deinitializeFn(context);
}

View File

@@ -17,16 +17,11 @@ public:
CustomLayerDeinitializeFunction,
void* context);
Impl(const Impl&);
~Impl() final;
void initialize();
void deinitialize();
void initialize() const;
void deinitialize() const;
void render(const TransformState&) const;
private:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const final;

View File

@@ -3,33 +3,34 @@
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
#include <mbgl/style/layers/fill_extrusion_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
FillExtrusionLayer::FillExtrusionLayer(const std::string& layerID, const std::string& sourceID)
: Layer(LayerType::FillExtrusion, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
impl->source = sourceID;
: Layer(makeMutable<Impl>(LayerType::FillExtrusion, layerID, sourceID)) {
}
FillExtrusionLayer::FillExtrusionLayer(const Impl& other)
: Layer(LayerType::FillExtrusion, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
FillExtrusionLayer::FillExtrusionLayer(Immutable<Impl> impl_)
: Layer(std::move(impl_)) {
}
FillExtrusionLayer::~FillExtrusionLayer() = default;
std::unique_ptr<Layer> FillExtrusionLayer::Impl::clone() const {
return std::make_unique<FillExtrusionLayer>(*this);
const FillExtrusionLayer::Impl& FillExtrusionLayer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
std::unique_ptr<Layer> FillExtrusionLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<FillExtrusionLayer>(*this);
result->impl->id = id_;
result->impl->cascading = FillExtrusionPaintProperties::Cascading();
return std::move(result);
Mutable<FillExtrusionLayer::Impl> FillExtrusionLayer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> FillExtrusionLayer::cloneRef(const std::string& id_) const {
auto impl_ = mutableImpl();
impl_->id = id_;
impl_->cascading = FillExtrusionPaintProperties::Cascading();
return std::make_unique<FillExtrusionLayer>(std::move(impl_));
}
void FillExtrusionLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
@@ -38,26 +39,55 @@ void FillExtrusionLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::Stri
// Source
const std::string& FillExtrusionLayer::getSourceID() const {
return impl->source;
return impl().source;
}
void FillExtrusionLayer::setSourceLayer(const std::string& sourceLayer) {
impl->sourceLayer = sourceLayer;
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& FillExtrusionLayer::getSourceLayer() const {
return impl->sourceLayer;
return impl().sourceLayer;
}
// Filter
void FillExtrusionLayer::setFilter(const Filter& filter) {
impl->filter = filter;
impl->observer->onLayerFilterChanged(*this);
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerFilterChanged(*this);
}
const Filter& FillExtrusionLayer::getFilter() const {
return impl->filter;
return impl().filter;
}
// Visibility
void FillExtrusionLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void FillExtrusionLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void FillExtrusionLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
// Layout properties
@@ -70,22 +100,26 @@ PropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionOpacity() {
}
PropertyValue<float> FillExtrusionLayer::getFillExtrusionOpacity(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionOpacity>().get(klass);
return impl().cascading.template get<FillExtrusionOpacity>().get(klass);
}
void FillExtrusionLayer::setFillExtrusionOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getFillExtrusionOpacity(klass))
return;
impl->cascading.template get<FillExtrusionOpacity>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionOpacity>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillExtrusionLayer::setFillExtrusionOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillExtrusionOpacity>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionOpacity>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionOpacityTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionOpacity>().getTransition(klass);
return impl().cascading.template get<FillExtrusionOpacity>().getTransition(klass);
}
DataDrivenPropertyValue<Color> FillExtrusionLayer::getDefaultFillExtrusionColor() {
@@ -93,26 +127,30 @@ DataDrivenPropertyValue<Color> FillExtrusionLayer::getDefaultFillExtrusionColor(
}
DataDrivenPropertyValue<Color> FillExtrusionLayer::getFillExtrusionColor(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionColor>().get(klass);
return impl().cascading.template get<FillExtrusionColor>().get(klass);
}
void FillExtrusionLayer::setFillExtrusionColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getFillExtrusionColor(klass))
return;
impl->cascading.template get<FillExtrusionColor>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionColor>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void FillExtrusionLayer::setFillExtrusionColorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillExtrusionColor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionColor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionColorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionColor>().getTransition(klass);
return impl().cascading.template get<FillExtrusionColor>().getTransition(klass);
}
PropertyValue<std::array<float, 2>> FillExtrusionLayer::getDefaultFillExtrusionTranslate() {
@@ -120,22 +158,26 @@ PropertyValue<std::array<float, 2>> FillExtrusionLayer::getDefaultFillExtrusionT
}
PropertyValue<std::array<float, 2>> FillExtrusionLayer::getFillExtrusionTranslate(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionTranslate>().get(klass);
return impl().cascading.template get<FillExtrusionTranslate>().get(klass);
}
void FillExtrusionLayer::setFillExtrusionTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) {
if (value == getFillExtrusionTranslate(klass))
return;
impl->cascading.template get<FillExtrusionTranslate>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionTranslate>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillExtrusionLayer::setFillExtrusionTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillExtrusionTranslate>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionTranslate>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionTranslateTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionTranslate>().getTransition(klass);
return impl().cascading.template get<FillExtrusionTranslate>().getTransition(klass);
}
PropertyValue<TranslateAnchorType> FillExtrusionLayer::getDefaultFillExtrusionTranslateAnchor() {
@@ -143,22 +185,26 @@ PropertyValue<TranslateAnchorType> FillExtrusionLayer::getDefaultFillExtrusionTr
}
PropertyValue<TranslateAnchorType> FillExtrusionLayer::getFillExtrusionTranslateAnchor(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionTranslateAnchor>().get(klass);
return impl().cascading.template get<FillExtrusionTranslateAnchor>().get(klass);
}
void FillExtrusionLayer::setFillExtrusionTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) {
if (value == getFillExtrusionTranslateAnchor(klass))
return;
impl->cascading.template get<FillExtrusionTranslateAnchor>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionTranslateAnchor>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillExtrusionLayer::setFillExtrusionTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillExtrusionTranslateAnchor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionTranslateAnchor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionTranslateAnchorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionTranslateAnchor>().getTransition(klass);
return impl().cascading.template get<FillExtrusionTranslateAnchor>().getTransition(klass);
}
PropertyValue<std::string> FillExtrusionLayer::getDefaultFillExtrusionPattern() {
@@ -166,22 +212,26 @@ PropertyValue<std::string> FillExtrusionLayer::getDefaultFillExtrusionPattern()
}
PropertyValue<std::string> FillExtrusionLayer::getFillExtrusionPattern(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionPattern>().get(klass);
return impl().cascading.template get<FillExtrusionPattern>().get(klass);
}
void FillExtrusionLayer::setFillExtrusionPattern(PropertyValue<std::string> value, const optional<std::string>& klass) {
if (value == getFillExtrusionPattern(klass))
return;
impl->cascading.template get<FillExtrusionPattern>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionPattern>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillExtrusionLayer::setFillExtrusionPatternTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillExtrusionPattern>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionPattern>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionPatternTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionPattern>().getTransition(klass);
return impl().cascading.template get<FillExtrusionPattern>().getTransition(klass);
}
DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionHeight() {
@@ -189,26 +239,30 @@ DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionHeight
}
DataDrivenPropertyValue<float> FillExtrusionLayer::getFillExtrusionHeight(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionHeight>().get(klass);
return impl().cascading.template get<FillExtrusionHeight>().get(klass);
}
void FillExtrusionLayer::setFillExtrusionHeight(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getFillExtrusionHeight(klass))
return;
impl->cascading.template get<FillExtrusionHeight>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionHeight>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void FillExtrusionLayer::setFillExtrusionHeightTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillExtrusionHeight>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionHeight>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionHeightTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionHeight>().getTransition(klass);
return impl().cascading.template get<FillExtrusionHeight>().getTransition(klass);
}
DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionBase() {
@@ -216,26 +270,30 @@ DataDrivenPropertyValue<float> FillExtrusionLayer::getDefaultFillExtrusionBase()
}
DataDrivenPropertyValue<float> FillExtrusionLayer::getFillExtrusionBase(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionBase>().get(klass);
return impl().cascading.template get<FillExtrusionBase>().get(klass);
}
void FillExtrusionLayer::setFillExtrusionBase(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getFillExtrusionBase(klass))
return;
impl->cascading.template get<FillExtrusionBase>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionBase>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void FillExtrusionLayer::setFillExtrusionBaseTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillExtrusionBase>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillExtrusionBase>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillExtrusionLayer::getFillExtrusionBaseTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillExtrusionBase>().getTransition(klass);
return impl().cascading.template get<FillExtrusionBase>().getTransition(klass);
}
} // namespace style

View File

@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> FillExtrusionLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderFillExtrusionLayer>(*this);
return std::make_unique<RenderFillExtrusionLayer>(staticImmutableCast<FillExtrusionLayer::Impl>(immutableFromThis()));
}
} // namespace style

View File

@@ -9,8 +9,8 @@ namespace style {
class FillExtrusionLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
using Layer::Impl::Impl;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const override;

View File

@@ -3,33 +3,34 @@
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/fill_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
FillLayer::FillLayer(const std::string& layerID, const std::string& sourceID)
: Layer(LayerType::Fill, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
impl->source = sourceID;
: Layer(makeMutable<Impl>(LayerType::Fill, layerID, sourceID)) {
}
FillLayer::FillLayer(const Impl& other)
: Layer(LayerType::Fill, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
FillLayer::FillLayer(Immutable<Impl> impl_)
: Layer(std::move(impl_)) {
}
FillLayer::~FillLayer() = default;
std::unique_ptr<Layer> FillLayer::Impl::clone() const {
return std::make_unique<FillLayer>(*this);
const FillLayer::Impl& FillLayer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
std::unique_ptr<Layer> FillLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<FillLayer>(*this);
result->impl->id = id_;
result->impl->cascading = FillPaintProperties::Cascading();
return std::move(result);
Mutable<FillLayer::Impl> FillLayer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> FillLayer::cloneRef(const std::string& id_) const {
auto impl_ = mutableImpl();
impl_->id = id_;
impl_->cascading = FillPaintProperties::Cascading();
return std::make_unique<FillLayer>(std::move(impl_));
}
void FillLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
@@ -38,26 +39,55 @@ void FillLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>
// Source
const std::string& FillLayer::getSourceID() const {
return impl->source;
return impl().source;
}
void FillLayer::setSourceLayer(const std::string& sourceLayer) {
impl->sourceLayer = sourceLayer;
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& FillLayer::getSourceLayer() const {
return impl->sourceLayer;
return impl().sourceLayer;
}
// Filter
void FillLayer::setFilter(const Filter& filter) {
impl->filter = filter;
impl->observer->onLayerFilterChanged(*this);
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerFilterChanged(*this);
}
const Filter& FillLayer::getFilter() const {
return impl->filter;
return impl().filter;
}
// Visibility
void FillLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void FillLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void FillLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
// Layout properties
@@ -70,22 +100,26 @@ PropertyValue<bool> FillLayer::getDefaultFillAntialias() {
}
PropertyValue<bool> FillLayer::getFillAntialias(const optional<std::string>& klass) const {
return impl->cascading.template get<FillAntialias>().get(klass);
return impl().cascading.template get<FillAntialias>().get(klass);
}
void FillLayer::setFillAntialias(PropertyValue<bool> value, const optional<std::string>& klass) {
if (value == getFillAntialias(klass))
return;
impl->cascading.template get<FillAntialias>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillAntialias>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillLayer::setFillAntialiasTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillAntialias>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillAntialias>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillLayer::getFillAntialiasTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillAntialias>().getTransition(klass);
return impl().cascading.template get<FillAntialias>().getTransition(klass);
}
DataDrivenPropertyValue<float> FillLayer::getDefaultFillOpacity() {
@@ -93,26 +127,30 @@ DataDrivenPropertyValue<float> FillLayer::getDefaultFillOpacity() {
}
DataDrivenPropertyValue<float> FillLayer::getFillOpacity(const optional<std::string>& klass) const {
return impl->cascading.template get<FillOpacity>().get(klass);
return impl().cascading.template get<FillOpacity>().get(klass);
}
void FillLayer::setFillOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getFillOpacity(klass))
return;
impl->cascading.template get<FillOpacity>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillOpacity>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void FillLayer::setFillOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillOpacity>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillOpacity>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillLayer::getFillOpacityTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillOpacity>().getTransition(klass);
return impl().cascading.template get<FillOpacity>().getTransition(klass);
}
DataDrivenPropertyValue<Color> FillLayer::getDefaultFillColor() {
@@ -120,26 +158,30 @@ DataDrivenPropertyValue<Color> FillLayer::getDefaultFillColor() {
}
DataDrivenPropertyValue<Color> FillLayer::getFillColor(const optional<std::string>& klass) const {
return impl->cascading.template get<FillColor>().get(klass);
return impl().cascading.template get<FillColor>().get(klass);
}
void FillLayer::setFillColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getFillColor(klass))
return;
impl->cascading.template get<FillColor>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillColor>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void FillLayer::setFillColorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillColor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillColor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillLayer::getFillColorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillColor>().getTransition(klass);
return impl().cascading.template get<FillColor>().getTransition(klass);
}
DataDrivenPropertyValue<Color> FillLayer::getDefaultFillOutlineColor() {
@@ -147,26 +189,30 @@ DataDrivenPropertyValue<Color> FillLayer::getDefaultFillOutlineColor() {
}
DataDrivenPropertyValue<Color> FillLayer::getFillOutlineColor(const optional<std::string>& klass) const {
return impl->cascading.template get<FillOutlineColor>().get(klass);
return impl().cascading.template get<FillOutlineColor>().get(klass);
}
void FillLayer::setFillOutlineColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getFillOutlineColor(klass))
return;
impl->cascading.template get<FillOutlineColor>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillOutlineColor>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void FillLayer::setFillOutlineColorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillOutlineColor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillOutlineColor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillLayer::getFillOutlineColorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillOutlineColor>().getTransition(klass);
return impl().cascading.template get<FillOutlineColor>().getTransition(klass);
}
PropertyValue<std::array<float, 2>> FillLayer::getDefaultFillTranslate() {
@@ -174,22 +220,26 @@ PropertyValue<std::array<float, 2>> FillLayer::getDefaultFillTranslate() {
}
PropertyValue<std::array<float, 2>> FillLayer::getFillTranslate(const optional<std::string>& klass) const {
return impl->cascading.template get<FillTranslate>().get(klass);
return impl().cascading.template get<FillTranslate>().get(klass);
}
void FillLayer::setFillTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) {
if (value == getFillTranslate(klass))
return;
impl->cascading.template get<FillTranslate>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillTranslate>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillLayer::setFillTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillTranslate>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillTranslate>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillLayer::getFillTranslateTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillTranslate>().getTransition(klass);
return impl().cascading.template get<FillTranslate>().getTransition(klass);
}
PropertyValue<TranslateAnchorType> FillLayer::getDefaultFillTranslateAnchor() {
@@ -197,22 +247,26 @@ PropertyValue<TranslateAnchorType> FillLayer::getDefaultFillTranslateAnchor() {
}
PropertyValue<TranslateAnchorType> FillLayer::getFillTranslateAnchor(const optional<std::string>& klass) const {
return impl->cascading.template get<FillTranslateAnchor>().get(klass);
return impl().cascading.template get<FillTranslateAnchor>().get(klass);
}
void FillLayer::setFillTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) {
if (value == getFillTranslateAnchor(klass))
return;
impl->cascading.template get<FillTranslateAnchor>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillTranslateAnchor>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillLayer::setFillTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillTranslateAnchor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillTranslateAnchor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillLayer::getFillTranslateAnchorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillTranslateAnchor>().getTransition(klass);
return impl().cascading.template get<FillTranslateAnchor>().getTransition(klass);
}
PropertyValue<std::string> FillLayer::getDefaultFillPattern() {
@@ -220,22 +274,26 @@ PropertyValue<std::string> FillLayer::getDefaultFillPattern() {
}
PropertyValue<std::string> FillLayer::getFillPattern(const optional<std::string>& klass) const {
return impl->cascading.template get<FillPattern>().get(klass);
return impl().cascading.template get<FillPattern>().get(klass);
}
void FillLayer::setFillPattern(PropertyValue<std::string> value, const optional<std::string>& klass) {
if (value == getFillPattern(klass))
return;
impl->cascading.template get<FillPattern>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillPattern>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void FillLayer::setFillPatternTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<FillPattern>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<FillPattern>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions FillLayer::getFillPatternTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<FillPattern>().getTransition(klass);
return impl().cascading.template get<FillPattern>().getTransition(klass);
}
} // namespace style

View File

@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> FillLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderFillLayer>(*this);
return std::make_unique<RenderFillLayer>(staticImmutableCast<FillLayer::Impl>(immutableFromThis()));
}
} // namespace style

View File

@@ -9,8 +9,8 @@ namespace style {
class FillLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
using Layer::Impl::Impl;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const override;

View File

@@ -8,41 +8,40 @@
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp>
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
<% if (type === 'background') { -%>
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID)
: Layer(LayerType::<%- camelize(type) %>, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
: Layer(makeMutable<Impl>(LayerType::<%- camelize(type) %>, layerID, std::string())) {
}
<% } else { -%>
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID, const std::string& sourceID)
: Layer(LayerType::<%- camelize(type) %>, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
impl->source = sourceID;
: Layer(makeMutable<Impl>(LayerType::<%- camelize(type) %>, layerID, sourceID)) {
}
<% } -%>
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const Impl& other)
: Layer(LayerType::<%- camelize(type) %>, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(Immutable<Impl> impl_)
: Layer(std::move(impl_)) {
}
<%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default;
std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::clone() const {
return std::make_unique<<%- camelize(type) %>Layer>(*this);
const <%- camelize(type) %>Layer::Impl& <%- camelize(type) %>Layer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<<%- camelize(type) %>Layer>(*this);
result->impl->id = id_;
result->impl->cascading = <%- camelize(type) %>PaintProperties::Cascading();
return std::move(result);
Mutable<<%- camelize(type) %>Layer::Impl> <%- camelize(type) %>Layer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> <%- camelize(type) %>Layer::cloneRef(const std::string& id_) const {
auto impl_ = mutableImpl();
impl_->id = id_;
impl_->cascading = <%- camelize(type) %>PaintProperties::Cascading();
return std::make_unique<<%- camelize(type) %>Layer>(std::move(impl_));
}
<% if (layoutProperties.length) { -%>
@@ -58,31 +57,60 @@ void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjs
// Source
const std::string& <%- camelize(type) %>Layer::getSourceID() const {
return impl->source;
return impl().source;
}
<% if (type !== 'raster') { -%>
void <%- camelize(type) %>Layer::setSourceLayer(const std::string& sourceLayer) {
impl->sourceLayer = sourceLayer;
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& <%- camelize(type) %>Layer::getSourceLayer() const {
return impl->sourceLayer;
return impl().sourceLayer;
}
// Filter
void <%- camelize(type) %>Layer::setFilter(const Filter& filter) {
impl->filter = filter;
impl->observer->onLayerFilterChanged(*this);
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerFilterChanged(*this);
}
const Filter& <%- camelize(type) %>Layer::getFilter() const {
return impl->filter;
return impl().filter;
}
<% } -%>
<% } -%>
// Visibility
void <%- camelize(type) %>Layer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void <%- camelize(type) %>Layer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void <%- camelize(type) %>Layer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
// Layout properties
<% for (const property of layoutProperties) { -%>
@@ -91,14 +119,16 @@ const Filter& <%- camelize(type) %>Layer::getFilter() const {
}
<%- propertyValueType(property) %> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
return impl->layout.unevaluated.get<<%- camelize(property.name) %>>();
return impl().layout.unevaluated.get<<%- camelize(property.name) %>>();
}
void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> value) {
if (value == get<%- camelize(property.name) %>())
return;
impl->layout.unevaluated.get<<%- camelize(property.name) %>>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "<%- property.name %>");
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<<%- camelize(property.name) %>>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "<%- property.name %>");
}
<% } -%>
@@ -109,30 +139,34 @@ void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyV
}
<%- propertyValueType(property) %> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(const optional<std::string>& klass) const {
return impl->cascading.template get<<%- camelize(property.name) %>>().get(klass);
return impl().cascading.template get<<%- camelize(property.name) %>>().get(klass);
}
void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> value, const optional<std::string>& klass) {
if (value == get<%- camelize(property.name) %>(klass))
return;
impl->cascading.template get<<%- camelize(property.name) %>>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<<%- camelize(property.name) %>>().set(value, klass);
baseImpl = std::move(impl_);
<% if (isDataDriven(property)) { -%>
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
<% } else { -%>
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
<% } -%>
}
void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>Transition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<<%- camelize(property.name) %>>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<<%- camelize(property.name) %>>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions <%- camelize(type) %>Layer::get<%- camelize(property.name) %>Transition(const optional<std::string>& klass) const {
return impl->cascading.template get<<%- camelize(property.name) %>>().getTransition(klass);
return impl().cascading.template get<<%- camelize(property.name) %>>().getTransition(klass);
}
<% } -%>

View File

@@ -3,33 +3,34 @@
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/line_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
LineLayer::LineLayer(const std::string& layerID, const std::string& sourceID)
: Layer(LayerType::Line, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
impl->source = sourceID;
: Layer(makeMutable<Impl>(LayerType::Line, layerID, sourceID)) {
}
LineLayer::LineLayer(const Impl& other)
: Layer(LayerType::Line, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
LineLayer::LineLayer(Immutable<Impl> impl_)
: Layer(std::move(impl_)) {
}
LineLayer::~LineLayer() = default;
std::unique_ptr<Layer> LineLayer::Impl::clone() const {
return std::make_unique<LineLayer>(*this);
const LineLayer::Impl& LineLayer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
std::unique_ptr<Layer> LineLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<LineLayer>(*this);
result->impl->id = id_;
result->impl->cascading = LinePaintProperties::Cascading();
return std::move(result);
Mutable<LineLayer::Impl> LineLayer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> LineLayer::cloneRef(const std::string& id_) const {
auto impl_ = mutableImpl();
impl_->id = id_;
impl_->cascading = LinePaintProperties::Cascading();
return std::make_unique<LineLayer>(std::move(impl_));
}
void LineLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
@@ -39,26 +40,55 @@ void LineLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>
// Source
const std::string& LineLayer::getSourceID() const {
return impl->source;
return impl().source;
}
void LineLayer::setSourceLayer(const std::string& sourceLayer) {
impl->sourceLayer = sourceLayer;
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& LineLayer::getSourceLayer() const {
return impl->sourceLayer;
return impl().sourceLayer;
}
// Filter
void LineLayer::setFilter(const Filter& filter) {
impl->filter = filter;
impl->observer->onLayerFilterChanged(*this);
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerFilterChanged(*this);
}
const Filter& LineLayer::getFilter() const {
return impl->filter;
return impl().filter;
}
// Visibility
void LineLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void LineLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void LineLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
// Layout properties
@@ -68,56 +98,64 @@ PropertyValue<LineCapType> LineLayer::getDefaultLineCap() {
}
PropertyValue<LineCapType> LineLayer::getLineCap() const {
return impl->layout.unevaluated.get<LineCap>();
return impl().layout.unevaluated.get<LineCap>();
}
void LineLayer::setLineCap(PropertyValue<LineCapType> value) {
if (value == getLineCap())
return;
impl->layout.unevaluated.get<LineCap>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "line-cap");
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineCap>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-cap");
}
PropertyValue<LineJoinType> LineLayer::getDefaultLineJoin() {
return LineJoin::defaultValue();
}
PropertyValue<LineJoinType> LineLayer::getLineJoin() const {
return impl->layout.unevaluated.get<LineJoin>();
return impl().layout.unevaluated.get<LineJoin>();
}
void LineLayer::setLineJoin(PropertyValue<LineJoinType> value) {
if (value == getLineJoin())
return;
impl->layout.unevaluated.get<LineJoin>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "line-join");
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineJoin>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-join");
}
PropertyValue<float> LineLayer::getDefaultLineMiterLimit() {
return LineMiterLimit::defaultValue();
}
PropertyValue<float> LineLayer::getLineMiterLimit() const {
return impl->layout.unevaluated.get<LineMiterLimit>();
return impl().layout.unevaluated.get<LineMiterLimit>();
}
void LineLayer::setLineMiterLimit(PropertyValue<float> value) {
if (value == getLineMiterLimit())
return;
impl->layout.unevaluated.get<LineMiterLimit>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit");
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineMiterLimit>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit");
}
PropertyValue<float> LineLayer::getDefaultLineRoundLimit() {
return LineRoundLimit::defaultValue();
}
PropertyValue<float> LineLayer::getLineRoundLimit() const {
return impl->layout.unevaluated.get<LineRoundLimit>();
return impl().layout.unevaluated.get<LineRoundLimit>();
}
void LineLayer::setLineRoundLimit(PropertyValue<float> value) {
if (value == getLineRoundLimit())
return;
impl->layout.unevaluated.get<LineRoundLimit>() = value;
impl->observer->onLayerLayoutPropertyChanged(*this, "line-round-limit");
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineRoundLimit>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-round-limit");
}
// Paint properties
@@ -127,26 +165,30 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineOpacity() {
}
DataDrivenPropertyValue<float> LineLayer::getLineOpacity(const optional<std::string>& klass) const {
return impl->cascading.template get<LineOpacity>().get(klass);
return impl().cascading.template get<LineOpacity>().get(klass);
}
void LineLayer::setLineOpacity(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineOpacity(klass))
return;
impl->cascading.template get<LineOpacity>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineOpacity>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void LineLayer::setLineOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineOpacity>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineOpacity>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineOpacityTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineOpacity>().getTransition(klass);
return impl().cascading.template get<LineOpacity>().getTransition(klass);
}
DataDrivenPropertyValue<Color> LineLayer::getDefaultLineColor() {
@@ -154,26 +196,30 @@ DataDrivenPropertyValue<Color> LineLayer::getDefaultLineColor() {
}
DataDrivenPropertyValue<Color> LineLayer::getLineColor(const optional<std::string>& klass) const {
return impl->cascading.template get<LineColor>().get(klass);
return impl().cascading.template get<LineColor>().get(klass);
}
void LineLayer::setLineColor(DataDrivenPropertyValue<Color> value, const optional<std::string>& klass) {
if (value == getLineColor(klass))
return;
impl->cascading.template get<LineColor>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineColor>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void LineLayer::setLineColorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineColor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineColor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineColorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineColor>().getTransition(klass);
return impl().cascading.template get<LineColor>().getTransition(klass);
}
PropertyValue<std::array<float, 2>> LineLayer::getDefaultLineTranslate() {
@@ -181,22 +227,26 @@ PropertyValue<std::array<float, 2>> LineLayer::getDefaultLineTranslate() {
}
PropertyValue<std::array<float, 2>> LineLayer::getLineTranslate(const optional<std::string>& klass) const {
return impl->cascading.template get<LineTranslate>().get(klass);
return impl().cascading.template get<LineTranslate>().get(klass);
}
void LineLayer::setLineTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) {
if (value == getLineTranslate(klass))
return;
impl->cascading.template get<LineTranslate>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineTranslate>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void LineLayer::setLineTranslateTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineTranslate>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineTranslate>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineTranslateTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineTranslate>().getTransition(klass);
return impl().cascading.template get<LineTranslate>().getTransition(klass);
}
PropertyValue<TranslateAnchorType> LineLayer::getDefaultLineTranslateAnchor() {
@@ -204,22 +254,26 @@ PropertyValue<TranslateAnchorType> LineLayer::getDefaultLineTranslateAnchor() {
}
PropertyValue<TranslateAnchorType> LineLayer::getLineTranslateAnchor(const optional<std::string>& klass) const {
return impl->cascading.template get<LineTranslateAnchor>().get(klass);
return impl().cascading.template get<LineTranslateAnchor>().get(klass);
}
void LineLayer::setLineTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) {
if (value == getLineTranslateAnchor(klass))
return;
impl->cascading.template get<LineTranslateAnchor>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineTranslateAnchor>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void LineLayer::setLineTranslateAnchorTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineTranslateAnchor>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineTranslateAnchor>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineTranslateAnchorTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineTranslateAnchor>().getTransition(klass);
return impl().cascading.template get<LineTranslateAnchor>().getTransition(klass);
}
PropertyValue<float> LineLayer::getDefaultLineWidth() {
@@ -227,22 +281,26 @@ PropertyValue<float> LineLayer::getDefaultLineWidth() {
}
PropertyValue<float> LineLayer::getLineWidth(const optional<std::string>& klass) const {
return impl->cascading.template get<LineWidth>().get(klass);
return impl().cascading.template get<LineWidth>().get(klass);
}
void LineLayer::setLineWidth(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineWidth(klass))
return;
impl->cascading.template get<LineWidth>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineWidth>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void LineLayer::setLineWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineWidth>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineWidth>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineWidthTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineWidth>().getTransition(klass);
return impl().cascading.template get<LineWidth>().getTransition(klass);
}
DataDrivenPropertyValue<float> LineLayer::getDefaultLineGapWidth() {
@@ -250,26 +308,30 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineGapWidth() {
}
DataDrivenPropertyValue<float> LineLayer::getLineGapWidth(const optional<std::string>& klass) const {
return impl->cascading.template get<LineGapWidth>().get(klass);
return impl().cascading.template get<LineGapWidth>().get(klass);
}
void LineLayer::setLineGapWidth(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineGapWidth(klass))
return;
impl->cascading.template get<LineGapWidth>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineGapWidth>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void LineLayer::setLineGapWidthTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineGapWidth>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineGapWidth>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineGapWidthTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineGapWidth>().getTransition(klass);
return impl().cascading.template get<LineGapWidth>().getTransition(klass);
}
DataDrivenPropertyValue<float> LineLayer::getDefaultLineOffset() {
@@ -277,26 +339,30 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineOffset() {
}
DataDrivenPropertyValue<float> LineLayer::getLineOffset(const optional<std::string>& klass) const {
return impl->cascading.template get<LineOffset>().get(klass);
return impl().cascading.template get<LineOffset>().get(klass);
}
void LineLayer::setLineOffset(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineOffset(klass))
return;
impl->cascading.template get<LineOffset>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineOffset>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void LineLayer::setLineOffsetTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineOffset>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineOffset>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineOffsetTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineOffset>().getTransition(klass);
return impl().cascading.template get<LineOffset>().getTransition(klass);
}
DataDrivenPropertyValue<float> LineLayer::getDefaultLineBlur() {
@@ -304,26 +370,30 @@ DataDrivenPropertyValue<float> LineLayer::getDefaultLineBlur() {
}
DataDrivenPropertyValue<float> LineLayer::getLineBlur(const optional<std::string>& klass) const {
return impl->cascading.template get<LineBlur>().get(klass);
return impl().cascading.template get<LineBlur>().get(klass);
}
void LineLayer::setLineBlur(DataDrivenPropertyValue<float> value, const optional<std::string>& klass) {
if (value == getLineBlur(klass))
return;
impl->cascading.template get<LineBlur>().set(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineBlur>().set(value, klass);
baseImpl = std::move(impl_);
if (value.isDataDriven()) {
impl->observer->onLayerDataDrivenPaintPropertyChanged(*this);
observer->onLayerDataDrivenPaintPropertyChanged(*this);
} else {
impl->observer->onLayerPaintPropertyChanged(*this);
observer->onLayerPaintPropertyChanged(*this);
}
}
void LineLayer::setLineBlurTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineBlur>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineBlur>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineBlurTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineBlur>().getTransition(klass);
return impl().cascading.template get<LineBlur>().getTransition(klass);
}
PropertyValue<std::vector<float>> LineLayer::getDefaultLineDasharray() {
@@ -331,22 +401,26 @@ PropertyValue<std::vector<float>> LineLayer::getDefaultLineDasharray() {
}
PropertyValue<std::vector<float>> LineLayer::getLineDasharray(const optional<std::string>& klass) const {
return impl->cascading.template get<LineDasharray>().get(klass);
return impl().cascading.template get<LineDasharray>().get(klass);
}
void LineLayer::setLineDasharray(PropertyValue<std::vector<float>> value, const optional<std::string>& klass) {
if (value == getLineDasharray(klass))
return;
impl->cascading.template get<LineDasharray>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineDasharray>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void LineLayer::setLineDasharrayTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LineDasharray>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LineDasharray>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLineDasharrayTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LineDasharray>().getTransition(klass);
return impl().cascading.template get<LineDasharray>().getTransition(klass);
}
PropertyValue<std::string> LineLayer::getDefaultLinePattern() {
@@ -354,22 +428,26 @@ PropertyValue<std::string> LineLayer::getDefaultLinePattern() {
}
PropertyValue<std::string> LineLayer::getLinePattern(const optional<std::string>& klass) const {
return impl->cascading.template get<LinePattern>().get(klass);
return impl().cascading.template get<LinePattern>().get(klass);
}
void LineLayer::setLinePattern(PropertyValue<std::string> value, const optional<std::string>& klass) {
if (value == getLinePattern(klass))
return;
impl->cascading.template get<LinePattern>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<LinePattern>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void LineLayer::setLinePatternTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<LinePattern>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<LinePattern>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions LineLayer::getLinePatternTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<LinePattern>().getTransition(klass);
return impl().cascading.template get<LinePattern>().getTransition(klass);
}
} // namespace style

View File

@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> LineLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderLineLayer>(*this);
return std::make_unique<RenderLineLayer>(staticImmutableCast<LineLayer::Impl>(immutableFromThis()));
}
} // namespace style

View File

@@ -9,8 +9,8 @@ namespace style {
class LineLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
using Layer::Impl::Impl;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const override;

View File

@@ -3,33 +3,34 @@
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/raster_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
namespace style {
RasterLayer::RasterLayer(const std::string& layerID, const std::string& sourceID)
: Layer(LayerType::Raster, std::make_unique<Impl>())
, impl(static_cast<Impl*>(baseImpl.get())) {
impl->id = layerID;
impl->source = sourceID;
: Layer(makeMutable<Impl>(LayerType::Raster, layerID, sourceID)) {
}
RasterLayer::RasterLayer(const Impl& other)
: Layer(LayerType::Raster, std::make_unique<Impl>(other))
, impl(static_cast<Impl*>(baseImpl.get())) {
RasterLayer::RasterLayer(Immutable<Impl> impl_)
: Layer(std::move(impl_)) {
}
RasterLayer::~RasterLayer() = default;
std::unique_ptr<Layer> RasterLayer::Impl::clone() const {
return std::make_unique<RasterLayer>(*this);
const RasterLayer::Impl& RasterLayer::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
std::unique_ptr<Layer> RasterLayer::Impl::cloneRef(const std::string& id_) const {
auto result = std::make_unique<RasterLayer>(*this);
result->impl->id = id_;
result->impl->cascading = RasterPaintProperties::Cascading();
return std::move(result);
Mutable<RasterLayer::Impl> RasterLayer::mutableImpl() const {
return makeMutable<Impl>(impl());
}
std::unique_ptr<Layer> RasterLayer::cloneRef(const std::string& id_) const {
auto impl_ = mutableImpl();
impl_->id = id_;
impl_->cascading = RasterPaintProperties::Cascading();
return std::make_unique<RasterLayer>(std::move(impl_));
}
void RasterLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
@@ -38,10 +39,35 @@ void RasterLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffe
// Source
const std::string& RasterLayer::getSourceID() const {
return impl->source;
return impl().source;
}
// Visibility
void RasterLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerVisibilityChanged(*this);
}
// Zoom range
void RasterLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void RasterLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
// Layout properties
@@ -52,22 +78,26 @@ PropertyValue<float> RasterLayer::getDefaultRasterOpacity() {
}
PropertyValue<float> RasterLayer::getRasterOpacity(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterOpacity>().get(klass);
return impl().cascading.template get<RasterOpacity>().get(klass);
}
void RasterLayer::setRasterOpacity(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getRasterOpacity(klass))
return;
impl->cascading.template get<RasterOpacity>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterOpacity>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void RasterLayer::setRasterOpacityTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<RasterOpacity>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterOpacity>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions RasterLayer::getRasterOpacityTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterOpacity>().getTransition(klass);
return impl().cascading.template get<RasterOpacity>().getTransition(klass);
}
PropertyValue<float> RasterLayer::getDefaultRasterHueRotate() {
@@ -75,22 +105,26 @@ PropertyValue<float> RasterLayer::getDefaultRasterHueRotate() {
}
PropertyValue<float> RasterLayer::getRasterHueRotate(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterHueRotate>().get(klass);
return impl().cascading.template get<RasterHueRotate>().get(klass);
}
void RasterLayer::setRasterHueRotate(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getRasterHueRotate(klass))
return;
impl->cascading.template get<RasterHueRotate>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterHueRotate>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void RasterLayer::setRasterHueRotateTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<RasterHueRotate>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterHueRotate>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions RasterLayer::getRasterHueRotateTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterHueRotate>().getTransition(klass);
return impl().cascading.template get<RasterHueRotate>().getTransition(klass);
}
PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMin() {
@@ -98,22 +132,26 @@ PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMin() {
}
PropertyValue<float> RasterLayer::getRasterBrightnessMin(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterBrightnessMin>().get(klass);
return impl().cascading.template get<RasterBrightnessMin>().get(klass);
}
void RasterLayer::setRasterBrightnessMin(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getRasterBrightnessMin(klass))
return;
impl->cascading.template get<RasterBrightnessMin>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterBrightnessMin>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void RasterLayer::setRasterBrightnessMinTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<RasterBrightnessMin>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterBrightnessMin>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions RasterLayer::getRasterBrightnessMinTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterBrightnessMin>().getTransition(klass);
return impl().cascading.template get<RasterBrightnessMin>().getTransition(klass);
}
PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMax() {
@@ -121,22 +159,26 @@ PropertyValue<float> RasterLayer::getDefaultRasterBrightnessMax() {
}
PropertyValue<float> RasterLayer::getRasterBrightnessMax(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterBrightnessMax>().get(klass);
return impl().cascading.template get<RasterBrightnessMax>().get(klass);
}
void RasterLayer::setRasterBrightnessMax(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getRasterBrightnessMax(klass))
return;
impl->cascading.template get<RasterBrightnessMax>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterBrightnessMax>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void RasterLayer::setRasterBrightnessMaxTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<RasterBrightnessMax>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterBrightnessMax>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions RasterLayer::getRasterBrightnessMaxTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterBrightnessMax>().getTransition(klass);
return impl().cascading.template get<RasterBrightnessMax>().getTransition(klass);
}
PropertyValue<float> RasterLayer::getDefaultRasterSaturation() {
@@ -144,22 +186,26 @@ PropertyValue<float> RasterLayer::getDefaultRasterSaturation() {
}
PropertyValue<float> RasterLayer::getRasterSaturation(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterSaturation>().get(klass);
return impl().cascading.template get<RasterSaturation>().get(klass);
}
void RasterLayer::setRasterSaturation(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getRasterSaturation(klass))
return;
impl->cascading.template get<RasterSaturation>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterSaturation>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void RasterLayer::setRasterSaturationTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<RasterSaturation>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterSaturation>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions RasterLayer::getRasterSaturationTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterSaturation>().getTransition(klass);
return impl().cascading.template get<RasterSaturation>().getTransition(klass);
}
PropertyValue<float> RasterLayer::getDefaultRasterContrast() {
@@ -167,22 +213,26 @@ PropertyValue<float> RasterLayer::getDefaultRasterContrast() {
}
PropertyValue<float> RasterLayer::getRasterContrast(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterContrast>().get(klass);
return impl().cascading.template get<RasterContrast>().get(klass);
}
void RasterLayer::setRasterContrast(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getRasterContrast(klass))
return;
impl->cascading.template get<RasterContrast>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterContrast>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void RasterLayer::setRasterContrastTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<RasterContrast>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterContrast>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions RasterLayer::getRasterContrastTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterContrast>().getTransition(klass);
return impl().cascading.template get<RasterContrast>().getTransition(klass);
}
PropertyValue<float> RasterLayer::getDefaultRasterFadeDuration() {
@@ -190,22 +240,26 @@ PropertyValue<float> RasterLayer::getDefaultRasterFadeDuration() {
}
PropertyValue<float> RasterLayer::getRasterFadeDuration(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterFadeDuration>().get(klass);
return impl().cascading.template get<RasterFadeDuration>().get(klass);
}
void RasterLayer::setRasterFadeDuration(PropertyValue<float> value, const optional<std::string>& klass) {
if (value == getRasterFadeDuration(klass))
return;
impl->cascading.template get<RasterFadeDuration>().set(value, klass);
impl->observer->onLayerPaintPropertyChanged(*this);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterFadeDuration>().set(value, klass);
baseImpl = std::move(impl_);
observer->onLayerPaintPropertyChanged(*this);
}
void RasterLayer::setRasterFadeDurationTransition(const TransitionOptions& value, const optional<std::string>& klass) {
impl->cascading.template get<RasterFadeDuration>().setTransition(value, klass);
auto impl_ = mutableImpl();
impl_->cascading.template get<RasterFadeDuration>().setTransition(value, klass);
baseImpl = std::move(impl_);
}
TransitionOptions RasterLayer::getRasterFadeDurationTransition(const optional<std::string>& klass) const {
return impl->cascading.template get<RasterFadeDuration>().getTransition(klass);
return impl().cascading.template get<RasterFadeDuration>().getTransition(klass);
}
} // namespace style

View File

@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> RasterLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderRasterLayer>(*this);
return std::make_unique<RenderRasterLayer>(staticImmutableCast<RasterLayer::Impl>(immutableFromThis()));
}
} // namespace style

View File

@@ -9,8 +9,8 @@ namespace style {
class RasterLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
using Layer::Impl::Impl;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const override;

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
std::unique_ptr<RenderLayer> SymbolLayer::Impl::createRenderLayer() const {
return std::make_unique<RenderSymbolLayer>(*this);
return std::make_unique<RenderSymbolLayer>(staticImmutableCast<SymbolLayer::Impl>(immutableFromThis()));
}
} // namespace style

View File

@@ -6,13 +6,12 @@
#include <mbgl/style/layers/symbol_layer_properties.hpp>
namespace mbgl {
namespace style {
class SymbolLayer::Impl : public Layer::Impl {
public:
std::unique_ptr<Layer> clone() const override;
std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
using Layer::Impl::Impl;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
std::unique_ptr<RenderLayer> createRenderLayer() const override;

View File

@@ -2,17 +2,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);
}
LightAnchorType Light::getDefaultAnchor() {
return LightAnchor::defaultValue();
}
@@ -22,13 +34,17 @@ PropertyValue<LightAnchorType> Light::getAnchor() const {
}
void Light::setAnchor(PropertyValue<LightAnchorType> property) {
impl->properties.template get<LightAnchor>().value = property;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightAnchor>().value = property;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setAnchorTransition(const TransitionOptions& transition) {
impl->properties.template get<LightAnchor>().transition = transition;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightAnchor>().transition = transition;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getAnchorTransition() const {
@@ -44,13 +60,17 @@ PropertyValue<Position> Light::getPosition() const {
}
void Light::setPosition(PropertyValue<Position> property) {
impl->properties.template get<LightPosition>().value = property;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightPosition>().value = property;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setPositionTransition(const TransitionOptions& transition) {
impl->properties.template get<LightPosition>().transition = transition;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightPosition>().transition = transition;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getPositionTransition() const {
@@ -66,13 +86,17 @@ PropertyValue<Color> Light::getColor() const {
}
void Light::setColor(PropertyValue<Color> property) {
impl->properties.template get<LightColor>().value = property;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightColor>().value = property;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setColorTransition(const TransitionOptions& transition) {
impl->properties.template get<LightColor>().transition = transition;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightColor>().transition = transition;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getColorTransition() const {
@@ -88,13 +112,17 @@ PropertyValue<float> Light::getIntensity() const {
}
void Light::setIntensity(PropertyValue<float> property) {
impl->properties.template get<LightIntensity>().value = property;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightIntensity>().value = property;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
void Light::setIntensityTransition(const TransitionOptions& transition) {
impl->properties.template get<LightIntensity>().transition = transition;
impl->observer->onLightChanged(*this);
auto impl_ = mutableImpl();
impl_->properties.template get<LightIntensity>().transition = transition;
impl = std::move(impl_);
observer->onLightChanged(*this);
}
TransitionOptions Light::getIntensityTransition() const {

View File

@@ -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 {

View File

@@ -3,9 +3,5 @@
namespace mbgl {
namespace style {
void Light::Impl::setObserver(LightObserver* observer_) {
observer = observer_;
}
} // namespace style
} // namespace mbgl

View File

@@ -1,18 +1,13 @@
#pragma once
#include <mbgl/style/light.hpp>
#include <mbgl/style/light_properties.hpp>
#include <mbgl/style/light_observer.hpp>
namespace mbgl {
namespace style {
class Light::Impl {
public:
LightObserver nullObserver;
LightObserver* observer = &nullObserver;
void setObserver(LightObserver*);
IndexedTuple<LightProperties, LightProperties> properties;
};

View File

@@ -1,10 +1,10 @@
#pragma once
#include <mbgl/style/light.hpp>
namespace mbgl {
namespace style {
class Light;
class LightObserver {
public:
virtual ~LightObserver() = default;

View File

@@ -236,7 +236,7 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
return;
}
layer = reference->baseImpl->cloneRef(id);
layer = reference->cloneRef(id);
conversion::setPaintProperties(*layer, value);
} else {
conversion::Error error;

View File

@@ -1,15 +1,24 @@
#include <mbgl/style/source.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/util/logging.hpp>
namespace mbgl {
namespace style {
Source::Source(SourceType type_, std::unique_ptr<Impl> baseImpl_)
: baseImpl(std::move(baseImpl_)), type(type_) {
static SourceObserver nullObserver;
Source::Source(Immutable<Impl> impl)
: baseImpl(std::move(impl)),
observer(&nullObserver) {
}
Source::~Source() = default;
SourceType Source::getType() const {
return baseImpl->type;
}
const std::string& Source::getID() const {
return baseImpl->id;
}
@@ -18,5 +27,14 @@ optional<std::string> Source::getAttribution() const {
return baseImpl->getAttribution();
}
void Source::setObserver(SourceObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
}
void Source::dumpDebugLogs() const {
Log::Info(Event::General, "Source::id: %s", getID().c_str());
Log::Info(Event::General, "Source::loaded: %d", loaded);
}
} // namespace style
} // namespace mbgl

View File

@@ -1,26 +1,11 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/util/logging.hpp>
namespace mbgl {
namespace style {
static SourceObserver nullObserver;
Source::Impl::Impl(SourceType type_, std::string id_, Source& base_)
Source::Impl::Impl(SourceType type_, std::string id_)
: type(type_),
id(std::move(id_)),
base(base_),
observer(&nullObserver) {
}
void Source::Impl::dumpDebugLogs() const {
Log::Info(Event::General, "Source::id: %s", base.getID().c_str());
Log::Info(Event::General, "Source::loaded: %d", loaded);
}
void Source::Impl::setObserver(SourceObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
id(std::move(id_)) {
}
} // namespace style

View File

@@ -3,35 +3,30 @@
#include <mbgl/style/source.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <string>
namespace mbgl {
class FileSource;
class RenderSource;
namespace style {
class SourceObserver;
class Source::Impl : private util::noncopyable {
class Source::Impl : public EnableImmutableFromThis<Source::Impl> {
public:
Impl(SourceType, std::string id, Source&);
virtual ~Impl() = default;
virtual void loadDescription(FileSource&) = 0;
virtual optional<std::string> getAttribution() const = 0;
virtual std::unique_ptr<RenderSource> createRenderSource() const = 0;
virtual optional<std::string> getAttribution() const { return {}; };
const SourceType type;
const std::string id;
bool loaded = false;
Source& base;
void setObserver(SourceObserver*);
SourceObserver* observer = nullptr;
void dumpDebugLogs() const;
protected:
Impl(SourceType, std::string);
Impl(const Impl&) = default;
Impl& operator=(const Impl&) = delete;
};
} // namespace style

View File

@@ -1,25 +1,80 @@
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/geojson.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/logging.hpp>
namespace mbgl {
namespace style {
GeoJSONSource::GeoJSONSource(const std::string& id, const GeoJSONOptions& options)
: Source(SourceType::GeoJSON,
std::make_unique<GeoJSONSource::Impl>(std::move(id), *this, options)),
impl(static_cast<Impl*>(baseImpl.get())) {
: Source(makeMutable<Impl>(std::move(id), options)) {
}
void GeoJSONSource::setURL(const std::string& url) {
impl->setURL(url);
GeoJSONSource::~GeoJSONSource() = default;
const GeoJSONSource::Impl& GeoJSONSource::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
void GeoJSONSource::setURL(const std::string& url_) {
url = std::move(url_);
// Signal that the source description needs a reload
if (loaded || req) {
loaded = false;
req.reset();
observer->onSourceDescriptionChanged(*this);
}
}
void GeoJSONSource::setGeoJSON(const mapbox::geojson::geojson& geoJSON) {
impl->setGeoJSON(geoJSON);
req.reset();
baseImpl = makeMutable<Impl>(impl(), geoJSON);
}
optional<std::string> GeoJSONSource::getURL() const {
return impl->getURL();
return url;
}
void GeoJSONSource::loadDescription(FileSource& fileSource) {
if (!url) {
loaded = true;
return;
}
if (req) {
return;
}
req = fileSource.request(Resource::source(*url), [this](Response res) {
if (res.error) {
observer->onSourceError(
*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
return;
} else if (res.noContent) {
observer->onSourceError(
*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
} else {
conversion::Error error;
optional<GeoJSON> geoJSON = conversion::convertJSON<GeoJSON>(*res.data, error);
if (!geoJSON) {
Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: %s",
error.message.c_str());
// Create an empty GeoJSON VT object to make sure we're not infinitely waiting for
// tiles to load.
baseImpl = makeMutable<Impl>(impl(), GeoJSON{ FeatureCollection{} });
} else {
baseImpl = makeMutable<Impl>(impl(), *geoJSON);
}
loaded = true;
observer->onSourceLoaded(*this);
}
});
}
} // namespace style

View File

@@ -1,12 +1,6 @@
#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/geojson.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/renderer/sources/render_geojson_source.hpp>
#include <mbgl/util/constants.cpp>
#include <mbgl/util/logging.hpp>
#include <mapbox/geojsonvt.hpp>
#include <supercluster.hpp>
@@ -42,33 +36,14 @@ private:
mapbox::supercluster::Supercluster impl;
};
GeoJSONSource::Impl::Impl(std::string id_, Source& base_, const GeoJSONOptions options_)
: Source::Impl(SourceType::GeoJSON, std::move(id_), base_), options(options_) {
GeoJSONSource::Impl::Impl(std::string id_, GeoJSONOptions options_)
: Source::Impl(SourceType::GeoJSON, std::move(id_)),
options(std::move(options_)) {
}
GeoJSONSource::Impl::~Impl() = default;
void GeoJSONSource::Impl::setURL(std::string url_) {
url = std::move(url_);
// Signal that the source description needs a reload
if (loaded || req) {
loaded = false;
req.reset();
observer->onSourceDescriptionChanged(base);
}
}
optional<std::string> GeoJSONSource::Impl::getURL() const {
return url;
}
void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) {
req.reset();
_setGeoJSON(geoJSON);
}
void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) {
GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON)
: Source::Impl(other),
options(other.options) {
double scale = util::EXTENT / util::tileSize;
if (options.cluster
@@ -90,47 +65,7 @@ void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) {
}
}
void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) {
if (!url) {
loaded = true;
return;
}
if (req) {
return;
}
req = fileSource.request(Resource::source(*url), [this](Response res) {
if (res.error) {
observer->onSourceError(
base, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
return;
} else if (res.noContent) {
observer->onSourceError(
base, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
} else {
conversion::Error error;
optional<GeoJSON> geoJSON = conversion::convertJSON<GeoJSON>(*res.data, error);
if (!geoJSON) {
Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: %s",
error.message.c_str());
// Create an empty GeoJSON VT object to make sure we're not infinitely waiting for
// tiles to load.
_setGeoJSON(GeoJSON{ FeatureCollection{} });
} else {
_setGeoJSON(*geoJSON);
}
loaded = true;
observer->onSourceLoaded(base);
}
});
}
std::unique_ptr<RenderSource> GeoJSONSource::Impl::createRenderSource() const {
return std::make_unique<RenderGeoJSONSource>(*this);
}
GeoJSONSource::Impl::~Impl() = default;
Range<uint8_t> GeoJSONSource::Impl::getZoomRange() const {
return { 0, options.maxzoom };
@@ -140,5 +75,13 @@ GeoJSONData* GeoJSONSource::Impl::getData() const {
return data.get();
}
optional<std::string> GeoJSONSource::Impl::getAttribution() const {
return {};
}
std::unique_ptr<RenderSource> GeoJSONSource::Impl::createRenderSource() const {
return std::make_unique<RenderGeoJSONSource>(staticImmutableCast<GeoJSONSource::Impl>(immutableFromThis()));
}
} // namespace style
} // namespace mbgl

Some files were not shown because too many files have changed in this diff Show More