From b4864ca9d5a18dda4476baa31e33fe8547d55b40 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 29 Aug 2016 13:53:55 -0700 Subject: [core] Trigger Source::Impl::reload when a filter or layout property is modified --- include/mbgl/style/layer.hpp | 70 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 15 deletions(-) (limited to 'include/mbgl/style/layer.hpp') diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 1eff9eb3dc..925629a349 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -8,6 +8,14 @@ namespace mbgl { namespace style { +class FillLayer; +class LineLayer; +class CircleLayer; +class SymbolLayer; +class RasterLayer; +class BackgroundLayer; +class CustomLayer; + /** * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style * Specification. @@ -25,6 +33,21 @@ namespace style { * auto circleLayer = std::make_unique("my-circle-layer"); */ class Layer : public mbgl::util::noncopyable { +protected: + enum class Type { + Fill, + Line, + Circle, + Symbol, + Raster, + Background, + Custom, + }; + + class Impl; + const Type type; + Layer(Type, std::unique_ptr); + public: virtual ~Layer(); @@ -43,6 +66,38 @@ public: return is() ? reinterpret_cast(this) : nullptr; } + // Convenience method for dynamic dispatch on the concrete layer type. Using + // method overloading, this allows consolidation of logic common to vector-based + // layers (Fill, Line, Circle, or Symbol). For example: + // + // struct Visitor { + // void operator()(CustomLayer&) { ... } + // void operator()(RasterLayer&) { ... } + // void operator()(BackgroundLayer&) { ... } + // template + // void operator()(VectorLayer&) { ... } + // }; + // + template + auto accept(V&& visitor) { + switch (type) { + case Type::Fill: + return visitor(*as()); + case Type::Line: + return visitor(*as()); + case Type::Circle: + return visitor(*as()); + case Type::Symbol: + return visitor(*as()); + case Type::Raster: + return visitor(*as()); + case Type::Background: + return visitor(*as()); + case Type::Custom: + return visitor(*as()); + } + } + const std::string& getID() const; // Visibility @@ -56,22 +111,7 @@ public: void setMaxZoom(float) const; // Private implementation - class Impl; const std::unique_ptr baseImpl; - -protected: - enum class Type { - Fill, - Line, - Circle, - Symbol, - Raster, - Background, - Custom, - }; - - const Type type; - Layer(Type, std::unique_ptr); }; } // namespace style -- cgit v1.2.1