From 900568cfb0b84a298395f4d84488fd9323552c63 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 14 Jun 2016 16:07:21 -0700 Subject: [core] Runtime source API: private impls --- include/mbgl/style/source.hpp | 63 +++++++++++++++++++++++++++ include/mbgl/style/sources/geojson_source.hpp | 27 ++++++++++++ include/mbgl/style/sources/raster_source.hpp | 20 +++++++++ include/mbgl/style/sources/vector_source.hpp | 20 +++++++++ include/mbgl/util/tileset.hpp | 20 +++++++++ 5 files changed, 150 insertions(+) create mode 100644 include/mbgl/style/source.hpp create mode 100644 include/mbgl/style/sources/geojson_source.hpp create mode 100644 include/mbgl/style/sources/raster_source.hpp create mode 100644 include/mbgl/style/sources/vector_source.hpp create mode 100644 include/mbgl/util/tileset.hpp (limited to 'include/mbgl') diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp new file mode 100644 index 0000000000..92341066b1 --- /dev/null +++ b/include/mbgl/style/source.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include +#include + +#include +#include + +namespace mbgl { +namespace style { + +/** + * The runtime representation of a [source](https://www.mapbox.com/mapbox-gl-style-spec/#sources) from the Mapbox Style + * Specification. + * + * `Source` is an abstract base class; concrete derived classes are provided for each source type. `Source` contains + * functionality that is common to all layer types: + * + * * Runtime type information: type predicates and casting + * * Accessors for properties common to all source types: ID, etc. + * * Cloning and copying + * + * All other functionality lives in the derived classes. To instantiate a source, create an instance of the desired + * type, passing the ID: + * + * auto vectorSource = std::make_unique("my-vector-source"); + */ +class Source : public mbgl::util::noncopyable { +public: + virtual ~Source(); + + // Check whether this source is of the given subtype. + template + bool is() const; + + // Dynamically cast this source 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; + + // Create a new source with the specified `id`. All other properties + // are copied from this source. + std::unique_ptr copy(const std::string& id) const; + + // Private implementation + class Impl; + const std::unique_ptr baseImpl; + +protected: + const SourceType type; + Source(SourceType, std::unique_ptr); +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp new file mode 100644 index 0000000000..96b9a99606 --- /dev/null +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +namespace mbgl { +namespace style { + +class GeoJSONSource : public Source { +public: + // Future public API: + // void setData(FeatureCollection&&); + // void setJSON(const std::string& json); + // void loadData(const std::string& url); + + + // Private implementation + + class Impl; + + template + GeoJSONSource(Fn&& fn) + : Source(SourceType::GeoJSON, fn(*this)) { + } +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/sources/raster_source.hpp b/include/mbgl/style/sources/raster_source.hpp new file mode 100644 index 0000000000..2d1d648eec --- /dev/null +++ b/include/mbgl/style/sources/raster_source.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { + +class RasterSource : public Source { +public: + RasterSource(std::string id, variant urlOrTileset, uint16_t tileSize); + + // Private implementation + + class Impl; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/sources/vector_source.hpp b/include/mbgl/style/sources/vector_source.hpp new file mode 100644 index 0000000000..3d53362734 --- /dev/null +++ b/include/mbgl/style/sources/vector_source.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { + +class VectorSource : public Source { +public: + VectorSource(std::string id, variant urlOrTileset); + + // Private implementation + + class Impl; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/util/tileset.hpp b/include/mbgl/util/tileset.hpp new file mode 100644 index 0000000000..8a7fbe9b73 --- /dev/null +++ b/include/mbgl/util/tileset.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include +#include +#include + +namespace mbgl { + +class Tileset { +public: + std::vector tiles; + Range zoomRange { 0, 22 }; + std::string attribution; + + // TileJSON also includes center, zoom, and bounds, but they are not used by mbgl. +}; + +} // namespace mbgl -- cgit v1.2.1