summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mbgl/layer/background_layer.hpp6
-rw-r--r--src/mbgl/layer/circle_layer.hpp6
-rw-r--r--src/mbgl/layer/custom_layer.cpp3
-rw-r--r--src/mbgl/layer/custom_layer.hpp5
-rw-r--r--src/mbgl/layer/fill_layer.hpp6
-rw-r--r--src/mbgl/layer/line_layer.hpp6
-rw-r--r--src/mbgl/layer/raster_layer.hpp6
-rw-r--r--src/mbgl/layer/symbol_layer.hpp6
-rw-r--r--src/mbgl/style/style_layer.hpp27
9 files changed, 66 insertions, 5 deletions
diff --git a/src/mbgl/layer/background_layer.hpp b/src/mbgl/layer/background_layer.hpp
index 063331fade..118bb19053 100644
--- a/src/mbgl/layer/background_layer.hpp
+++ b/src/mbgl/layer/background_layer.hpp
@@ -15,6 +15,7 @@ public:
class BackgroundLayer : public StyleLayer {
public:
+ BackgroundLayer() : StyleLayer(Type::Background) {}
std::unique_ptr<StyleLayer> clone() const override;
void parseLayout(const JSValue&) override {};
@@ -28,6 +29,11 @@ public:
BackgroundPaintProperties paint;
};
+template <>
+inline bool StyleLayer::is<BackgroundLayer>() const {
+ return type == Type::Background;
+}
+
} // namespace mbgl
#endif
diff --git a/src/mbgl/layer/circle_layer.hpp b/src/mbgl/layer/circle_layer.hpp
index 03169ca065..036bf79991 100644
--- a/src/mbgl/layer/circle_layer.hpp
+++ b/src/mbgl/layer/circle_layer.hpp
@@ -22,6 +22,7 @@ public:
class CircleLayer : public StyleLayer {
public:
+ CircleLayer() : StyleLayer(Type::Circle) {}
std::unique_ptr<StyleLayer> clone() const override;
void parseLayout(const JSValue&) override {};
@@ -35,6 +36,11 @@ public:
CirclePaintProperties paint;
};
+template <>
+inline bool StyleLayer::is<CircleLayer>() const {
+ return type == Type::Circle;
+}
+
} // namespace mbgl
#endif
diff --git a/src/mbgl/layer/custom_layer.cpp b/src/mbgl/layer/custom_layer.cpp
index 39742ecad8..0b6de51e67 100644
--- a/src/mbgl/layer/custom_layer.cpp
+++ b/src/mbgl/layer/custom_layer.cpp
@@ -8,7 +8,8 @@ CustomLayer::CustomLayer(const std::string& id_,
CustomLayerInitializeFunction initializeFn_,
CustomLayerRenderFunction renderFn_,
CustomLayerDeinitializeFunction deinitializeFn_,
- void * context_) {
+ void* context_)
+ : StyleLayer(Type::Custom) {
id = id_;
initializeFn = initializeFn_;
renderFn = renderFn_;
diff --git a/src/mbgl/layer/custom_layer.hpp b/src/mbgl/layer/custom_layer.hpp
index 315d158802..b54ac7481e 100644
--- a/src/mbgl/layer/custom_layer.hpp
+++ b/src/mbgl/layer/custom_layer.hpp
@@ -38,6 +38,11 @@ private:
void* context = nullptr;
};
+template <>
+inline bool StyleLayer::is<CustomLayer>() const {
+ return type == Type::Custom;
+}
+
} // namespace mbgl
#endif
diff --git a/src/mbgl/layer/fill_layer.hpp b/src/mbgl/layer/fill_layer.hpp
index ee079a5c8a..3b1c5a84fe 100644
--- a/src/mbgl/layer/fill_layer.hpp
+++ b/src/mbgl/layer/fill_layer.hpp
@@ -19,6 +19,7 @@ public:
class FillLayer : public StyleLayer {
public:
+ FillLayer() : StyleLayer(Type::Fill) {}
std::unique_ptr<StyleLayer> clone() const override;
void parseLayout(const JSValue&) override {};
@@ -32,6 +33,11 @@ public:
FillPaintProperties paint;
};
+template <>
+inline bool StyleLayer::is<FillLayer>() const {
+ return type == Type::Fill;
+}
+
} // namespace mbgl
#endif
diff --git a/src/mbgl/layer/line_layer.hpp b/src/mbgl/layer/line_layer.hpp
index 027f7a9c06..200541c620 100644
--- a/src/mbgl/layer/line_layer.hpp
+++ b/src/mbgl/layer/line_layer.hpp
@@ -38,6 +38,7 @@ public:
class LineLayer : public StyleLayer {
public:
+ LineLayer() : StyleLayer(Type::Line) {}
std::unique_ptr<StyleLayer> clone() const override;
void parseLayout(const JSValue&) override;
@@ -52,6 +53,11 @@ public:
LinePaintProperties paint;
};
+template <>
+inline bool StyleLayer::is<LineLayer>() const {
+ return type == Type::Line;
+}
+
} // namespace mbgl
#endif
diff --git a/src/mbgl/layer/raster_layer.hpp b/src/mbgl/layer/raster_layer.hpp
index bf912bad4a..52c0f0a7ae 100644
--- a/src/mbgl/layer/raster_layer.hpp
+++ b/src/mbgl/layer/raster_layer.hpp
@@ -19,6 +19,7 @@ public:
class RasterLayer : public StyleLayer {
public:
+ RasterLayer() : StyleLayer(Type::Raster) {}
std::unique_ptr<StyleLayer> clone() const override;
void parseLayout(const JSValue&) override {};
@@ -32,6 +33,11 @@ public:
RasterPaintProperties paint;
};
+template <>
+inline bool StyleLayer::is<RasterLayer>() const {
+ return type == Type::Raster;
+}
+
} // namespace mbgl
#endif
diff --git a/src/mbgl/layer/symbol_layer.hpp b/src/mbgl/layer/symbol_layer.hpp
index 7a798433f3..a2b3b0acf9 100644
--- a/src/mbgl/layer/symbol_layer.hpp
+++ b/src/mbgl/layer/symbol_layer.hpp
@@ -84,6 +84,7 @@ public:
class SymbolLayer : public StyleLayer {
public:
+ SymbolLayer() : StyleLayer(Type::Symbol) {}
std::unique_ptr<StyleLayer> clone() const override;
void parseLayout(const JSValue&) override;
@@ -100,6 +101,11 @@ public:
SpriteAtlas* spriteAtlas = nullptr;
};
+template <>
+inline bool StyleLayer::is<SymbolLayer>() const {
+ return type == Type::Symbol;
+}
+
} // namespace mbgl
#endif
diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/style/style_layer.hpp
index 764906576f..fa09ee2e82 100644
--- a/src/mbgl/style/style_layer.hpp
+++ b/src/mbgl/style/style_layer.hpp
@@ -23,11 +23,18 @@ public:
virtual ~StyleLayer() = default;
// Check whether this layer is of the given subtype.
- template <class T> bool is() const { return dynamic_cast<const T*>(this); }
+ template <class T>
+ bool is() const;
// Dynamically cast this layer to the given subtype.
- template <class T> T* as() { return dynamic_cast< T*>(this); }
- template <class T> const T* as() const { return dynamic_cast<const T*>(this); }
+ template <class T>
+ T* as() {
+ return is<T>() ? reinterpret_cast<T*>(this) : nullptr;
+ }
+ template <class T>
+ const T* as() const {
+ return is<T>() ? reinterpret_cast<const T*>(this) : nullptr;
+ }
// Create a copy of this layer.
virtual std::unique_ptr<StyleLayer> clone() const = 0;
@@ -64,10 +71,22 @@ public:
VisibilityType visibility = VisibilityType::Visible;
protected:
- StyleLayer() = default;
+ enum class Type {
+ Fill,
+ Line,
+ Circle,
+ Symbol,
+ Raster,
+ Background,
+ Custom,
+ };
+
+ StyleLayer(Type type_) : type(type_) {}
StyleLayer(const StyleLayer&) = default;
StyleLayer& operator=(const StyleLayer&) = delete;
+ const Type type;
+
// 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;