summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/style/source.hpp63
-rw-r--r--include/mbgl/style/sources/geojson_source.hpp27
-rw-r--r--include/mbgl/style/sources/raster_source.hpp20
-rw-r--r--include/mbgl/style/sources/vector_source.hpp20
-rw-r--r--include/mbgl/util/tileset.hpp (renamed from src/mbgl/util/tileset.hpp)0
-rw-r--r--platform/default/mbgl/storage/offline_download.cpp28
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp2
-rw-r--r--src/mbgl/annotation/annotation_source.cpp18
-rw-r--r--src/mbgl/annotation/annotation_source.hpp8
-rw-r--r--src/mbgl/annotation/annotation_tile.cpp3
-rw-r--r--src/mbgl/annotation/annotation_tile.hpp3
-rw-r--r--src/mbgl/renderer/painter.cpp5
-rw-r--r--src/mbgl/style/parser.cpp12
-rw-r--r--src/mbgl/style/source_impl.cpp (renamed from src/mbgl/style/source.cpp)43
-rw-r--r--src/mbgl/style/source_impl.hpp (renamed from src/mbgl/style/source.hpp)9
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp (renamed from src/mbgl/style/sources/geojson_source.cpp)36
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.hpp (renamed from src/mbgl/style/sources/geojson_source.hpp)10
-rw-r--r--src/mbgl/style/sources/raster_source_impl.cpp (renamed from src/mbgl/style/sources/raster_source.cpp)16
-rw-r--r--src/mbgl/style/sources/raster_source_impl.hpp (renamed from src/mbgl/style/sources/raster_source.hpp)7
-rw-r--r--src/mbgl/style/sources/vector_source.cpp25
-rw-r--r--src/mbgl/style/sources/vector_source_impl.cpp25
-rw-r--r--src/mbgl/style/sources/vector_source_impl.hpp (renamed from src/mbgl/style/sources/vector_source.hpp)7
-rw-r--r--src/mbgl/style/style.cpp36
-rw-r--r--src/mbgl/style/tile_source_impl.cpp (renamed from src/mbgl/style/tile_source.cpp)29
-rw-r--r--src/mbgl/style/tile_source_impl.hpp (renamed from src/mbgl/style/tile_source.hpp)13
-rw-r--r--test/style/source.cpp73
-rw-r--r--test/style/style.cpp10
-rw-r--r--test/style/tile_source.cpp10
28 files changed, 356 insertions, 202 deletions
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 <mbgl/util/noncopyable.hpp>
+#include <mbgl/style/types.hpp>
+
+#include <memory>
+#include <string>
+
+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<VectorSource>("my-vector-source");
+ */
+class Source : public mbgl::util::noncopyable {
+public:
+ virtual ~Source();
+
+ // Check whether this source is of the given subtype.
+ template <class T>
+ bool is() const;
+
+ // Dynamically cast this source 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;
+
+ // Create a new source with the specified `id`. All other properties
+ // are copied from this source.
+ std::unique_ptr<Source> copy(const std::string& id) const;
+
+ // Private implementation
+ class Impl;
+ const std::unique_ptr<Impl> baseImpl;
+
+protected:
+ const SourceType type;
+ Source(SourceType, std::unique_ptr<Impl>);
+};
+
+} // 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 <mbgl/style/source.hpp>
+
+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 <class Fn>
+ 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 <mbgl/style/source.hpp>
+#include <mbgl/util/tileset.hpp>
+#include <mbgl/util/variant.hpp>
+
+namespace mbgl {
+namespace style {
+
+class RasterSource : public Source {
+public:
+ RasterSource(std::string id, variant<std::string, Tileset> 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 <mbgl/style/source.hpp>
+#include <mbgl/util/tileset.hpp>
+#include <mbgl/util/variant.hpp>
+
+namespace mbgl {
+namespace style {
+
+class VectorSource : public Source {
+public:
+ VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset);
+
+ // Private implementation
+
+ class Impl;
+};
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/util/tileset.hpp b/include/mbgl/util/tileset.hpp
index 8a7fbe9b73..8a7fbe9b73 100644
--- a/src/mbgl/util/tileset.hpp
+++ b/include/mbgl/util/tileset.hpp
diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp
index 3f21b8571e..2aaeb30fab 100644
--- a/platform/default/mbgl/storage/offline_download.cpp
+++ b/platform/default/mbgl/storage/offline_download.cpp
@@ -4,8 +4,8 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/style/parser.hpp>
-#include <mbgl/style/tile_source.hpp>
-#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/util/tile_cover.hpp>
#include <mbgl/util/mapbox.hpp>
@@ -103,21 +103,21 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
result.requiredResourceCountIsPrecise = true;
for (const auto& source : parser.sources) {
- switch (source->type) {
+ switch (source->baseImpl->type) {
case SourceType::Vector:
case SourceType::Raster: {
- style::TileSource* tileSource = static_cast<style::TileSource*>(source.get());
+ style::TileSourceImpl* tileSource = static_cast<style::TileSourceImpl*>(source->baseImpl.get());
const variant<std::string, Tileset>& urlOrTileset = tileSource->getURLOrTileset();
if (urlOrTileset.is<Tileset>()) {
- result.requiredResourceCount += tileResources(source->type, tileSource->getTileSize(), urlOrTileset.get<Tileset>()).size();
+ result.requiredResourceCount += tileResources(source->baseImpl->type, tileSource->getTileSize(), urlOrTileset.get<Tileset>()).size();
} else {
result.requiredResourceCount += 1;
const std::string& url = urlOrTileset.get<std::string>();
optional<Response> sourceResponse = offlineDatabase.get(Resource::source(url));
if (sourceResponse) {
- result.requiredResourceCount += tileResources(source->type, tileSource->getTileSize(),
- style::TileSource::parseTileJSON(*sourceResponse->data, url, source->type, tileSource->getTileSize())).size();
+ result.requiredResourceCount += tileResources(source->baseImpl->type, tileSource->getTileSize(),
+ style::TileSourceImpl::parseTileJSON(*sourceResponse->data, url, source->baseImpl->type, tileSource->getTileSize())).size();
} else {
result.requiredResourceCountIsPrecise = false;
}
@@ -126,8 +126,8 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
}
case SourceType::GeoJSON: {
- style::GeoJSONSource* geojsonSource = static_cast<style::GeoJSONSource*>(source.get());
- const variant<std::string, style::GeoJSONSource::GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
+ style::GeoJSONSource::Impl* geojsonSource = static_cast<style::GeoJSONSource::Impl*>(source->baseImpl.get());
+ const variant<std::string, style::GeoJSONSource::Impl::GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
if (urlOrGeoJSON.is<std::string>()) {
result.requiredResourceCount += 1;
@@ -160,12 +160,12 @@ void OfflineDownload::activateDownload() {
parser.parse(*styleResponse.data);
for (const auto& source : parser.sources) {
- SourceType type = source->type;
+ SourceType type = source->baseImpl->type;
switch (type) {
case SourceType::Vector:
case SourceType::Raster: {
- const style::TileSource* tileSource = static_cast<style::TileSource*>(source.get());
+ const style::TileSourceImpl* tileSource = static_cast<style::TileSourceImpl*>(source->baseImpl.get());
const variant<std::string, Tileset>& urlOrTileset = tileSource->getURLOrTileset();
const uint16_t tileSize = tileSource->getTileSize();
@@ -177,7 +177,7 @@ void OfflineDownload::activateDownload() {
requiredSourceURLs.insert(url);
ensureResource(Resource::source(url), [=] (Response sourceResponse) {
- ensureTiles(type, tileSize, style::TileSource::parseTileJSON(*sourceResponse.data, url, type, tileSize));
+ ensureTiles(type, tileSize, style::TileSourceImpl::parseTileJSON(*sourceResponse.data, url, type, tileSize));
requiredSourceURLs.erase(url);
if (requiredSourceURLs.empty()) {
@@ -189,8 +189,8 @@ void OfflineDownload::activateDownload() {
}
case SourceType::GeoJSON: {
- style::GeoJSONSource* geojsonSource = static_cast<style::GeoJSONSource*>(source.get());
- const variant<std::string, style::GeoJSONSource::GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
+ style::GeoJSONSource::Impl* geojsonSource = static_cast<style::GeoJSONSource::Impl*>(source->baseImpl.get());
+ const variant<std::string, style::GeoJSONSource::Impl::GeoJSON>& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON();
if (urlOrGeoJSON.is<std::string>()) {
ensureResource(Resource::source(urlOrGeoJSON.get<std::string>()));
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index b3edbf857d..e3c6cc56d4 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -108,7 +108,7 @@ void AnnotationManager::updateStyle(Style& style) {
// Create annotation source, point layer, and point bucket
if (!style.getSource(SourceID)) {
std::unique_ptr<Source> source = std::make_unique<AnnotationSource>();
- source->enabled = true;
+ source->baseImpl->enabled = true;
style.addSource(std::move(source));
std::unique_ptr<SymbolLayer> layer = std::make_unique<SymbolLayer>(PointLayerID);
diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp
index 2c87c4f207..61fc4ca2e4 100644
--- a/src/mbgl/annotation/annotation_source.cpp
+++ b/src/mbgl/annotation/annotation_source.cpp
@@ -4,21 +4,27 @@
namespace mbgl {
+using namespace style;
+
AnnotationSource::AnnotationSource()
- : Source(SourceType::Annotations, AnnotationManager::SourceID) {
+ : Source(SourceType::Annotations, std::make_unique<Impl>(*this)) {
+}
+
+AnnotationSource::Impl::Impl(Source& base_)
+ : Source::Impl(SourceType::Annotations, AnnotationManager::SourceID, base_) {
}
-Range<uint8_t> AnnotationSource::getZoomRange() {
+Range<uint8_t> AnnotationSource::Impl::getZoomRange() {
return { 0, 22 };
}
-void AnnotationSource::load(FileSource&) {
+void AnnotationSource::Impl::load(FileSource&) {
loaded = true;
}
-std::unique_ptr<Tile> AnnotationSource::createTile(const OverscaledTileID& tileID,
- const style::UpdateParameters& parameters) {
- return std::make_unique<AnnotationTile>(tileID, id, parameters);
+std::unique_ptr<Tile> AnnotationSource::Impl::createTile(const OverscaledTileID& tileID,
+ const style::UpdateParameters& parameters) {
+ return std::make_unique<AnnotationTile>(tileID, parameters);
}
} // namespace mbgl
diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp
index e8d3b43e09..db9221788f 100644
--- a/src/mbgl/annotation/annotation_source.hpp
+++ b/src/mbgl/annotation/annotation_source.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
namespace mbgl {
@@ -8,6 +9,13 @@ class AnnotationSource : public style::Source {
public:
AnnotationSource();
+ class Impl;
+};
+
+class AnnotationSource::Impl : public style::Source::Impl {
+public:
+ Impl(Source&);
+
void load(FileSource&) final;
private:
diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp
index 79e281acce..91b7f7ddc1 100644
--- a/src/mbgl/annotation/annotation_tile.cpp
+++ b/src/mbgl/annotation/annotation_tile.cpp
@@ -9,9 +9,8 @@
namespace mbgl {
AnnotationTile::AnnotationTile(const OverscaledTileID& overscaledTileID,
- std::string sourceID,
const style::UpdateParameters& parameters)
- : GeometryTile(overscaledTileID, sourceID, parameters.style, parameters.mode),
+ : GeometryTile(overscaledTileID, AnnotationManager::SourceID, parameters.style, parameters.mode),
annotationManager(parameters.annotationManager) {
annotationManager.addTile(*this);
}
diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp
index 290df3537e..3e7c2c447f 100644
--- a/src/mbgl/annotation/annotation_tile.hpp
+++ b/src/mbgl/annotation/annotation_tile.hpp
@@ -14,8 +14,7 @@ class UpdateParameters;
class AnnotationTile : public GeometryTile {
public:
AnnotationTile(const OverscaledTileID&,
- std::string sourceID,
- const style::UpdateParameters&);
+ const style::UpdateParameters&);
~AnnotationTile() override;
void setNecessity(Necessity) final;
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index eee568ec92..ca536f6671 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -2,6 +2,7 @@
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/gl/debugging.hpp>
@@ -161,7 +162,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
// Update all clipping IDs.
algorithm::ClipIDGenerator generator;
for (const auto& source : sources) {
- source->startRender(generator, projMatrix, state);
+ source->baseImpl->startRender(generator, projMatrix, state);
}
drawClippingMasks(generator.getStencils());
@@ -202,7 +203,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
// When only rendering layers via the stylesheet, it's possible that we don't
// ever visit a tile during rendering.
for (const auto& source : sources) {
- source->finishRender(*this);
+ source->baseImpl->finishRender(*this);
}
}
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index 09689f22f1..34f01c14c1 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -1,7 +1,7 @@
#include <mbgl/style/parser.hpp>
-#include <mbgl/style/sources/raster_source.hpp>
-#include <mbgl/style/sources/vector_source.hpp>
-#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/sources/raster_source_impl.hpp>
+#include <mbgl/style/sources/vector_source_impl.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
@@ -99,16 +99,16 @@ void Parser::parseSources(const JSValue& value) {
switch (*type) {
case SourceType::Raster: {
- source = RasterSource::parse(id, sourceVal);
+ source = RasterSource::Impl::parse(id, sourceVal);
break;
}
case SourceType::Vector:
- source = VectorSource::parse(id, sourceVal);
+ source = VectorSource::Impl::parse(id, sourceVal);
break;
case SourceType::GeoJSON:
- source = GeoJSONSource::parse(id, sourceVal);
+ source = GeoJSONSource::Impl::parse(id, sourceVal);
break;
default:
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source_impl.cpp
index 5f4949c94c..4223f2b50d 100644
--- a/src/mbgl/style/source.cpp
+++ b/src/mbgl/style/source_impl.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/renderer/render_tile.hpp>
@@ -23,15 +23,16 @@ namespace style {
static SourceObserver nullObserver;
-Source::Source(SourceType type_, std::string id_)
+Source::Impl::Impl(SourceType type_, std::string id_, Source& base_)
: type(type_),
id(std::move(id_)),
+ base(base_),
observer(&nullObserver) {
}
-Source::~Source() = default;
+Source::Impl::~Impl() = default;
-bool Source::isLoaded() const {
+bool Source::Impl::isLoaded() const {
if (!loaded) return false;
for (const auto& pair : tiles) {
@@ -43,13 +44,13 @@ bool Source::isLoaded() const {
return true;
}
-void Source::invalidateTiles() {
+void Source::Impl::invalidateTiles() {
tiles.clear();
renderTiles.clear();
cache.clear();
}
-void Source::startRender(algorithm::ClipIDGenerator& generator,
+void Source::Impl::startRender(algorithm::ClipIDGenerator& generator,
const mat4& projMatrix,
const TransformState& transform) {
if (type == SourceType::Vector ||
@@ -65,18 +66,18 @@ void Source::startRender(algorithm::ClipIDGenerator& generator,
}
}
-void Source::finishRender(Painter& painter) {
+void Source::Impl::finishRender(Painter& painter) {
for (auto& pair : renderTiles) {
auto& tile = pair.second;
painter.renderTileDebug(tile);
}
}
-const std::map<UnwrappedTileID, RenderTile>& Source::getRenderTiles() const {
+const std::map<UnwrappedTileID, RenderTile>& Source::Impl::getRenderTiles() const {
return renderTiles;
}
-Tile* Source::getTile(const OverscaledTileID& overscaledTileID) const {
+Tile* Source::Impl::getTile(const OverscaledTileID& overscaledTileID) const {
auto it = tiles.find(overscaledTileID);
if (it != tiles.end()) {
return it->second.get();
@@ -85,7 +86,7 @@ Tile* Source::getTile(const OverscaledTileID& overscaledTileID) const {
}
}
-bool Source::update(const UpdateParameters& parameters) {
+bool Source::Impl::update(const UpdateParameters& parameters) {
bool allTilesUpdated = true;
if (!loaded || parameters.animationTime <= updated) {
@@ -205,7 +206,7 @@ static Point<int16_t> coordinateToTilePoint(const UnwrappedTileID& tileID, const
};
}
-std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatures(const QueryParameters& parameters) const {
+std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRenderedFeatures(const QueryParameters& parameters) const {
LineString<double> queryGeometry;
for (const auto& p : parameters.geometry) {
@@ -241,32 +242,32 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
return result;
}
-void Source::setCacheSize(size_t size) {
+void Source::Impl::setCacheSize(size_t size) {
cache.setSize(size);
}
-void Source::onLowMemory() {
+void Source::Impl::onLowMemory() {
cache.clear();
}
-void Source::setObserver(SourceObserver* observer_) {
+void Source::Impl::setObserver(SourceObserver* observer_) {
observer = observer_;
}
-void Source::onTileLoaded(Tile& tile, bool isNewTile) {
- observer->onTileLoaded(*this, tile.id, isNewTile);
+void Source::Impl::onTileLoaded(Tile& tile, bool isNewTile) {
+ observer->onTileLoaded(base, tile.id, isNewTile);
}
-void Source::onTileError(Tile& tile, std::exception_ptr error) {
- observer->onTileError(*this, tile.id, error);
+void Source::Impl::onTileError(Tile& tile, std::exception_ptr error) {
+ observer->onTileError(base, tile.id, error);
}
-void Source::onNeedsRepaint() {
+void Source::Impl::onNeedsRepaint() {
observer->onNeedsRepaint();
}
-void Source::dumpDebugLogs() const {
- Log::Info(Event::General, "Source::id: %s", id.c_str());
+void Source::Impl::dumpDebugLogs() const {
+ Log::Info(Event::General, "Source::id: %s", base.getID().c_str());
Log::Info(Event::General, "Source::loaded: %d", loaded);
for (const auto& pair : tiles) {
diff --git a/src/mbgl/style/source.hpp b/src/mbgl/style/source_impl.hpp
index 5c1a813562..64651d7e3f 100644
--- a/src/mbgl/style/source.hpp
+++ b/src/mbgl/style/source_impl.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <mbgl/style/source.hpp>
+
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/tile/tile.hpp>
@@ -33,10 +35,10 @@ class UpdateParameters;
class QueryParameters;
class SourceObserver;
-class Source : public TileObserver, private util::noncopyable {
+class Source::Impl : public TileObserver, private util::noncopyable {
public:
- Source(SourceType, std::string id);
- ~Source() override;
+ Impl(SourceType, std::string id, Source&);
+ ~Impl() override;
virtual void load(FileSource&) = 0;
bool isLoaded() const;
@@ -74,6 +76,7 @@ public:
protected:
void invalidateTiles();
+ Source& base;
SourceObserver* observer = nullptr;
private:
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index e06b00ec99..f58e0fc62b 100644
--- a/src/mbgl/style/sources/geojson_source.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/parser.hpp>
#include <mbgl/tile/geojson_tile.hpp>
@@ -15,7 +15,7 @@
namespace mbgl {
namespace style {
-std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> GeoJSONSource::parseGeoJSON(const JSValue& value) {
+std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> GeoJSONSource::Impl::parseGeoJSON(const JSValue& value) {
using namespace mapbox::geojsonvt;
Options options;
@@ -32,7 +32,7 @@ std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> GeoJSONSource::parseGeoJSON(const
}
}
-std::unique_ptr<GeoJSONSource> GeoJSONSource::parse(const std::string& id, const JSValue& value) {
+std::unique_ptr<GeoJSONSource> GeoJSONSource::Impl::parse(const std::string& id, const JSValue& value) {
// We should probably split this up to have URLs in the url property, and actual data
// in the data property. Until then, we're going to detect the content based on the
// object type.
@@ -43,23 +43,27 @@ std::unique_ptr<GeoJSONSource> GeoJSONSource::parse(const std::string& id, const
const JSValue& dataVal = value["data"];
if (dataVal.IsString()) {
- return std::make_unique<GeoJSONSource>(id, std::string(dataVal.GetString(), dataVal.GetStringLength()));
+ return std::make_unique<GeoJSONSource>([&] (Source& base) {
+ return std::make_unique<Impl>(id, base, std::string(dataVal.GetString(), dataVal.GetStringLength()));
+ });
} else if (dataVal.IsObject()) {
- return std::make_unique<GeoJSONSource>(id, parseGeoJSON(dataVal));
+ return std::make_unique<GeoJSONSource>([&] (Source& base) {
+ return std::make_unique<Impl>(id, base, parseGeoJSON(dataVal));
+ });
} else {
Log::Error(Event::ParseStyle, "GeoJSON data must be a URL or an object");
return nullptr;
}
}
-GeoJSONSource::GeoJSONSource(std::string id_, variant<std::string, GeoJSON> urlOrGeoJSON_)
- : Source(SourceType::GeoJSON, std::move(id_)),
+GeoJSONSource::Impl::Impl(std::string id_, Source& base_, variant<std::string, GeoJSON> urlOrGeoJSON_)
+ : Source::Impl(SourceType::GeoJSON, std::move(id_), base_),
urlOrGeoJSON(std::move(urlOrGeoJSON_)) {
}
-GeoJSONSource::~GeoJSONSource() = default;
+GeoJSONSource::Impl::~Impl() = default;
-void GeoJSONSource::load(FileSource& fileSource) {
+void GeoJSONSource::Impl::load(FileSource& fileSource) {
if (urlOrGeoJSON.is<GeoJSON>()) {
loaded = true;
return;
@@ -72,11 +76,11 @@ void GeoJSONSource::load(FileSource& fileSource) {
const std::string& url = urlOrGeoJSON.get<std::string>();
req = fileSource.request(Resource::source(url), [this](Response res) {
if (res.error) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
return;
} else if (res.noContent) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
} else {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
d.Parse<0>(res.data->c_str());
@@ -84,7 +88,7 @@ void GeoJSONSource::load(FileSource& fileSource) {
if (d.HasParseError()) {
std::stringstream message;
message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(message.str())));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error(message.str())));
return;
}
@@ -93,20 +97,20 @@ void GeoJSONSource::load(FileSource& fileSource) {
urlOrGeoJSON = parseGeoJSON(d);
loaded = true;
- observer->onSourceLoaded(*this);
+ observer->onSourceLoaded(base);
}
});
}
-Range<uint8_t> GeoJSONSource::getZoomRange() {
+Range<uint8_t> GeoJSONSource::Impl::getZoomRange() {
assert(loaded);
return { 0, urlOrGeoJSON.get<GeoJSON>()->options.maxZoom };
}
-std::unique_ptr<Tile> GeoJSONSource::createTile(const OverscaledTileID& tileID,
+std::unique_ptr<Tile> GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID,
const UpdateParameters& parameters) {
assert(loaded);
- return std::make_unique<GeoJSONTile>(tileID, id, parameters, *urlOrGeoJSON.get<GeoJSON>());
+ return std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters, *urlOrGeoJSON.get<GeoJSON>());
}
} // namespace style
diff --git a/src/mbgl/style/sources/geojson_source.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp
index 490dae48b8..350045b27c 100644
--- a/src/mbgl/style/sources/geojson_source.hpp
+++ b/src/mbgl/style/sources/geojson_source_impl.hpp
@@ -1,6 +1,7 @@
#pragma once
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/util/variant.hpp>
@@ -16,15 +17,16 @@ class AsyncRequest;
namespace style {
-class GeoJSONSource : public Source {
+class GeoJSONSource::Impl : public Source::Impl {
public:
using GeoJSON = std::unique_ptr<mapbox::geojsonvt::GeoJSONVT>;
static std::unique_ptr<GeoJSONSource> parse(const std::string& id, const JSValue&);
static GeoJSON parseGeoJSON(const JSValue&);
- GeoJSONSource(std::string id, variant<std::string, GeoJSON> urlOrGeoJSON);
- ~GeoJSONSource() final;
+ Impl(std::string id, Source&,
+ variant<std::string, GeoJSON> urlOrGeoJSON);
+ ~Impl() final;
void load(FileSource&) final;
diff --git a/src/mbgl/style/sources/raster_source.cpp b/src/mbgl/style/sources/raster_source_impl.cpp
index 9f873a3065..a6e19b4757 100644
--- a/src/mbgl/style/sources/raster_source.cpp
+++ b/src/mbgl/style/sources/raster_source_impl.cpp
@@ -1,12 +1,12 @@
-#include <mbgl/style/sources/raster_source.hpp>
+#include <mbgl/style/sources/raster_source_impl.hpp>
#include <mbgl/tile/raster_tile.hpp>
#include <mbgl/platform/log.hpp>
namespace mbgl {
namespace style {
-std::unique_ptr<RasterSource> RasterSource::parse(std::string id, const JSValue& value) {
- optional<variant<std::string, Tileset>> urlOrTileset = TileSource::parseURLOrTileset(value);
+std::unique_ptr<RasterSource> RasterSource::Impl::parse(std::string id, const JSValue& value) {
+ optional<variant<std::string, Tileset>> urlOrTileset = TileSourceImpl::parseURLOrTileset(value);
if (!urlOrTileset) {
return nullptr;
}
@@ -25,13 +25,13 @@ std::unique_ptr<RasterSource> RasterSource::parse(std::string id, const JSValue&
return std::make_unique<RasterSource>(std::move(id), std::move(*urlOrTileset), tileSize);
}
-RasterSource::RasterSource(std::string id_,
- variant<std::string, Tileset> urlOrTileset_,
- uint16_t tileSize_)
- : TileSource(SourceType::Raster, std::move(id_), std::move(urlOrTileset_), tileSize_) {
+RasterSource::Impl::Impl(std::string id_, Source& base_,
+ variant<std::string, Tileset> urlOrTileset_,
+ uint16_t tileSize_)
+ : TileSourceImpl(SourceType::Raster, std::move(id_), base_, std::move(urlOrTileset_), tileSize_) {
}
-std::unique_ptr<Tile> RasterSource::createTile(const OverscaledTileID& tileID,
+std::unique_ptr<Tile> RasterSource::Impl::createTile(const OverscaledTileID& tileID,
const UpdateParameters& parameters) {
return std::make_unique<RasterTile>(tileID, parameters, tileset);
}
diff --git a/src/mbgl/style/sources/raster_source.hpp b/src/mbgl/style/sources/raster_source_impl.hpp
index 27b2276df5..2222b13082 100644
--- a/src/mbgl/style/sources/raster_source.hpp
+++ b/src/mbgl/style/sources/raster_source_impl.hpp
@@ -1,15 +1,16 @@
#pragma once
-#include <mbgl/style/tile_source.hpp>
+#include <mbgl/style/sources/raster_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
namespace mbgl {
namespace style {
-class RasterSource : public TileSource {
+class RasterSource::Impl : public TileSourceImpl {
public:
static std::unique_ptr<RasterSource> parse(std::string id, const JSValue&);
- RasterSource(std::string id, variant<std::string, Tileset>, uint16_t tileSize);
+ Impl(std::string id, Source&, variant<std::string, Tileset>, uint16_t tileSize);
private:
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp
deleted file mode 100644
index 3f8f840b38..0000000000
--- a/src/mbgl/style/sources/vector_source.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <mbgl/style/sources/vector_source.hpp>
-#include <mbgl/tile/vector_tile.hpp>
-
-namespace mbgl {
-namespace style {
-
-std::unique_ptr<VectorSource> VectorSource::parse(std::string id, const JSValue& value) {
- optional<variant<std::string, Tileset>> urlOrTileset = TileSource::parseURLOrTileset(value);
- if (!urlOrTileset) {
- return nullptr;
- }
- return std::make_unique<VectorSource>(std::move(id), std::move(*urlOrTileset));
-}
-
-VectorSource::VectorSource(std::string id_, variant<std::string, Tileset> urlOrTileset_)
- : TileSource(SourceType::Vector, std::move(id_), std::move(urlOrTileset_), util::tileSize) {
-}
-
-std::unique_ptr<Tile> VectorSource::createTile(const OverscaledTileID& tileID,
- const UpdateParameters& parameters) {
- return std::make_unique<VectorTile>(tileID, id, parameters, tileset);
-}
-
-} // namespace style
-} // namespace mbgl
diff --git a/src/mbgl/style/sources/vector_source_impl.cpp b/src/mbgl/style/sources/vector_source_impl.cpp
new file mode 100644
index 0000000000..28e14f3e16
--- /dev/null
+++ b/src/mbgl/style/sources/vector_source_impl.cpp
@@ -0,0 +1,25 @@
+#include <mbgl/style/sources/vector_source_impl.hpp>
+#include <mbgl/tile/vector_tile.hpp>
+
+namespace mbgl {
+namespace style {
+
+std::unique_ptr<VectorSource> VectorSource::Impl::parse(std::string id, const JSValue& value) {
+ optional<variant<std::string, Tileset>> urlOrTileset = TileSourceImpl::parseURLOrTileset(value);
+ if (!urlOrTileset) {
+ return nullptr;
+ }
+ return std::make_unique<VectorSource>(std::move(id), std::move(*urlOrTileset));
+}
+
+VectorSource::Impl::Impl(std::string id_, Source& base_, variant<std::string, Tileset> urlOrTileset_)
+ : TileSourceImpl(SourceType::Vector, std::move(id_), base_, std::move(urlOrTileset_), util::tileSize) {
+}
+
+std::unique_ptr<Tile> VectorSource::Impl::createTile(const OverscaledTileID& tileID,
+ const UpdateParameters& parameters) {
+ return std::make_unique<VectorTile>(tileID, base.getID(), parameters, tileset);
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/sources/vector_source.hpp b/src/mbgl/style/sources/vector_source_impl.hpp
index ced7d80471..4a6703e5c0 100644
--- a/src/mbgl/style/sources/vector_source.hpp
+++ b/src/mbgl/style/sources/vector_source_impl.hpp
@@ -1,15 +1,16 @@
#pragma once
-#include <mbgl/style/tile_source.hpp>
+#include <mbgl/style/sources/vector_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
namespace mbgl {
namespace style {
-class VectorSource : public TileSource {
+class VectorSource::Impl : public TileSourceImpl {
public:
static std::unique_ptr<VectorSource> parse(std::string id, const JSValue&);
- VectorSource(std::string id, variant<std::string, Tileset>);
+ Impl(std::string id, Source&, variant<std::string, Tileset>);
private:
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index af19c41393..a75133f82d 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -1,6 +1,6 @@
#include <mbgl/style/style.hpp>
#include <mbgl/style/observer.hpp>
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/style/layers/custom_layer.hpp>
@@ -47,7 +47,7 @@ Style::Style(FileSource& fileSource_, float pixelRatio)
Style::~Style() {
for (const auto& source : sources) {
- source->setObserver(nullptr);
+ source->baseImpl->setObserver(nullptr);
}
glyphStore->setObserver(nullptr);
@@ -107,7 +107,7 @@ void Style::setJSON(const std::string& json) {
}
void Style::addSource(std::unique_ptr<Source> source) {
- source->setObserver(this);
+ source->baseImpl->setObserver(this);
sources.emplace_back(std::move(source));
}
@@ -156,7 +156,7 @@ void Style::update(const UpdateParameters& parameters) {
bool allTilesUpdated = true;
for (const auto& source : sources) {
- if (!source->update(parameters)) {
+ if (!source->baseImpl->update(parameters)) {
allTilesUpdated = false;
}
}
@@ -195,7 +195,7 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) {
void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
for (const auto& source : sources) {
- source->enabled = false;
+ source->baseImpl->enabled = false;
}
zoomHistory.update(z, timePoint);
@@ -213,9 +213,9 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
Source* source = getSource(layer->baseImpl->source);
if (source && layer->baseImpl->needsRendering()) {
- source->enabled = true;
- if (!source->loaded) {
- source->load(fileSource);
+ source->baseImpl->enabled = true;
+ if (!source->baseImpl->loaded) {
+ source->baseImpl->load(fileSource);
}
}
}
@@ -223,7 +223,7 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
Source* Style::getSource(const std::string& id) const {
const auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) {
- return source->id == id;
+ return source->getID() == id;
});
return it != sources.end() ? it->get() : nullptr;
@@ -239,7 +239,7 @@ bool Style::isLoaded() const {
}
for (const auto& source: sources) {
- if (source->enabled && !source->isLoaded()) return false;
+ if (source->baseImpl->enabled && !source->baseImpl->isLoaded()) return false;
}
if (!spriteStore->isLoaded()) {
@@ -253,7 +253,7 @@ RenderData Style::getRenderData() const {
RenderData result;
for (const auto& source : sources) {
- if (source->enabled) {
+ if (source->baseImpl->enabled) {
result.sources.insert(source.get());
}
}
@@ -285,7 +285,7 @@ RenderData Style::getRenderData() const {
continue;
}
- for (auto& pair : source->getRenderTiles()) {
+ for (auto& pair : source->baseImpl->getRenderTiles()) {
auto& tile = pair.second;
if (!tile.tile.isRenderable()) {
continue;
@@ -324,7 +324,7 @@ std::vector<Feature> Style::queryRenderedFeatures(const QueryParameters& paramet
std::unordered_map<std::string, std::vector<Feature>> resultsByLayer;
for (const auto& source : sources) {
- auto sourceResults = source->queryRenderedFeatures(parameters);
+ auto sourceResults = source->baseImpl->queryRenderedFeatures(parameters);
std::move(sourceResults.begin(), sourceResults.end(), std::inserter(resultsByLayer, resultsByLayer.begin()));
}
@@ -352,13 +352,13 @@ float Style::getQueryRadius() const {
void Style::setSourceTileCacheSize(size_t size) {
for (const auto& source : sources) {
- source->setCacheSize(size);
+ source->baseImpl->setCacheSize(size);
}
}
void Style::onLowMemory() {
for (const auto& source : sources) {
- source->onLowMemory();
+ source->baseImpl->onLowMemory();
}
}
@@ -388,7 +388,7 @@ void Style::onSourceLoaded(Source& source) {
void Style::onSourceError(Source& source, std::exception_ptr error) {
lastError = error;
Log::Error(Event::Style, "Failed to load source %s: %s",
- source.id.c_str(), util::toString(error).c_str());
+ source.getID().c_str(), util::toString(error).c_str());
observer->onSourceError(source, error);
observer->onResourceError(error);
}
@@ -405,7 +405,7 @@ void Style::onTileLoaded(Source& source, const OverscaledTileID& tileID, bool is
void Style::onTileError(Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
lastError = error;
Log::Error(Event::Style, "Failed to load tile %s for source %s: %s",
- util::toString(tileID).c_str(), source.id.c_str(), util::toString(error).c_str());
+ util::toString(tileID).c_str(), source.getID().c_str(), util::toString(error).c_str());
observer->onTileError(source, tileID, error);
observer->onResourceError(error);
}
@@ -429,7 +429,7 @@ void Style::onSpriteError(std::exception_ptr error) {
void Style::dumpDebugLogs() const {
for (const auto& source : sources) {
- source->dumpDebugLogs();
+ source->baseImpl->dumpDebugLogs();
}
spriteStore->dumpDebugLogs();
diff --git a/src/mbgl/style/tile_source.cpp b/src/mbgl/style/tile_source_impl.cpp
index 0824693331..634ef39808 100644
--- a/src/mbgl/style/tile_source.cpp
+++ b/src/mbgl/style/tile_source_impl.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/style/tile_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/parser.hpp>
#include <mbgl/util/tileset.hpp>
@@ -81,7 +81,7 @@ Tileset parseTileJSON(const JSValue& value) {
} // end namespace
-Tileset TileSource::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) {
+Tileset TileSourceImpl::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
document.Parse<0>(json.c_str());
@@ -103,7 +103,7 @@ Tileset TileSource::parseTileJSON(const std::string& json, const std::string& so
return result;
}
-optional<variant<std::string, Tileset>> TileSource::parseURLOrTileset(const JSValue& value) {
+optional<variant<std::string, Tileset>> TileSourceImpl::parseURLOrTileset(const JSValue& value) {
if (!value.HasMember("url")) {
return { mbgl::style::parseTileJSON(value) };
}
@@ -117,18 +117,17 @@ optional<variant<std::string, Tileset>> TileSource::parseURLOrTileset(const JSVa
return { std::string(urlVal.GetString(), urlVal.GetStringLength()) };
}
-TileSource::TileSource(SourceType type_,
- std::string id_,
- variant<std::string, Tileset> urlOrTileset_,
- uint16_t tileSize_)
- : Source(type_, std::move(id_)),
+TileSourceImpl::TileSourceImpl(SourceType type_, std::string id_, Source& base_,
+ variant<std::string, Tileset> urlOrTileset_,
+ uint16_t tileSize_)
+ : Impl(type_, std::move(id_), base_),
urlOrTileset(std::move(urlOrTileset_)),
tileSize(tileSize_) {
}
-TileSource::~TileSource() = default;
+TileSourceImpl::~TileSourceImpl() = default;
-void TileSource::load(FileSource& fileSource) {
+void TileSourceImpl::load(FileSource& fileSource) {
if (urlOrTileset.is<Tileset>()) {
tileset = urlOrTileset.get<Tileset>();
loaded = true;
@@ -142,11 +141,11 @@ void TileSource::load(FileSource& fileSource) {
const std::string& url = urlOrTileset.get<std::string>();
req = fileSource.request(Resource::source(url), [this, url](Response res) {
if (res.error) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
return;
} else if (res.noContent) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON")));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON")));
} else {
Tileset newTileset;
@@ -156,7 +155,7 @@ void TileSource::load(FileSource& fileSource) {
try {
newTileset = parseTileJSON(*res.data, url, type, tileSize);
} catch (...) {
- observer->onSourceError(*this, std::current_exception());
+ observer->onSourceError(base, std::current_exception());
return;
}
@@ -183,12 +182,12 @@ void TileSource::load(FileSource& fileSource) {
tileset = newTileset;
loaded = true;
- observer->onSourceLoaded(*this);
+ observer->onSourceLoaded(base);
}
});
}
-Range<uint8_t> TileSource::getZoomRange() {
+Range<uint8_t> TileSourceImpl::getZoomRange() {
assert(loaded);
return tileset.zoomRange;
}
diff --git a/src/mbgl/style/tile_source.hpp b/src/mbgl/style/tile_source_impl.hpp
index 66d956a6ef..1ceb1188db 100644
--- a/src/mbgl/style/tile_source.hpp
+++ b/src/mbgl/style/tile_source_impl.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/util/tileset.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/optional.hpp>
@@ -16,17 +16,16 @@ namespace style {
Shared implementation for VectorSource and RasterSource. Should eventually
be refactored to use composition rather than inheritance.
*/
-class TileSource : public Source {
+class TileSourceImpl : public Source::Impl {
public:
// A tile source can either specify a URL to TileJSON, or inline TileJSON.
static optional<variant<std::string, Tileset>> parseURLOrTileset(const JSValue&);
static Tileset parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize);
- TileSource(SourceType,
- std::string id,
- variant<std::string, Tileset> urlOrTileset,
- uint16_t tileSize);
- ~TileSource() override;
+ TileSourceImpl(SourceType, std::string id, Source&,
+ variant<std::string, Tileset> urlOrTileset,
+ uint16_t tileSize);
+ ~TileSourceImpl() override;
void load(FileSource&) final;
diff --git a/test/style/source.cpp b/test/style/source.cpp
index 9de208f343..6afa5073d4 100644
--- a/test/style/source.cpp
+++ b/test/style/source.cpp
@@ -2,6 +2,7 @@
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/stub_style_observer.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/raster_source.hpp>
#include <mbgl/style/sources/vector_source.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
@@ -82,14 +83,14 @@ TEST(Source, LoadingFail) {
};
test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
- EXPECT_EQ("source", source.id);
+ EXPECT_EQ("source", source.getID());
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
};
VectorSource source("source", "url");
- source.setObserver(&test.observer);
- source.load(test.fileSource);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
test.run();
}
@@ -105,14 +106,14 @@ TEST(Source, LoadingCorrupt) {
};
test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
- EXPECT_EQ("source", source.id);
+ EXPECT_EQ("source", source.getID());
EXPECT_EQ("0 - Invalid value.", util::toString(error));
test.end();
};
VectorSource source("source", "url");
- source.setObserver(&test.observer);
- source.load(test.fileSource);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
test.run();
}
@@ -127,7 +128,7 @@ TEST(Source, RasterTileEmpty) {
};
test.observer.tileLoaded = [&] (Source& source, const OverscaledTileID&, bool) {
- EXPECT_EQ("source", source.id);
+ EXPECT_EQ("source", source.getID());
test.end();
};
@@ -139,9 +140,9 @@ TEST(Source, RasterTileEmpty) {
tileset.tiles = { "tiles" };
RasterSource source("source", tileset, 512);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
@@ -156,7 +157,7 @@ TEST(Source, VectorTileEmpty) {
};
test.observer.tileLoaded = [&] (Source& source, const OverscaledTileID&, bool) {
- EXPECT_EQ("source", source.id);
+ EXPECT_EQ("source", source.getID());
test.end();
};
@@ -168,9 +169,9 @@ TEST(Source, VectorTileEmpty) {
tileset.tiles = { "tiles" };
VectorSource source("source", tileset);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
@@ -187,7 +188,7 @@ TEST(Source, RasterTileFail) {
};
test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(SourceType::Raster, source.type);
+ EXPECT_EQ(SourceType::Raster, source.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
@@ -197,9 +198,9 @@ TEST(Source, RasterTileFail) {
tileset.tiles = { "tiles" };
RasterSource source("source", tileset, 512);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
@@ -216,7 +217,7 @@ TEST(Source, VectorTileFail) {
};
test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(SourceType::Vector, source.type);
+ EXPECT_EQ(SourceType::Vector, source.baseImpl->type);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ("Failed by the test case", util::toString(error));
test.end();
@@ -226,9 +227,9 @@ TEST(Source, VectorTileFail) {
tileset.tiles = { "tiles" };
VectorSource source("source", tileset);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
@@ -243,7 +244,7 @@ TEST(Source, RasterTileCorrupt) {
};
test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(source.type, SourceType::Raster);
+ EXPECT_EQ(source.baseImpl->type, SourceType::Raster);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_TRUE(bool(error));
// Not asserting on platform-specific error text.
@@ -254,9 +255,9 @@ TEST(Source, RasterTileCorrupt) {
tileset.tiles = { "tiles" };
RasterSource source("source", tileset, 512);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
@@ -271,7 +272,7 @@ TEST(Source, VectorTileCorrupt) {
};
test.observer.tileError = [&] (Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
- EXPECT_EQ(source.type, SourceType::Vector);
+ EXPECT_EQ(source.baseImpl->type, SourceType::Vector);
EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID);
EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
test.end();
@@ -286,9 +287,9 @@ TEST(Source, VectorTileCorrupt) {
tileset.tiles = { "tiles" };
VectorSource source("source", tileset);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
@@ -313,9 +314,9 @@ TEST(Source, RasterTileCancel) {
tileset.tiles = { "tiles" };
RasterSource source("source", tileset, 512);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
@@ -340,9 +341,9 @@ TEST(Source, VectorTileCancel) {
tileset.tiles = { "tiles" };
VectorSource source("source", tileset);
- source.setObserver(&test.observer);
- source.load(test.fileSource);
- source.update(test.updateParameters);
+ source.baseImpl->setObserver(&test.observer);
+ source.baseImpl->load(test.fileSource);
+ source.baseImpl->update(test.updateParameters);
test.run();
}
diff --git a/test/style/style.cpp b/test/style/style.cpp
index d530d9cbdd..1681bac1c9 100644
--- a/test/style/style.cpp
+++ b/test/style/style.cpp
@@ -2,7 +2,7 @@
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/util/io.hpp>
using namespace mbgl;
@@ -22,11 +22,11 @@ TEST(Style, UnusedSource) {
Source *usedSource = style.getSource("usedsource");
EXPECT_TRUE(usedSource);
- EXPECT_TRUE(usedSource->isLoaded());
+ EXPECT_TRUE(usedSource->baseImpl->isLoaded());
Source *unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);
- EXPECT_FALSE(unusedSource->isLoaded());
+ EXPECT_FALSE(unusedSource->baseImpl->isLoaded());
}
TEST(Style, UnusedSourceActiveViaClassUpdate) {
@@ -46,7 +46,7 @@ TEST(Style, UnusedSourceActiveViaClassUpdate) {
Source *unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);
- EXPECT_TRUE(unusedSource->isLoaded());
+ EXPECT_TRUE(unusedSource->baseImpl->isLoaded());
// Style classes should be cleared upon new style load.
style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
@@ -59,5 +59,5 @@ TEST(Style, UnusedSourceActiveViaClassUpdate) {
unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);
- EXPECT_FALSE(unusedSource->isLoaded());
+ EXPECT_FALSE(unusedSource->baseImpl->isLoaded());
}
diff --git a/test/style/tile_source.cpp b/test/style/tile_source.cpp
index e0709e3be1..35d037a049 100644
--- a/test/style/tile_source.cpp
+++ b/test/style/tile_source.cpp
@@ -1,13 +1,13 @@
#include <mbgl/test/util.hpp>
-#include <mbgl/style/tile_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
#include <mbgl/util/io.hpp>
using namespace mbgl;
using namespace mbgl::style;
-TEST(TileSource, ParseTileJSONRaster) {
- auto result = TileSource::parseTileJSON(
+TEST(TileSourceImpl, ParseTileJSONRaster) {
+ auto result = TileSourceImpl::parseTileJSON(
util::read_file("test/fixtures/style_parser/tilejson.raster.json"),
"mapbox://mapbox.satellite",
SourceType::Raster,
@@ -23,8 +23,8 @@ TEST(TileSource, ParseTileJSONRaster) {
#endif
}
-TEST(TileSource, ParseTileJSONVector) {
- auto result = TileSource::parseTileJSON(
+TEST(TileSourceImpl, ParseTileJSONVector) {
+ auto result = TileSourceImpl::parseTileJSON(
util::read_file("test/fixtures/style_parser/tilejson.vector.json"),
"mapbox://mapbox.streets",
SourceType::Vector,