diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-02-23 17:55:22 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-02-24 15:58:56 +0100 |
commit | 9557cd8d93749b70c16521e15e156d02baa4bda7 (patch) | |
tree | 57918d712861b96c3b2d6df0d7375218b52a3a49 /src/mbgl/style/style_layer.hpp | |
parent | f4bf96162219cb9700d8bdaf6a16da3395e076c8 (diff) | |
download | qtlocation-mapboxgl-9557cd8d93749b70c16521e15e156d02baa4bda7.tar.gz |
[core] use a store enum instead of RTTI
RTTI is pretty slow, in particular in iOS devices
Diffstat (limited to 'src/mbgl/style/style_layer.hpp')
-rw-r--r-- | src/mbgl/style/style_layer.hpp | 27 |
1 files changed, 23 insertions, 4 deletions
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; |