diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp index 32ad8f019..a1b9bfe69 100644 --- a/include/mbgl/map/camera.hpp +++ b/include/mbgl/map/camera.hpp @@ -1,11 +1,10 @@ #ifndef MBGL_MAP_CAMERA #define MBGL_MAP_CAMERA -#include - #include #include #include +#include #include @@ -15,27 +14,27 @@ namespace mbgl { optional. */ struct CameraOptions { /** Coordinate at the center of the map. */ - mapbox::util::optional center; + optional center; /** Padding around the interior of the view that affects the frame of reference for `center`. */ - mapbox::util::optional padding; + optional padding; /** Point of reference for `zoom` and `angle`, assuming an origin at the top-left corner of the view. */ - mapbox::util::optional anchor; + optional anchor; /** Zero-based zoom level. Constrained to the minimum and maximum zoom levels. */ - mapbox::util::optional zoom; + optional zoom; /** Bearing, measured in radians counterclockwise from true north. Wrapped to [−π rad, π rad). */ - mapbox::util::optional angle; + optional angle; /** Pitch toward the horizon measured in radians, with 0 rad resulting in a two-dimensional map. */ - mapbox::util::optional pitch; + optional pitch; }; /** Various options for describing a transition between viewpoints with @@ -43,21 +42,21 @@ struct CameraOptions { struct is used. */ struct AnimationOptions { /** Time to animate to the viewpoint defined herein. */ - mapbox::util::optional duration; + optional duration; /** Average velocity of a flyTo() transition, measured in screenfuls per second, assuming a linear timing curve. A screenful is the visible span in pixels. It does not correspond to a fixed physical distance but rather varies by zoom level. */ - mapbox::util::optional velocity; + optional velocity; /** Zero-based zoom level at the peak of the flyTo() transition’s flight path. */ - mapbox::util::optional minZoom; + optional minZoom; /** The easing timing curve of the transition. */ - mapbox::util::optional easing; + optional easing; /** A function that is called on each frame of the transition, just before a screen update, except on the last frame. The first parameter indicates diff --git a/include/mbgl/util/optional.hpp b/include/mbgl/util/optional.hpp new file mode 100644 index 000000000..1063ba84a --- /dev/null +++ b/include/mbgl/util/optional.hpp @@ -0,0 +1,13 @@ +#ifndef MBGL_UTIL_OPTIONAL +#define MBGL_UTIL_OPTIONAL + +#include + +namespace mbgl { + +template +using optional = std::experimental::optional; + +} // namespace mbgl + +#endif diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index e8d68170a..8157820d7 100644 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -1297,9 +1297,9 @@ void JNICALL nativeSetVisibleCoordinateBounds(JNIEnv *env, jobject obj, jlong na } mbgl::AnimationOptions animationOptions; if (duration > 0) { - animationOptions.duration = std::chrono::milliseconds(duration); + animationOptions.duration = mbgl::Duration(std::chrono::milliseconds(duration)); // equivalent to kCAMediaTimingFunctionDefault in iOS - animationOptions.easing = {0.25, 0.1, 0.25, 0.1}; + animationOptions.easing = mbgl::util::UnitBezier(0.25, 0.1, 0.25, 0.1); } nativeMapView->getMap().easeTo(cameraOptions, animationOptions); diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp index f3897ad3e..39dbee408 100644 --- a/src/mbgl/annotation/annotation_tile.cpp +++ b/src/mbgl/annotation/annotation_tile.cpp @@ -12,12 +12,12 @@ AnnotationTileFeature::AnnotationTileFeature(FeatureType type_, GeometryCollecti properties(std::move(properties_)), geometries(geometries_) {} -mapbox::util::optional AnnotationTileFeature::getValue(const std::string& key) const { +optional AnnotationTileFeature::getValue(const std::string& key) const { auto it = properties.find(key); if (it != properties.end()) { - return mapbox::util::optional(it->second); + return optional(it->second); } - return mapbox::util::optional(); + return optional(); } util::ptr AnnotationTile::getLayer(const std::string& name) const { diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp index 3903e1b79..1735b3eb8 100644 --- a/src/mbgl/annotation/annotation_tile.hpp +++ b/src/mbgl/annotation/annotation_tile.hpp @@ -15,7 +15,7 @@ public: std::unordered_map properties = {{}}); FeatureType getType() const override { return type; } - mapbox::util::optional getValue(const std::string&) const override; + optional getValue(const std::string&) const override; GeometryCollection getGeometries() const override { return geometries; } const FeatureType type; diff --git a/src/mbgl/map/geometry_tile.cpp b/src/mbgl/map/geometry_tile.cpp index 1bb132f31..82affc689 100644 --- a/src/mbgl/map/geometry_tile.cpp +++ b/src/mbgl/map/geometry_tile.cpp @@ -4,7 +4,7 @@ namespace mbgl { -mapbox::util::optional GeometryTileFeatureExtractor::getValue(const std::string& key) const { +optional GeometryTileFeatureExtractor::getValue(const std::string& key) const { if (key == "$type") { return Value(uint64_t(feature.getType())); } diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp index 4ae08cc9d..dd9a21bc6 100644 --- a/src/mbgl/map/geometry_tile.hpp +++ b/src/mbgl/map/geometry_tile.hpp @@ -2,13 +2,13 @@ #define MBGL_MAP_GEOMETRY_TILE #include -#include #include #include #include #include #include +#include #include #include @@ -30,7 +30,7 @@ class GeometryTileFeature : private util::noncopyable { public: virtual ~GeometryTileFeature() = default; virtual FeatureType getType() const = 0; - virtual mapbox::util::optional getValue(const std::string& key) const = 0; + virtual optional getValue(const std::string& key) const = 0; virtual GeometryCollection getGeometries() const = 0; }; @@ -73,7 +73,7 @@ public: GeometryTileFeatureExtractor(const GeometryTileFeature& feature_) : feature(feature_) {} - mapbox::util::optional getValue(const std::string& key) const; + optional getValue(const std::string& key) const; private: const GeometryTileFeature& feature; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index e710ca4c1..51106db88 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -469,7 +469,7 @@ void Map::addCustomLayer(const std::string& id, const char* before) { context->invoke(&MapContext::addLayer, std::make_unique(id, initialize, render, deinitialize, context_), - before ? std::string(before) : mapbox::util::optional()); + before ? std::string(before) : optional()); } void Map::removeCustomLayer(const std::string& id) { diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index eb17e20ae..89c491fac 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -279,7 +279,7 @@ double MapContext::getTopOffsetPixelsForAnnotationIcon(const std::string& name) return data.getAnnotationManager()->getTopOffsetPixelsForIcon(name); } -void MapContext::addLayer(std::unique_ptr layer, mapbox::util::optional after) { +void MapContext::addLayer(std::unique_ptr layer, optional after) { style->addLayer(std::move(layer), after); updateFlags |= Update::Classes; asyncUpdate.send(); diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index 012da785c..dd0c2de46 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -10,8 +10,7 @@ #include #include #include - -#include +#include #include @@ -58,7 +57,7 @@ public: // Style API void addLayer(std::unique_ptr, - const mapbox::util::optional before); + const optional before); void removeLayer(const std::string& id); void setSourceTileCacheSize(size_t size); diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp index 343efe431..8faaae395 100644 --- a/src/mbgl/map/vector_tile.cpp +++ b/src/mbgl/map/vector_tile.cpp @@ -54,10 +54,10 @@ VectorTileFeature::VectorTileFeature(pbf feature_pbf, const VectorTileLayer& lay } } -mapbox::util::optional VectorTileFeature::getValue(const std::string& key) const { +optional VectorTileFeature::getValue(const std::string& key) const { auto keyIter = layer.keys.find(key); if (keyIter == layer.keys.end()) { - return mapbox::util::optional(); + return optional(); } pbf tags = tags_pbf; @@ -82,7 +82,7 @@ mapbox::util::optional VectorTileFeature::getValue(const std::string& key } } - return mapbox::util::optional(); + return optional(); } GeometryCollection VectorTileFeature::getGeometries() const { diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp index 1b836b84b..1557db784 100644 --- a/src/mbgl/map/vector_tile.hpp +++ b/src/mbgl/map/vector_tile.hpp @@ -16,7 +16,7 @@ public: VectorTileFeature(pbf, const VectorTileLayer&); FeatureType getType() const override { return type; } - mapbox::util::optional getValue(const std::string&) const override; + optional getValue(const std::string&) const override; GeometryCollection getGeometries() const override; private: diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 35bc10ab6..a4d6aa6c6 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -262,8 +262,8 @@ void Painter::renderBackground(const BackgroundLayer& layer) { const BackgroundPaintProperties& properties = layer.paint; if (!properties.pattern.value.to.empty()) { - mapbox::util::optional imagePosA = spriteAtlas->getPosition(properties.pattern.value.from, true); - mapbox::util::optional imagePosB = spriteAtlas->getPosition(properties.pattern.value.to, true); + optional imagePosA = spriteAtlas->getPosition(properties.pattern.value.from, true); + optional imagePosB = spriteAtlas->getPosition(properties.pattern.value.to, true); if (!imagePosA || !imagePosB) return; diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 38aa92fb0..0217cb1a5 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -60,8 +60,8 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI } if (pattern) { - mapbox::util::optional posA = spriteAtlas->getPosition(properties.pattern.value.from, true); - mapbox::util::optional posB = spriteAtlas->getPosition(properties.pattern.value.to, true); + optional posA = spriteAtlas->getPosition(properties.pattern.value.from, true); + optional posB = spriteAtlas->getPosition(properties.pattern.value.to, true); // Image fill. if (pass == RenderPass::Translucent && posA && posB) { diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 4fa6c2552..b849073cc 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -103,8 +103,8 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI bucket.drawLineSDF(*linesdfShader); } else if (!properties.pattern.value.from.empty()) { - mapbox::util::optional imagePosA = spriteAtlas->getPosition(properties.pattern.value.from, true); - mapbox::util::optional imagePosB = spriteAtlas->getPosition(properties.pattern.value.to, true); + optional imagePosA = spriteAtlas->getPosition(properties.pattern.value.from, true); + optional imagePosB = spriteAtlas->getPosition(properties.pattern.value.to, true); if (!imagePosA || !imagePosB) return; diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index 497721a61..53f97e454 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -47,7 +47,7 @@ Rect SpriteAtlas::allocateImage(float src_width, float s return rect; } -mapbox::util::optional SpriteAtlas::getImage(const std::string& name, const bool wrap) { +optional SpriteAtlas::getImage(const std::string& name, const bool wrap) { std::lock_guard lock(mtx); auto rect_it = images.find({ name, wrap }); @@ -74,7 +74,7 @@ mapbox::util::optional SpriteAtlas::getImage(const std::stri return SpriteAtlasElement { rect, sprite, sprite->pixelRatio / pixelRatio }; } -mapbox::util::optional SpriteAtlas::getPosition(const std::string& name, bool repeating) { +optional SpriteAtlas::getPosition(const std::string& name, bool repeating) { std::lock_guard lock(mtx); auto img = getImage(name, repeating); diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp index aca82b3fe..f57700470 100644 --- a/src/mbgl/sprite/sprite_atlas.hpp +++ b/src/mbgl/sprite/sprite_atlas.hpp @@ -5,8 +5,7 @@ #include #include #include - -#include +#include #include #include @@ -32,9 +31,9 @@ struct SpriteAtlasPosition { }; struct SpriteAtlasElement { - const Rect pos; - const std::shared_ptr texture; - const float relativePixelRatio; + Rect pos; + std::shared_ptr texture; + float relativePixelRatio; }; class SpriteAtlas : public util::noncopyable { @@ -46,10 +45,10 @@ public: // If the sprite is loaded, copies the requsted image from it into the atlas and returns // the resulting icon measurements. If not, returns an empty optional. - mapbox::util::optional getImage(const std::string& name, const bool wrap); + optional getImage(const std::string& name, const bool wrap); // This function is used for getting the position during render time. - mapbox::util::optional getPosition(const std::string& name, bool repeating = false); + optional getPosition(const std::string& name, bool repeating = false); // Binds the atlas texture to the GPU, and uploads data if it is out of date. void bind(bool linear = false); diff --git a/src/mbgl/style/filter_expression_private.hpp b/src/mbgl/style/filter_expression_private.hpp index 67a37c2d4..bbc72526d 100644 --- a/src/mbgl/style/filter_expression_private.hpp +++ b/src/mbgl/style/filter_expression_private.hpp @@ -1,4 +1,4 @@ -#include +#include #include @@ -23,43 +23,43 @@ bool evaluate(const FilterExpression& expression, const Extractor& extractor) { template bool EqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); return actual && util::relaxed_equal(*actual, value); } template bool NotEqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); return !actual || util::relaxed_not_equal(*actual, value); } template bool LessThanExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); return actual && util::relaxed_less(*actual, value); } template bool LessThanEqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); return actual && util::relaxed_less_equal(*actual, value); } template bool GreaterThanExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); return actual && util::relaxed_greater(*actual, value); } template bool GreaterThanEqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); return actual && util::relaxed_greater_equal(*actual, value); } template bool InExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); if (!actual) return false; for (const auto& v: values) { @@ -72,7 +72,7 @@ bool InExpression::evaluate(const Extractor& extractor) const { template bool NotInExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional actual = extractor.getValue(key); + optional actual = extractor.getValue(key); if (!actual) return true; for (const auto& v: values) { diff --git a/src/mbgl/style/function.hpp b/src/mbgl/style/function.hpp index 00d4319e0..4d2e4fcbd 100644 --- a/src/mbgl/style/function.hpp +++ b/src/mbgl/style/function.hpp @@ -3,8 +3,7 @@ #include #include - -#include +#include #include #include diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index e27bab3af..a35728d87 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -29,7 +29,7 @@ public: void operator=(const T& v) { value = v; } operator T() const { return value; } - mapbox::util::optional> parsedValue; + optional> parsedValue; T value; }; diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 2c73d84a9..aaf46f038 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -214,11 +214,11 @@ optional parseProperty(const char *, const JSValue& value) { if (value.IsObject()) { bool parsed = false; if (value.HasMember("duration") && value["duration"].IsNumber()) { - transition.duration = std::chrono::milliseconds(value["duration"].GetUint()); + transition.duration = Duration(std::chrono::milliseconds(value["duration"].GetUint())); parsed = true; } if (value.HasMember("delay") && value["delay"].IsNumber()) { - transition.delay = std::chrono::milliseconds(value["delay"].GetUint()); + transition.delay = Duration(std::chrono::milliseconds(value["delay"].GetUint())); parsed = true; } if (!parsed) { diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index 8df95e1d6..73bc5a72c 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -4,15 +4,14 @@ #include #include - -#include +#include #include namespace mbgl { template -using optional = mapbox::util::optional; +using optional = optional; template optional parseProperty(const char* name, const JSValue&); diff --git a/src/mbgl/style/property_transition.hpp b/src/mbgl/style/property_transition.hpp index 63bbf4607..55b795e5d 100644 --- a/src/mbgl/style/property_transition.hpp +++ b/src/mbgl/style/property_transition.hpp @@ -2,16 +2,16 @@ #define MBGL_STYLE_PROPERTY_TRANSITION #include +#include -#include #include namespace mbgl { class PropertyTransition { public: - mapbox::util::optional duration; - mapbox::util::optional delay; + optional duration; + optional delay; }; } // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index f64bdfc92..58a3ae009 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -104,7 +104,7 @@ StyleLayer* Style::getLayer(const std::string& id) const { return it != layers.end() ? it->get() : nullptr; } -void Style::addLayer(std::unique_ptr layer, mapbox::util::optional before) { +void Style::addLayer(std::unique_ptr layer, optional before) { if (SymbolLayer* symbolLayer = layer->as()) { if (!symbolLayer->spriteAtlas) { symbolLayer->spriteAtlas = spriteAtlas.get(); diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index ba5da7435..29510a388 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -10,8 +10,7 @@ #include #include #include - -#include +#include #include #include @@ -97,7 +96,7 @@ public: std::vector> getLayers() const; StyleLayer* getLayer(const std::string& id) const; void addLayer(std::unique_ptr, - mapbox::util::optional beforeLayerID = {}); + optional beforeLayerID = {}); void removeLayer(const std::string& layerID); RenderData getRenderData() const; diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp index decf7b946..5fbb43303 100644 --- a/src/mbgl/text/shaping.hpp +++ b/src/mbgl/text/shaping.hpp @@ -4,9 +4,9 @@ #include #include #include -#include #include +#include namespace mbgl { @@ -19,7 +19,7 @@ namespace mbgl { float _top, float _bottom, float _left, float _right) : image(_image), top(_top), bottom(_bottom), left(_left), right(_right) {} - mapbox::util::optional image; + optional image; float top = 0; float bottom = 0; float left = 0; diff --git a/src/mbgl/tile/geojson_tile.cpp b/src/mbgl/tile/geojson_tile.cpp index 9f14780ca..e7ce5385f 100644 --- a/src/mbgl/tile/geojson_tile.cpp +++ b/src/mbgl/tile/geojson_tile.cpp @@ -14,12 +14,12 @@ FeatureType GeoJSONTileFeature::getType() const { return type; } -mapbox::util::optional GeoJSONTileFeature::getValue(const std::string& key) const { +optional GeoJSONTileFeature::getValue(const std::string& key) const { auto it = tags.find(key); if (it != tags.end()) { - return mapbox::util::optional(it->second); + return optional(it->second); } - return mapbox::util::optional(); + return optional(); } GeometryCollection GeoJSONTileFeature::getGeometries() const { diff --git a/src/mbgl/tile/geojson_tile.hpp b/src/mbgl/tile/geojson_tile.hpp index e5e9766a1..bbb3eef40 100644 --- a/src/mbgl/tile/geojson_tile.hpp +++ b/src/mbgl/tile/geojson_tile.hpp @@ -23,7 +23,7 @@ public: GeoJSONTileFeature(FeatureType, GeometryCollection&&, Tags&& = Tags{}); FeatureType getType() const override; - mapbox::util::optional getValue(const std::string&) const override; + optional getValue(const std::string&) const override; GeometryCollection getGeometries() const override; private: diff --git a/src/mbgl/util/http_header.hpp b/src/mbgl/util/http_header.hpp index bd1f809ce..e68c5e9fe 100644 --- a/src/mbgl/util/http_header.hpp +++ b/src/mbgl/util/http_header.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_UTIL_HTTP_HEADER #define MBGL_UTIL_HTTP_HEADER -#include +#include #include @@ -12,7 +12,7 @@ class CacheControl { public: static CacheControl parse(const std::string&); - mapbox::util::optional maxAge; + optional maxAge; bool mustRevalidate = false; }; diff --git a/test/miscellaneous/comparisons.cpp b/test/miscellaneous/comparisons.cpp index 2d5b8c542..dc2d74bf1 100644 --- a/test/miscellaneous/comparisons.cpp +++ b/test/miscellaneous/comparisons.cpp @@ -18,12 +18,12 @@ public: , type(type_) {} - mapbox::util::optional getValue(const std::string &key) const { + optional getValue(const std::string &key) const { if (key == "$type") return Value(uint64_t(type)); auto it = properties.find(key); if (it == properties.end()) - return mapbox::util::optional(); + return optional(); return it->second; }