Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace instances of mapbox/variant.hpp with std::variant #2946

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions include/mbgl/annotation/annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SymbolAnnotation {
};

using ShapeAnnotationGeometry =
variant<LineString<double>, Polygon<double>, MultiLineString<double>, MultiPolygon<double>>;
std::variant<LineString<double>, Polygon<double>, MultiLineString<double>, MultiPolygon<double>>;

class LineAnnotation {
public:
Expand Down Expand Up @@ -61,6 +61,6 @@ class FillAnnotation {
style::PropertyValue<Color> outlineColor;
};

using Annotation = variant<SymbolAnnotation, LineAnnotation, FillAnnotation>;
using Annotation = std::variant<SymbolAnnotation, LineAnnotation, FillAnnotation>;

} // namespace mbgl
2 changes: 1 addition & 1 deletion include/mbgl/gfx/gpu_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Expression;
class Interpolate;
class Step;
} // namespace expression
using ZoomCurvePtr = variant<std::nullptr_t, const expression::Interpolate*, const expression::Step*>;
using ZoomCurvePtr = std::variant<std::nullptr_t, const expression::Interpolate*, const expression::Step*>;
} // namespace style
namespace gfx {

Expand Down
1 change: 0 additions & 1 deletion include/mbgl/style/color_ramp_property_value.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <mbgl/util/variant.hpp>
#include <mbgl/style/undefined.hpp>
#include <mbgl/style/expression/expression.hpp>

Expand Down
1 change: 1 addition & 0 deletions include/mbgl/style/conversion_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <mbgl/util/feature.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/util/variant.hpp>

#include <mapbox/compatibility/value.hpp>

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/expression/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Interpolate;
class Step;

using ZoomCurveOrError = std::optional<variant<const Interpolate*, const Step*, ParsingError>>;
using ZoomCurvePtr = variant<std::nullptr_t, const Interpolate*, const Step*>;
using ZoomCurvePtr = std::variant<std::nullptr_t, const Interpolate*, const Step*>;

class Expression {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/expression/find_zoom_curve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace style {
namespace expression {

using ZoomCurveOrError = std::optional<variant<const Interpolate*, const Step*, ParsingError>>;
using ZoomCurvePtr = variant<std::nullptr_t, const Interpolate*, const Step*>;
using ZoomCurvePtr = std::variant<std::nullptr_t, const Interpolate*, const Step*>;

/// Find a zoom curve in the expression tree.
/// @param expr Expression root
Expand Down
1 change: 0 additions & 1 deletion include/mbgl/style/filter.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <mbgl/util/variant.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/style/expression/expression.hpp>
Expand Down
45 changes: 27 additions & 18 deletions include/mbgl/style/property_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace style {
template <class T>
class PropertyValue {
private:
using Value = variant<Undefined, T, PropertyExpression<T>>;
using Value = std::variant<Undefined, T, PropertyExpression<T>>;

Value value;

Expand All @@ -29,37 +29,43 @@ class PropertyValue {
PropertyValue(PropertyExpression<T> expression) noexcept
: value(std::move(expression)) {}

bool isUndefined() const noexcept { return value.template is<Undefined>(); }
bool isUndefined() const noexcept { return std::holds_alternative<Undefined>(value); }

bool isConstant() const noexcept { return value.template is<T>(); }
bool isConstant() const noexcept { return std::holds_alternative<T>(value); }

bool isExpression() const noexcept { return value.template is<PropertyExpression<T>>(); }
bool isExpression() const noexcept { return std::holds_alternative<PropertyExpression<T>>(value); }

bool isDataDriven() const noexcept {
return value.match([](const Undefined&) { return false; },
[](const T&) { return false; },
[](const PropertyExpression<T>& fn) { return !fn.isFeatureConstant(); });
return std::visit(overloaded{[](const Undefined&) { return false; },
[](const T&) { return false; },
[](const PropertyExpression<T>& fn) {
return !fn.isFeatureConstant();
}},
value);
}

bool isZoomConstant() const noexcept {
return value.match([](const Undefined&) { return true; },
[](const T&) { return true; },
[](const PropertyExpression<T>& fn) { return fn.isZoomConstant(); });
return std::visit(overloaded{[](const Undefined&) { return true; },
[](const T&) { return true; },
[](const PropertyExpression<T>& fn) {
return fn.isZoomConstant();
}},
value);
}

const T& asConstant() const noexcept { return value.template get<T>(); }
const T& asConstant() const noexcept { return std::get<T>(value); }

PropertyExpression<T>& asExpression() noexcept { return value.template get<PropertyExpression<T>>(); }
const PropertyExpression<T>& asExpression() const noexcept { return value.template get<PropertyExpression<T>>(); }
PropertyExpression<T>& asExpression() noexcept { return std::get<PropertyExpression<T>>(value); }
const PropertyExpression<T>& asExpression() const noexcept { return std::get<PropertyExpression<T>>(value); }

template <class... Ts>
auto match(Ts&&... ts) const {
return value.match(std::forward<Ts>(ts)...);
return std::visit(overloaded{std::forward<Ts>(ts)...}, value);
}

template <typename Evaluator>
auto evaluate(const Evaluator& evaluator, TimePoint = {}) const {
return Value::visit(value, evaluator);
return std::visit(evaluator, value);
}

bool hasDataDrivenPropertyDifference(const PropertyValue<T>& other) const noexcept {
Expand All @@ -68,9 +74,12 @@ class PropertyValue {

using Dependency = style::expression::Dependency;
Dependency getDependencies() const noexcept {
return value.match([](const Undefined&) { return Dependency::None; },
[](const T&) { return Dependency::None; },
[](const PropertyExpression<T>& ex) { return ex.getDependencies(); });
return std::visit(overloaded{[](const Undefined&) { return Dependency::None; },
[](const T&) { return Dependency::None; },
[](const PropertyExpression<T>& ex) {
return ex.getDependencies();
}},
value);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/sources/raster_dem_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace style {

class RasterDEMSource : public RasterSource {
public:
RasterDEMSource(std::string id, variant<std::string, Tileset> urlOrTileset, uint16_t tileSize);
RasterDEMSource(std::string id, std::variant<std::string, Tileset> urlOrTileset, uint16_t tileSize);
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
};

Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/style/sources/raster_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace style {
class RasterSource : public Source {
public:
RasterSource(std::string id,
variant<std::string, Tileset> urlOrTileset,
std::variant<std::string, Tileset> urlOrTileset,
uint16_t tileSize,
SourceType sourceType = SourceType::Raster);
~RasterSource() override;

const variant<std::string, Tileset>& getURLOrTileset() const;
const std::variant<std::string, Tileset>& getURLOrTileset() const;
std::optional<std::string> getURL() const;

uint16_t getTileSize() const;
Expand All @@ -36,7 +36,7 @@ class RasterSource : public Source {
Mutable<Source::Impl> createMutable() const noexcept final;

private:
const variant<std::string, Tileset> urlOrTileset;
const std::variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
// Do not add members here, see `WeakPtrFactory`
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/style/sources/vector_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace style {
class VectorSource final : public Source {
public:
VectorSource(std::string id,
variant<std::string, Tileset> urlOrTileset,
std::variant<std::string, Tileset> urlOrTileset,
std::optional<float> maxZoom = std::nullopt,
std::optional<float> minZoom = std::nullopt);
~VectorSource() final;

const variant<std::string, Tileset>& getURLOrTileset() const;
const std::variant<std::string, Tileset>& getURLOrTileset() const;
std::optional<std::string> getURL() const;

class Impl;
Expand All @@ -42,7 +42,7 @@ class VectorSource final : public Source {
Mutable<Source::Impl> createMutable() const noexcept final;

private:
const variant<std::string, Tileset> urlOrTileset;
const std::variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
std::optional<float> maxZoom;
std::optional<float> minZoom;
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/util/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#pragma warning(pop)
#endif

#include <variant>

namespace mbgl {

template <typename... T>
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MLNRasterDEMSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@implementation MLNRasterDEMSource

- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier urlOrTileset:(mbgl::variant<std::string, mbgl::Tileset>)urlOrTileset tileSize:(uint16_t)tileSize {
- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier urlOrTileset:(std::variant<std::string, mbgl::Tileset>)urlOrTileset tileSize:(uint16_t)tileSize {
auto source = std::make_unique<mbgl::style::RasterDEMSource>(identifier.UTF8String,
urlOrTileset,
tileSize);
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MLNRasterTileSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSUR
return self = [super initWithPendingSource:std::move(source)];
}

- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier urlOrTileset:(mbgl::variant<std::string, mbgl::Tileset>)urlOrTileset tileSize:(uint16_t)tileSize {
- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier urlOrTileset:(std::variant<std::string, mbgl::Tileset>)urlOrTileset tileSize:(uint16_t)tileSize {
auto source = std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String,
urlOrTileset,
tileSize);
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MLNRasterTileSource_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN

- (std::unique_ptr<mbgl::style::RasterSource>)
pendingSourceWithIdentifier:(NSString *)identifier
urlOrTileset:(mbgl::variant<std::string, mbgl::Tileset>)urlOrTileset
urlOrTileset:(std::variant<std::string, mbgl::Tileset>)urlOrTileset
tileSize:(uint16_t)tileSize;

@end
Expand Down
18 changes: 10 additions & 8 deletions platform/default/src/mbgl/storage/offline_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
for (const auto& source : parser.sources) {
SourceType type = source->getType();

auto handleTiledSource = [&](const variant<std::string, Tileset>& urlOrTileset, const uint16_t tileSize) {
if (urlOrTileset.is<Tileset>()) {
uint64_t tileSourceCount = tileCount(definition, type, tileSize, urlOrTileset.get<Tileset>().zoomRange);
auto handleTiledSource = [&](const std::variant<std::string, Tileset>& urlOrTileset, const uint16_t tileSize) {
if (std::holds_alternative<Tileset>(urlOrTileset)) {
uint64_t tileSourceCount = tileCount(
definition, type, tileSize, std::get<Tileset>(urlOrTileset).zoomRange);
result->requiredTileCount += tileSourceCount;
result->requiredResourceCount += tileSourceCount;
} else {
result->requiredResourceCount += 1;
const auto& url = urlOrTileset.get<std::string>();
const auto& url = std::get<std::string>(urlOrTileset);
std::optional<Response> sourceResponse = offlineDatabase.get(Resource::source(url));
if (sourceResponse) {
style::conversion::Error error;
Expand Down Expand Up @@ -258,11 +259,12 @@ void OfflineDownload::activateDownload() {
for (const auto& source : parser.sources) {
SourceType type = source->getType();

auto handleTiledSource = [&](const variant<std::string, Tileset>& urlOrTileset, const uint16_t tileSize) {
if (urlOrTileset.is<Tileset>()) {
queueTiles(type, tileSize, urlOrTileset.get<Tileset>());
auto handleTiledSource = [&](const std::variant<std::string, Tileset>& urlOrTileset,
const uint16_t tileSize) {
if (std::holds_alternative<Tileset>(urlOrTileset)) {
queueTiles(type, tileSize, std::get<Tileset>(urlOrTileset));
} else {
const auto& rawUrl = urlOrTileset.get<std::string>();
const auto& rawUrl = std::get<std::string>(urlOrTileset);
const auto& url = util::mapbox::canonicalizeSourceURL(tileServerOptions, rawUrl);

status.requiredResourceCountIsPrecise = false;
Expand Down
2 changes: 1 addition & 1 deletion platform/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/module.cmake)
add_node_module(
mbgl-node
INSTALL_PATH ${PROJECT_SOURCE_DIR}/platform/node/lib/{node_abi}/mbgl.node
NAN_VERSION 2.19.0
NAN_VERSION 2.22.0
EXCLUDE_NODE_ABIS
46
47
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation) {
CHECK_ANNOTATIONS_ENABLED_AND_RETURN(nextID++);
std::lock_guard<std::mutex> lock(mutex);
AnnotationID id = nextID++;
Annotation::visit(annotation, [&](const auto& annotation_) { this->add(id, annotation_); });
std::visit([&](const auto& annotation_) { this->add(id, annotation_); }, annotation);
dirty = true;
return id;
}

bool AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation) {
CHECK_ANNOTATIONS_ENABLED_AND_RETURN(true);
std::lock_guard<std::mutex> lock(mutex);
Annotation::visit(annotation, [&](const auto& annotation_) { this->update(id, annotation_); });
std::visit([&](const auto& annotation_) { this->update(id, annotation_); }, annotation);
return dirty;
}

Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/annotation/fill_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include <mbgl/style/style_impl.hpp>
#include <mbgl/style/layers/fill_layer.hpp>

#include <mbgl/util/variant.hpp>

namespace mbgl {

using namespace style;

FillAnnotationImpl::FillAnnotationImpl(AnnotationID id_, FillAnnotation annotation_)
: ShapeAnnotationImpl(id_),
annotation(ShapeAnnotationGeometry::visit(annotation_.geometry, CloseShapeAnnotation{}),
annotation(std::visit(CloseShapeAnnotation{}, annotation_.geometry),
annotation_.opacity,
annotation_.color,
annotation_.outlineColor) {}
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/annotation/line_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace style;

LineAnnotationImpl::LineAnnotationImpl(AnnotationID id_, LineAnnotation annotation_)
: ShapeAnnotationImpl(id_),
annotation(ShapeAnnotationGeometry::visit(annotation_.geometry, CloseShapeAnnotation{}),
annotation(std::visit(CloseShapeAnnotation{}, annotation_.geometry),
annotation_.opacity,
annotation_.width,
annotation_.color) {}
Expand Down
8 changes: 6 additions & 2 deletions src/mbgl/annotation/shape_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/geometry.hpp>

#include <mbgl/util/variant.hpp>

namespace mbgl {

using namespace style;
Expand All @@ -21,8 +23,10 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati

if (!shapeTiler) {
mapbox::feature::feature_collection<double> features;
features.emplace_back(ShapeAnnotationGeometry::visit(
geometry(), [](auto&& geom) { return Feature{std::forward<decltype(geom)>(geom)}; }));
features.emplace_back(std::visit(overloaded{[](auto&& geom) {
return Feature{std::forward<decltype(geom)>(geom)};
}},
geometry()));
mapbox::geojsonvt::Options options;
// The annotation source is currently hard coded to maxzoom 16, so we're
// topping out at z16 here as well.
Expand Down
Loading
Loading