From a43940afb2208c61b487bfd8729bbde1bd674794 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Apr 2016 13:15:44 -0700 Subject: [core] Runtime style layer API --- include/mbgl/style/layer.hpp | 78 ++++++++++++++++++++++++++++++++++++++++++++ include/mbgl/style/types.hpp | 21 ++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 include/mbgl/style/layer.hpp (limited to 'include/mbgl/style') 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 +#include + +#include + +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("my-circle-layer"); + */ +class Layer : public mbgl::util::noncopyable { +public: + virtual ~Layer(); + + // Check whether this layer is of the given subtype. + template + bool is() const; + + // Dynamically cast this layer to the given subtype. + template + T* as() { + return is() ? reinterpret_cast(this) : nullptr; + } + + template + const T* as() const { + return is() ? reinterpret_cast(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 copy(const std::string& id, + const std::string& ref) 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 mbgl + +#endif diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 9b03ab8a2d..a852a09a14 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace mbgl { @@ -20,6 +21,26 @@ struct FontStackHash { std::size_t operator()(const FontStack&) const; }; +template +class Function { +public: + using Stop = std::pair; + using Stops = std::vector; + + Function(const T& constant) + : stops({{ 0, constant }}) {} + + explicit Function(const Stops& stops_, float base_) + : base(base_), stops(stops_) {} + + float getBase() const { return base; } + const std::vector>& getStops() const { return stops; } + +private: + float base = 1; + std::vector> stops; +}; + // ------------------------------------------------------------------------------------------------- enum class SourceType : uint8_t { -- cgit v1.2.1