From 900568cfb0b84a298395f4d84488fd9323552c63 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 14 Jun 2016 16:07:21 -0700 Subject: [PATCH] [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 +++++ {src => include}/mbgl/util/tileset.hpp | 0 .../default/mbgl/storage/offline_download.cpp | 28 +++---- src/mbgl/annotation/annotation_manager.cpp | 2 +- src/mbgl/annotation/annotation_source.cpp | 18 +++-- src/mbgl/annotation/annotation_source.hpp | 8 ++ src/mbgl/annotation/annotation_tile.cpp | 3 +- src/mbgl/annotation/annotation_tile.hpp | 3 +- src/mbgl/renderer/painter.cpp | 5 +- src/mbgl/style/parser.cpp | 12 +-- .../style/{source.cpp => source_impl.cpp} | 43 +++++------ .../style/{source.hpp => source_impl.hpp} | 9 ++- ...son_source.cpp => geojson_source_impl.cpp} | 36 +++++---- ...son_source.hpp => geojson_source_impl.hpp} | 10 ++- ...ster_source.cpp => raster_source_impl.cpp} | 16 ++-- ...ster_source.hpp => raster_source_impl.hpp} | 7 +- src/mbgl/style/sources/vector_source.cpp | 25 ------- src/mbgl/style/sources/vector_source_impl.cpp | 25 +++++++ ...ctor_source.hpp => vector_source_impl.hpp} | 7 +- src/mbgl/style/style.cpp | 36 ++++----- .../{tile_source.cpp => tile_source_impl.cpp} | 29 ++++---- .../{tile_source.hpp => tile_source_impl.hpp} | 13 ++-- test/style/source.cpp | 73 ++++++++++--------- test/style/style.cpp | 10 +-- test/style/tile_source.cpp | 10 +-- 28 files changed, 356 insertions(+), 202 deletions(-) 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 rename {src => include}/mbgl/util/tileset.hpp (100%) rename src/mbgl/style/{source.cpp => source_impl.cpp} (86%) rename src/mbgl/style/{source.hpp => source_impl.hpp} (92%) rename src/mbgl/style/sources/{geojson_source.cpp => geojson_source_impl.cpp} (64%) rename src/mbgl/style/sources/{geojson_source.hpp => geojson_source_impl.hpp} (79%) rename src/mbgl/style/sources/{raster_source.cpp => raster_source_impl.cpp} (63%) rename src/mbgl/style/sources/{raster_source.hpp => raster_source_impl.hpp} (56%) delete mode 100644 src/mbgl/style/sources/vector_source.cpp create mode 100644 src/mbgl/style/sources/vector_source_impl.cpp rename src/mbgl/style/sources/{vector_source.hpp => vector_source_impl.hpp} (58%) rename src/mbgl/style/{tile_source.cpp => tile_source_impl.cpp} (83%) rename src/mbgl/style/{tile_source.hpp => tile_source_impl.hpp} (80%) diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp new file mode 100644 index 000000000..92341066b --- /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 000000000..96b9a9960 --- /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 000000000..2d1d648ee --- /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 000000000..3d5336273 --- /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/src/mbgl/util/tileset.hpp b/include/mbgl/util/tileset.hpp similarity index 100% rename from src/mbgl/util/tileset.hpp rename to include/mbgl/util/tileset.hpp diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index 3f21b8571..2aaeb30fa 100644 --- a/platform/default/mbgl/storage/offline_download.cpp +++ b/platform/default/mbgl/storage/offline_download.cpp @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -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(source.get()); + style::TileSourceImpl* tileSource = static_cast(source->baseImpl.get()); const variant& urlOrTileset = tileSource->getURLOrTileset(); if (urlOrTileset.is()) { - result.requiredResourceCount += tileResources(source->type, tileSource->getTileSize(), urlOrTileset.get()).size(); + result.requiredResourceCount += tileResources(source->baseImpl->type, tileSource->getTileSize(), urlOrTileset.get()).size(); } else { result.requiredResourceCount += 1; const std::string& url = urlOrTileset.get(); optional 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(source.get()); - const variant& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON(); + style::GeoJSONSource::Impl* geojsonSource = static_cast(source->baseImpl.get()); + const variant& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON(); if (urlOrGeoJSON.is()) { 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(source.get()); + const style::TileSourceImpl* tileSource = static_cast(source->baseImpl.get()); const variant& 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(source.get()); - const variant& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON(); + style::GeoJSONSource::Impl* geojsonSource = static_cast(source->baseImpl.get()); + const variant& urlOrGeoJSON = geojsonSource->getURLOrGeoJSON(); if (urlOrGeoJSON.is()) { ensureResource(Resource::source(urlOrGeoJSON.get())); diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index b3edbf857..e3c6cc56d 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 = std::make_unique(); - source->enabled = true; + source->baseImpl->enabled = true; style.addSource(std::move(source)); std::unique_ptr layer = std::make_unique(PointLayerID); diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp index 2c87c4f20..61fc4ca2e 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(*this)) { } -Range AnnotationSource::getZoomRange() { +AnnotationSource::Impl::Impl(Source& base_) + : Source::Impl(SourceType::Annotations, AnnotationManager::SourceID, base_) { +} + +Range AnnotationSource::Impl::getZoomRange() { return { 0, 22 }; } -void AnnotationSource::load(FileSource&) { +void AnnotationSource::Impl::load(FileSource&) { loaded = true; } -std::unique_ptr AnnotationSource::createTile(const OverscaledTileID& tileID, - const style::UpdateParameters& parameters) { - return std::make_unique(tileID, id, parameters); +std::unique_ptr AnnotationSource::Impl::createTile(const OverscaledTileID& tileID, + const style::UpdateParameters& parameters) { + return std::make_unique(tileID, parameters); } } // namespace mbgl diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp index e8d3b43e0..db9221788 100644 --- a/src/mbgl/annotation/annotation_source.hpp +++ b/src/mbgl/annotation/annotation_source.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include 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 79e281acc..91b7f7ddc 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 290df3537..3e7c2c447 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 eee568ec9..ca536f667 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -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 09689f22f..34f01c14c 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -1,7 +1,7 @@ #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -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 similarity index 86% rename from src/mbgl/style/source.cpp rename to src/mbgl/style/source_impl.cpp index 5f4949c94..4223f2b50 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -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& Source::getRenderTiles() const { +const std::map& 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 coordinateToTilePoint(const UnwrappedTileID& tileID, const }; } -std::unordered_map> Source::queryRenderedFeatures(const QueryParameters& parameters) const { +std::unordered_map> Source::Impl::queryRenderedFeatures(const QueryParameters& parameters) const { LineString queryGeometry; for (const auto& p : parameters.geometry) { @@ -241,32 +242,32 @@ std::unordered_map> 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 similarity index 92% rename from src/mbgl/style/source.hpp rename to src/mbgl/style/source_impl.hpp index 5c1a81356..64651d7e3 100644 --- a/src/mbgl/style/source.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include #include @@ -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 similarity index 64% rename from src/mbgl/style/sources/geojson_source.cpp rename to src/mbgl/style/sources/geojson_source_impl.cpp index e06b00ec9..f58e0fc62 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -15,7 +15,7 @@ namespace mbgl { namespace style { -std::unique_ptr GeoJSONSource::parseGeoJSON(const JSValue& value) { +std::unique_ptr GeoJSONSource::Impl::parseGeoJSON(const JSValue& value) { using namespace mapbox::geojsonvt; Options options; @@ -32,7 +32,7 @@ std::unique_ptr GeoJSONSource::parseGeoJSON(const } } -std::unique_ptr GeoJSONSource::parse(const std::string& id, const JSValue& value) { +std::unique_ptr 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::parse(const std::string& id, const const JSValue& dataVal = value["data"]; if (dataVal.IsString()) { - return std::make_unique(id, std::string(dataVal.GetString(), dataVal.GetStringLength())); + return std::make_unique([&] (Source& base) { + return std::make_unique(id, base, std::string(dataVal.GetString(), dataVal.GetStringLength())); + }); } else if (dataVal.IsObject()) { - return std::make_unique(id, parseGeoJSON(dataVal)); + return std::make_unique([&] (Source& base) { + return std::make_unique(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 urlOrGeoJSON_) - : Source(SourceType::GeoJSON, std::move(id_)), +GeoJSONSource::Impl::Impl(std::string id_, Source& base_, variant 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()) { loaded = true; return; @@ -72,11 +76,11 @@ void GeoJSONSource::load(FileSource& fileSource) { const std::string& url = urlOrGeoJSON.get(); 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::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 GeoJSONSource::getZoomRange() { +Range GeoJSONSource::Impl::getZoomRange() { assert(loaded); return { 0, urlOrGeoJSON.get()->options.maxZoom }; } -std::unique_ptr GeoJSONSource::createTile(const OverscaledTileID& tileID, +std::unique_ptr GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { assert(loaded); - return std::make_unique(tileID, id, parameters, *urlOrGeoJSON.get()); + return std::make_unique(tileID, base.getID(), parameters, *urlOrGeoJSON.get()); } } // namespace style diff --git a/src/mbgl/style/sources/geojson_source.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp similarity index 79% rename from src/mbgl/style/sources/geojson_source.hpp rename to src/mbgl/style/sources/geojson_source_impl.hpp index 490dae48b..350045b27 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 +#include +#include #include #include @@ -16,15 +17,16 @@ class AsyncRequest; namespace style { -class GeoJSONSource : public Source { +class GeoJSONSource::Impl : public Source::Impl { public: using GeoJSON = std::unique_ptr; static std::unique_ptr parse(const std::string& id, const JSValue&); static GeoJSON parseGeoJSON(const JSValue&); - GeoJSONSource(std::string id, variant urlOrGeoJSON); - ~GeoJSONSource() final; + Impl(std::string id, Source&, + variant 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 similarity index 63% rename from src/mbgl/style/sources/raster_source.cpp rename to src/mbgl/style/sources/raster_source_impl.cpp index 9f873a306..a6e19b475 100644 --- a/src/mbgl/style/sources/raster_source.cpp +++ b/src/mbgl/style/sources/raster_source_impl.cpp @@ -1,12 +1,12 @@ -#include +#include #include #include namespace mbgl { namespace style { -std::unique_ptr RasterSource::parse(std::string id, const JSValue& value) { - optional> urlOrTileset = TileSource::parseURLOrTileset(value); +std::unique_ptr RasterSource::Impl::parse(std::string id, const JSValue& value) { + optional> urlOrTileset = TileSourceImpl::parseURLOrTileset(value); if (!urlOrTileset) { return nullptr; } @@ -25,13 +25,13 @@ std::unique_ptr RasterSource::parse(std::string id, const JSValue& return std::make_unique(std::move(id), std::move(*urlOrTileset), tileSize); } -RasterSource::RasterSource(std::string id_, - variant urlOrTileset_, - uint16_t tileSize_) - : TileSource(SourceType::Raster, std::move(id_), std::move(urlOrTileset_), tileSize_) { +RasterSource::Impl::Impl(std::string id_, Source& base_, + variant urlOrTileset_, + uint16_t tileSize_) + : TileSourceImpl(SourceType::Raster, std::move(id_), base_, std::move(urlOrTileset_), tileSize_) { } -std::unique_ptr RasterSource::createTile(const OverscaledTileID& tileID, +std::unique_ptr RasterSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { return std::make_unique(tileID, parameters, tileset); } diff --git a/src/mbgl/style/sources/raster_source.hpp b/src/mbgl/style/sources/raster_source_impl.hpp similarity index 56% rename from src/mbgl/style/sources/raster_source.hpp rename to src/mbgl/style/sources/raster_source_impl.hpp index 27b2276df..2222b1308 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 +#include +#include namespace mbgl { namespace style { -class RasterSource : public TileSource { +class RasterSource::Impl : public TileSourceImpl { public: static std::unique_ptr parse(std::string id, const JSValue&); - RasterSource(std::string id, variant, uint16_t tileSize); + Impl(std::string id, Source&, variant, uint16_t tileSize); private: std::unique_ptr 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 3f8f840b3..000000000 --- a/src/mbgl/style/sources/vector_source.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -namespace mbgl { -namespace style { - -std::unique_ptr VectorSource::parse(std::string id, const JSValue& value) { - optional> urlOrTileset = TileSource::parseURLOrTileset(value); - if (!urlOrTileset) { - return nullptr; - } - return std::make_unique(std::move(id), std::move(*urlOrTileset)); -} - -VectorSource::VectorSource(std::string id_, variant urlOrTileset_) - : TileSource(SourceType::Vector, std::move(id_), std::move(urlOrTileset_), util::tileSize) { -} - -std::unique_ptr VectorSource::createTile(const OverscaledTileID& tileID, - const UpdateParameters& parameters) { - return std::make_unique(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 000000000..28e14f3e1 --- /dev/null +++ b/src/mbgl/style/sources/vector_source_impl.cpp @@ -0,0 +1,25 @@ +#include +#include + +namespace mbgl { +namespace style { + +std::unique_ptr VectorSource::Impl::parse(std::string id, const JSValue& value) { + optional> urlOrTileset = TileSourceImpl::parseURLOrTileset(value); + if (!urlOrTileset) { + return nullptr; + } + return std::make_unique(std::move(id), std::move(*urlOrTileset)); +} + +VectorSource::Impl::Impl(std::string id_, Source& base_, variant urlOrTileset_) + : TileSourceImpl(SourceType::Vector, std::move(id_), base_, std::move(urlOrTileset_), util::tileSize) { +} + +std::unique_ptr VectorSource::Impl::createTile(const OverscaledTileID& tileID, + const UpdateParameters& parameters) { + return std::make_unique(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 similarity index 58% rename from src/mbgl/style/sources/vector_source.hpp rename to src/mbgl/style/sources/vector_source_impl.hpp index ced7d8047..4a6703e5c 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 +#include +#include namespace mbgl { namespace style { -class VectorSource : public TileSource { +class VectorSource::Impl : public TileSourceImpl { public: static std::unique_ptr parse(std::string id, const JSValue&); - VectorSource(std::string id, variant); + Impl(std::string id, Source&, variant); private: std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index af19c4139..a75133f82 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -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->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 Style::queryRenderedFeatures(const QueryParameters& paramet std::unordered_map> 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 similarity index 83% rename from src/mbgl/style/tile_source.cpp rename to src/mbgl/style/tile_source_impl.cpp index 082469333..634ef3980 100644 --- a/src/mbgl/style/tile_source.cpp +++ b/src/mbgl/style/tile_source_impl.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -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::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> TileSource::parseURLOrTileset(const JSValue& value) { +optional> TileSourceImpl::parseURLOrTileset(const JSValue& value) { if (!value.HasMember("url")) { return { mbgl::style::parseTileJSON(value) }; } @@ -117,18 +117,17 @@ optional> TileSource::parseURLOrTileset(const JSVa return { std::string(urlVal.GetString(), urlVal.GetStringLength()) }; } -TileSource::TileSource(SourceType type_, - std::string id_, - variant urlOrTileset_, - uint16_t tileSize_) - : Source(type_, std::move(id_)), +TileSourceImpl::TileSourceImpl(SourceType type_, std::string id_, Source& base_, + variant 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 = urlOrTileset.get(); loaded = true; @@ -142,11 +141,11 @@ void TileSource::load(FileSource& fileSource) { const std::string& url = urlOrTileset.get(); 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 TileSource::getZoomRange() { +Range TileSourceImpl::getZoomRange() { assert(loaded); return tileset.zoomRange; } diff --git a/src/mbgl/style/tile_source.hpp b/src/mbgl/style/tile_source_impl.hpp similarity index 80% rename from src/mbgl/style/tile_source.hpp rename to src/mbgl/style/tile_source_impl.hpp index 66d956a6e..1ceb1188d 100644 --- a/src/mbgl/style/tile_source.hpp +++ b/src/mbgl/style/tile_source_impl.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -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> parseURLOrTileset(const JSValue&); static Tileset parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize); - TileSource(SourceType, - std::string id, - variant urlOrTileset, - uint16_t tileSize); - ~TileSource() override; + TileSourceImpl(SourceType, std::string id, Source&, + variant urlOrTileset, + uint16_t tileSize); + ~TileSourceImpl() override; void load(FileSource&) final; diff --git a/test/style/source.cpp b/test/style/source.cpp index 9de208f34..6afa5073d 100644 --- a/test/style/source.cpp +++ b/test/style/source.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -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 d530d9cbd..1681bac1c 100644 --- a/test/style/style.cpp +++ b/test/style/style.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include 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 e0709e3be..35d037a04 100644 --- a/test/style/tile_source.cpp +++ b/test/style/tile_source.cpp @@ -1,13 +1,13 @@ #include -#include +#include #include 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,