[core] change bool to enum class bool TileLoadState

This commit is contained in:
Konstantin Käfer
2016-09-06 12:23:35 +02:00
parent 8edf995946
commit 426242fe41
10 changed files with 28 additions and 21 deletions

View File

@@ -258,8 +258,8 @@ void Source::Impl::setObserver(SourceObserver* observer_) {
observer = observer_;
}
void Source::Impl::onTileLoaded(Tile& tile, bool isNewTile) {
observer->onTileLoaded(base, tile.id, isNewTile);
void Source::Impl::onTileLoaded(Tile& tile, TileLoadState loadState) {
observer->onTileLoaded(base, tile.id, loadState);
}
void Source::Impl::onTileError(Tile& tile, std::exception_ptr error) {

View File

@@ -88,7 +88,7 @@ protected:
private:
// TileObserver implementation.
void onTileLoaded(Tile&, bool isNewTile) override;
void onTileLoaded(Tile&, TileLoadState) override;
void onTileError(Tile&, std::exception_ptr) override;
void onTileUpdated(Tile&) override;

View File

@@ -1,5 +1,7 @@
#pragma once
#include <mbgl/tile/tile_observer.hpp>
#include <exception>
namespace mbgl {
@@ -17,7 +19,7 @@ public:
virtual void onSourceLoaded(Source&) {}
virtual void onSourceError(Source&, std::exception_ptr) {}
virtual void onTileLoaded(Source&, const OverscaledTileID&, bool /* isNewTile */) {}
virtual void onTileLoaded(Source&, const OverscaledTileID&, TileLoadState) {}
virtual void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) {}
virtual void onTileUpdated(Source&, const OverscaledTileID&) {}
};

View File

@@ -469,12 +469,12 @@ void Style::onSourceError(Source& source, std::exception_ptr error) {
observer->onResourceError(error);
}
void Style::onTileLoaded(Source& source, const OverscaledTileID& tileID, bool isNewTile) {
if (isNewTile) {
void Style::onTileLoaded(Source& source, const OverscaledTileID& tileID, TileLoadState loadState) {
if (loadState == TileLoadState::First) {
shouldReparsePartialTiles = true;
}
observer->onTileLoaded(source, tileID, isNewTile);
observer->onTileLoaded(source, tileID, loadState);
observer->onUpdate(Update::Repaint);
}

View File

@@ -130,7 +130,7 @@ private:
// SourceObserver implementation.
void onSourceLoaded(Source&) override;
void onSourceError(Source&, std::exception_ptr) override;
void onTileLoaded(Source&, const OverscaledTileID&, bool isNewTile) override;
void onTileLoaded(Source&, const OverscaledTileID&, TileLoadState) override;
void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) override;
void onTileUpdated(Source&, const OverscaledTileID&) override;

View File

@@ -69,7 +69,7 @@ void GeometryTile::setData(std::unique_ptr<const GeometryTileData> data_) {
featureIndex.reset();
data.reset();
redoPlacement();
observer->onTileLoaded(*this, true);
observer->onTileLoaded(*this, TileLoadState::First);
return;
}
@@ -124,7 +124,7 @@ void GeometryTile::tileLoaded(TileParseResult result, PlacementConfig config) {
}
redoPlacement();
observer->onTileLoaded(*this, true);
observer->onTileLoaded(*this, TileLoadState::First);
} else {
availableData = DataAvailability::All;
observer->onTileError(*this, result.get<std::exception_ptr>());
@@ -161,7 +161,7 @@ bool GeometryTile::parsePending() {
}
redoPlacement();
observer->onTileLoaded(*this, false);
observer->onTileLoaded(*this, TileLoadState::Subsequent);
} else {
availableData = DataAvailability::All;
observer->onTileError(*this, result.get<std::exception_ptr>());

View File

@@ -36,7 +36,7 @@ void RasterTile::setData(std::shared_ptr<const std::string> data,
workRequest.reset();
availableData = DataAvailability::All;
bucket.reset();
observer->onTileLoaded(*this, true);
observer->onTileLoaded(*this, TileLoadState::First);
return;
}
@@ -48,7 +48,7 @@ void RasterTile::setData(std::shared_ptr<const std::string> data,
if (result.is<std::unique_ptr<Bucket>>()) {
bucket = std::move(result.get<std::unique_ptr<Bucket>>());
observer->onTileLoaded(*this, true);
observer->onTileLoaded(*this, TileLoadState::First);
} else {
bucket.reset();
observer->onTileError(*this, result.get<std::exception_ptr>());

View File

@@ -6,11 +6,16 @@ namespace mbgl {
class Tile;
enum class TileLoadState : bool {
First = true,
Subsequent = false,
};
class TileObserver {
public:
virtual ~TileObserver() = default;
virtual void onTileLoaded(Tile&, bool /*isNewTile*/) {}
virtual void onTileLoaded(Tile&, TileLoadState) {}
virtual void onTileError(Tile&, std::exception_ptr) {}
virtual void onTileUpdated(Tile&) {}
};

View File

@@ -34,8 +34,8 @@ public:
if (sourceError) sourceError(source, error);
}
void onTileLoaded(Source& source, const OverscaledTileID& tileID, bool isNewTile) override {
if (tileLoaded) tileLoaded(source, tileID, isNewTile);
void onTileLoaded(Source& source, const OverscaledTileID& tileID, TileLoadState loadState) override {
if (tileLoaded) tileLoaded(source, tileID, loadState);
}
void
@@ -57,7 +57,7 @@ public:
std::function<void (std::exception_ptr)> spriteError;
std::function<void (Source&)> sourceLoaded;
std::function<void (Source&, std::exception_ptr)> sourceError;
std::function<void (Source&, const OverscaledTileID&, bool isNewTile)> tileLoaded;
std::function<void (Source&, const OverscaledTileID&, TileLoadState)> tileLoaded;
std::function<void (Source&, const OverscaledTileID&, std::exception_ptr)> tileError;
std::function<void (Source&, const OverscaledTileID&)> tileUpdated;
std::function<void (std::exception_ptr)> resourceError;

View File

@@ -123,7 +123,7 @@ TEST(Source, RasterTileEmpty) {
return response;
};
test.observer.tileLoaded = [&] (Source& source, const OverscaledTileID&, bool) {
test.observer.tileLoaded = [&] (Source& source, const OverscaledTileID&, TileLoadState) {
EXPECT_EQ("source", source.getID());
test.end();
};
@@ -152,7 +152,7 @@ TEST(Source, VectorTileEmpty) {
return response;
};
test.observer.tileLoaded = [&] (Source& source, const OverscaledTileID&, bool) {
test.observer.tileLoaded = [&] (Source& source, const OverscaledTileID&, TileLoadState) {
EXPECT_EQ("source", source.getID());
test.end();
};
@@ -298,7 +298,7 @@ TEST(Source, RasterTileCancel) {
return optional<Response>();
};
test.observer.tileLoaded = [&] (Source&, const OverscaledTileID&, bool) {
test.observer.tileLoaded = [&] (Source&, const OverscaledTileID&, TileLoadState) {
FAIL() << "Should never be called";
};
@@ -325,7 +325,7 @@ TEST(Source, VectorTileCancel) {
return optional<Response>();
};
test.observer.tileLoaded = [&] (Source&, const OverscaledTileID&, bool) {
test.observer.tileLoaded = [&] (Source&, const OverscaledTileID&, TileLoadState) {
FAIL() << "Should never be called";
};