summaryrefslogtreecommitdiff
path: root/include/mbgl/style/layer.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-04-25 13:15:44 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-02 14:51:39 -0700
commita43940afb2208c61b487bfd8729bbde1bd674794 (patch)
tree53d192ea899be1d88f99aeef3d1b3255f9cb5104 /include/mbgl/style/layer.hpp
parent27baa34d44f0006c05ba7c417bf11e184b0bd22b (diff)
downloadqtlocation-mapboxgl-a43940afb2208c61b487bfd8729bbde1bd674794.tar.gz
[core] Runtime style layer API
Diffstat (limited to 'include/mbgl/style/layer.hpp')
-rw-r--r--include/mbgl/style/layer.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp
new file mode 100644
index 0000000000..e6c33a9784
--- /dev/null
+++ b/include/mbgl/style/layer.hpp
@@ -0,0 +1,78 @@
+#ifndef MBGL_LAYER
+#define MBGL_LAYER
+
+#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/style/types.hpp>
+
+#include <memory>
+
+namespace mbgl {
+
+/**
+ * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style
+ * Specification.
+ *
+ * `Layer` is an abstract base class; concrete derived classes are provided for each layer type. `Layer` contains
+ * functionality that is common to all layer types:
+ *
+ * * Runtime type information: type predicates and casting
+ * * Accessors for properties common to all layer types: ID, visibility, etc.
+ * * Cloning and copying
+ *
+ * All other functionality lives in the derived classes. To instantiate a layer, create an instance of the desired
+ * type, passing the ID:
+ *
+ * auto circleLayer = std::make_unique<CircleLayer>("my-circle-layer");
+ */
+class Layer : public mbgl::util::noncopyable {
+public:
+ virtual ~Layer();
+
+ // Check whether this layer is of the given subtype.
+ template <class T>
+ bool is() const;
+
+ // Dynamically cast this layer to the given subtype.
+ 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;
+ }
+
+ const std::string& getID() const;
+
+ // Visibility
+ VisibilityType getVisibility() const;
+ void setVisibility(VisibilityType);
+
+ // Create a new layer with the specified `id` and `ref`. All other properties
+ // are copied from this layer.
+ std::unique_ptr<Layer> copy(const std::string& id,
+ const std::string& ref) const;
+
+ // Private implementation
+ class Impl;
+ const std::unique_ptr<Impl> baseImpl;
+
+protected:
+ enum class Type {
+ Fill,
+ Line,
+ Circle,
+ Symbol,
+ Raster,
+ Background,
+ Custom,
+ };
+
+ const Type type;
+ Layer(Type, std::unique_ptr<Impl>);
+};
+
+} // namespace mbgl
+
+#endif