diff options
author | m-stephen <truestyle2005@163.com> | 2019-11-01 10:27:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-01 10:27:03 +0800 |
commit | 9427c04bc709c39f7e083b6d1597aaf33af8c302 (patch) | |
tree | 224fa2bffbc6a81b447c76b98e4c13a51baadc29 /include | |
parent | fc2c02bbc6abaef52077fe5e9e78f772e6009967 (diff) | |
parent | 5b38cfee18800cbb3c6a3186882744592662c3d6 (diff) | |
download | qtlocation-mapboxgl-9427c04bc709c39f7e083b6d1597aaf33af8c302.tar.gz |
Merge branch 'master' into stephen-improve-accuracy-for-cameraupstream/stephen-improve-accuracy-for-camera
Diffstat (limited to 'include')
30 files changed, 317 insertions, 36 deletions
diff --git a/include/mbgl/actor/mailbox.hpp b/include/mbgl/actor/mailbox.hpp index 23c579917a..2b9838ef29 100644 --- a/include/mbgl/actor/mailbox.hpp +++ b/include/mbgl/actor/mailbox.hpp @@ -2,6 +2,7 @@ #include <mbgl/util/optional.hpp> +#include <functional> #include <memory> #include <mutex> #include <queue> @@ -34,6 +35,7 @@ public: void receive(); static void maybeReceive(std::weak_ptr<Mailbox>); + static std::function<void()> makeClosure(std::weak_ptr<Mailbox>); private: optional<Scheduler*> scheduler; diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index 6470ab1245..bb2cf124b8 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -1,5 +1,8 @@ #pragma once +#include <mapbox/weak.hpp> + +#include <functional> #include <memory> namespace mbgl { @@ -31,12 +34,21 @@ class Mailbox; class Scheduler { public: virtual ~Scheduler() = default; - - // Used by a Mailbox when it has a message in its queue to request that it - // be scheduled. Specifically, the scheduler is expected to asynchronously - // call `receive() on the given mailbox, provided it still exists at that - // time. - virtual void schedule(std::weak_ptr<Mailbox>) = 0; + + // Enqueues a function for execution. + virtual void schedule(std::function<void()>) = 0; + // Makes a weak pointer to this Scheduler. + virtual mapbox::base::WeakPtr<Scheduler> makeWeakPtr() = 0; + + // Returns a closure wrapping the given one. + // + // When the returned closure is invoked for the first time, it schedules + // the given closure to this scheduler, the consequent calls of the + // returned closure are ignored. + // + // If this scheduler is already deleted by the time the returnded closure is + // first invoked, the call is ignored. + std::function<void()> bindOnce(std::function<void()>); // Set/Get the current Scheduler for this thread static Scheduler* GetCurrent(); diff --git a/include/mbgl/gfx/rendering_stats.hpp b/include/mbgl/gfx/rendering_stats.hpp new file mode 100644 index 0000000000..8fb01a5825 --- /dev/null +++ b/include/mbgl/gfx/rendering_stats.hpp @@ -0,0 +1,22 @@ +#pragma once + +namespace mbgl { +namespace gfx { + +struct RenderingStats { + RenderingStats() = default; + bool isZero() const; + + int numDrawCalls; + int numActiveTextures; + int numCreatedTextures; + int numBuffers; + int numFrameBuffers; + + int memTextures; + int memIndexBuffers; + int memVertexBuffers; +}; + +} // namespace gfx +} // namespace mbgl
\ No newline at end of file diff --git a/include/mbgl/i18n/collator.hpp b/include/mbgl/i18n/collator.hpp new file mode 100644 index 0000000000..9db1f804aa --- /dev/null +++ b/include/mbgl/i18n/collator.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <mbgl/util/optional.hpp> + +#include <memory> +#include <string> + +namespace mbgl { +namespace platform { + +class Collator { +public: + explicit Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale = nullopt); + int compare(const std::string& lhs, const std::string& rhs) const; + std::string resolvedLocale() const; + bool operator==(const Collator& other) const; + +private: + class Impl; + std::shared_ptr<Impl> impl; +}; + +} // namespace platform +} // namespace mbgl diff --git a/include/mbgl/i18n/number_format.hpp b/include/mbgl/i18n/number_format.hpp new file mode 100644 index 0000000000..cb1e94c7bd --- /dev/null +++ b/include/mbgl/i18n/number_format.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include <string> + +namespace mbgl { +namespace platform { + +std::string formatNumber(double number, + const std::string& localeId, + const std::string& currency, + uint8_t minFractionDigits, + uint8_t maxFractionDigits); + +} // namespace platform +} // namespace mbgl diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp index 2c83d1561b..29af9fac91 100644 --- a/include/mbgl/style/conversion.hpp +++ b/include/mbgl/style/conversion.hpp @@ -17,9 +17,12 @@ class ConversionTraits; class Convertible; -template <class T, class Enable = void> +template <typename T, typename Enable = void> struct Converter; +template <typename T, typename Enable = void> +struct ValueFactory; + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index f049ba4ffb..3e1b8455e5 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -1,11 +1,21 @@ #pragma once +#include <mbgl/style/color_ramp_property_value.hpp> #include <mbgl/style/conversion.hpp> -#include <mbgl/util/optional.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> +#include <mbgl/style/transition_options.hpp> #include <mbgl/util/feature.hpp> #include <mbgl/util/geojson.hpp> +#include <mbgl/util/optional.hpp> +#include <mbgl/util/traits.hpp> + +#include <mapbox/value.hpp> +#include <array> +#include <chrono> #include <string> +#include <type_traits> namespace mbgl { namespace style { @@ -288,6 +298,81 @@ optional<T> convert(const Convertible& value, Error& error, Args&&...args) { return Converter<T>()(value, error, std::forward<Args>(args)...); } +template <> +struct ValueFactory<ColorRampPropertyValue> { + static Value make(const ColorRampPropertyValue& value) { return value.getExpression().serialize(); } +}; + +template <> +struct ValueFactory<TransitionOptions> { + static Value make(const TransitionOptions& value) { + return mapbox::base::ValueArray{ + {std::chrono::duration_cast<std::chrono::milliseconds>(value.duration.value_or(mbgl::Duration::zero())) + .count(), + std::chrono::duration_cast<std::chrono::milliseconds>(value.delay.value_or(mbgl::Duration::zero())) + .count(), + value.enablePlacementTransitions}}; + } +}; + +template <> +struct ValueFactory<Color> { + static Value make(const Color& color) { return color.toObject(); } +}; + +template <typename T> +struct ValueFactory<T, typename std::enable_if<(!std::is_enum<T>::value && !is_linear_container<T>::value)>::type> { + static Value make(const T& arg) { return {arg}; } +}; + +template <typename T> +struct ValueFactory<T, typename std::enable_if<std::is_enum<T>::value>::type> { + static Value make(T arg) { return {Enum<T>::toString(arg)}; } +}; + +template <typename T> +struct ValueFactory<T, typename std::enable_if<is_linear_container<T>::value>::type> { + static Value make(const T& arg) { + mapbox::base::ValueArray result; + result.reserve(arg.size()); + for (const auto& item : arg) { + result.emplace_back(ValueFactory<std::decay_t<decltype(item)>>::make(item)); + } + return result; + } +}; + +template <> +struct ValueFactory<Position> { + static Value make(const Position& position) { + return ValueFactory<std::array<float, 3>>::make(position.getSpherical()); + } +}; + +template <typename T> +Value makeValue(T&& arg) { + return ValueFactory<std::decay_t<T>>::make(std::forward<T>(arg)); +} + +template <typename T> +StyleProperty makeStyleProperty(const PropertyValue<T>& value) { + return value.match([](const Undefined&) -> StyleProperty { return {}; }, + [](const T& t) -> StyleProperty { + return {makeValue(t), StyleProperty::Kind::Constant}; + }, + [](const PropertyExpression<T>& fn) -> StyleProperty { + return {fn.getExpression().serialize(), StyleProperty::Kind::Expression}; + }); +} + +inline StyleProperty makeStyleProperty(const TransitionOptions& value) { + return {makeValue(value), StyleProperty::Kind::Transition}; +} + +inline StyleProperty makeStyleProperty(const ColorRampPropertyValue& value) { + return {makeValue(value), StyleProperty::Kind::Expression}; +} + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/expression/collator.hpp b/include/mbgl/style/expression/collator.hpp index 2a79e55556..51ba426fad 100644 --- a/include/mbgl/style/expression/collator.hpp +++ b/include/mbgl/style/expression/collator.hpp @@ -1,10 +1,9 @@ #pragma once -#include <mbgl/util/feature.hpp> +#include <mbgl/i18n/collator.hpp> #include <mbgl/util/optional.hpp> #include <string> -#include <memory> namespace mbgl { namespace style { @@ -20,8 +19,7 @@ public: std::string resolvedLocale() const; private: - class Impl; - std::shared_ptr<Impl> impl; + platform::Collator collator; }; } // namespace expression diff --git a/include/mbgl/style/expression/formatted.hpp b/include/mbgl/style/expression/formatted.hpp index f4f08e9197..bb3d609c91 100644 --- a/include/mbgl/style/expression/formatted.hpp +++ b/include/mbgl/style/expression/formatted.hpp @@ -48,7 +48,8 @@ public: bool operator==(const Formatted& ) const; std::string toString() const; - + mbgl::Value toObject() const; + bool empty() const { return sections.empty() || sections.at(0).text.empty(); } @@ -59,13 +60,18 @@ public: } // namespace expression namespace conversion { - + template <> -struct Converter<mbgl::style::expression::Formatted> { +struct Converter<expression::Formatted> { public: - optional<mbgl::style::expression::Formatted> operator()(const Convertible& value, Error& error) const; + optional<expression::Formatted> operator()(const Convertible& value, Error& error) const; }; - + +template <> +struct ValueFactory<expression::Formatted> { + static Value make(const expression::Formatted& formatted) { return formatted.toObject(); } +}; + } // namespace conversion } // namespace style diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 35577411eb..b50ca75067 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -1,9 +1,10 @@ #pragma once +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/style_property.hpp> +#include <mbgl/style/types.hpp> #include <mbgl/util/immutable.hpp> #include <mbgl/util/optional.hpp> -#include <mbgl/style/types.hpp> -#include <mbgl/style/conversion.hpp> #include <mapbox/weak.hpp> #include <mapbox/type_wrapper.hpp> @@ -110,9 +111,12 @@ public: // Dynamic properties virtual optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) = 0; - virtual optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) = 0; + virtual optional<conversion::Error> setPaintProperty(const std::string& name, + const conversion::Convertible& value) = 0; optional<conversion::Error> setVisibility(const conversion::Convertible& value); + virtual StyleProperty getProperty(const std::string&) const = 0; + // Private implementation // TODO : We should not have public mutable data members. class Impl; diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 4a73ae4a0b..ebdce35d0f 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<Color> getDefaultBackgroundColor(); diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index f171805806..842094f944 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> getDefaultCircleBlur(); diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 4ae59dfae3..c193cfb8d9 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -71,7 +71,7 @@ public: // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; - + StyleProperty getProperty(const std::string&) const final; // Private implementation class Impl; diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index 2e89032ae7..76c2359617 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> getDefaultFillExtrusionBase(); diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 0c4369de4c..9ec33d7e96 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<bool> getDefaultFillAntialias(); diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 2023d8c21e..2dec03b927 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -25,6 +25,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static ColorRampPropertyValue getDefaultHeatmapColor(); diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index f6b04a0062..824606c29b 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<Color> getDefaultHillshadeAccentColor(); diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 638db5fe4b..7b60fcf6ea 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -40,6 +40,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + <% if (layoutProperties.length) { -%> // Layout properties diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 8f1d51295c..4f2cf53708 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -27,6 +27,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Layout properties static PropertyValue<LineCapType> getDefaultLineCap(); diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index ba2ea45428..bff38d42ac 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> getDefaultRasterBrightnessMax(); diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index b60e991f49..92e214919a 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -26,6 +26,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Layout properties static PropertyValue<bool> getDefaultIconAllowOverlap(); diff --git a/include/mbgl/style/light.hpp b/include/mbgl/style/light.hpp index 9a82eb14b5..7434fb2882 100644 --- a/include/mbgl/style/light.hpp +++ b/include/mbgl/style/light.hpp @@ -6,6 +6,7 @@ #include <mbgl/style/conversion.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/style/style_property.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/style/types.hpp> #include <mbgl/util/immutable.hpp> @@ -22,6 +23,7 @@ public: // Dynamic properties optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value); + StyleProperty getProperty(const std::string&) const; static LightAnchorType getDefaultAnchor(); PropertyValue<LightAnchorType> getAnchor() const; diff --git a/include/mbgl/style/light.hpp.ejs b/include/mbgl/style/light.hpp.ejs index a5b907b4dc..e4661dc59b 100644 --- a/include/mbgl/style/light.hpp.ejs +++ b/include/mbgl/style/light.hpp.ejs @@ -9,6 +9,7 @@ #include <mbgl/style/conversion.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/style/style_property.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/style/types.hpp> #include <mbgl/util/immutable.hpp> @@ -25,6 +26,7 @@ public: // Dynamic properties optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value); + StyleProperty getProperty(const std::string&) const; <% for (const property of properties) { -%> static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>(); diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index a256ad6f15..549393e9b2 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -2,6 +2,7 @@ #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/source.hpp> +#include <mbgl/tile/tile_id.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/geojson.hpp> #include <mbgl/util/optional.hpp> @@ -34,6 +35,20 @@ struct GeoJSONOptions { using ClusterProperties = std::unordered_map<std::string, ClusterExpression>; ClusterProperties clusterProperties; }; +class GeoJSONData { +public: + static std::shared_ptr<GeoJSONData> create(const GeoJSON&, const GeoJSONOptions&); + + virtual ~GeoJSONData() = default; + virtual mapbox::feature::feature_collection<int16_t> getTile(const CanonicalTileID&) = 0; + + // SuperclusterData + virtual mapbox::feature::feature_collection<double> getChildren(const std::uint32_t) = 0; + virtual mapbox::feature::feature_collection<double> getLeaves(const std::uint32_t, + const std::uint32_t limit = 10u, + const std::uint32_t offset = 0u) = 0; + virtual std::uint8_t getClusterExpansionZoom(std::uint32_t) = 0; +}; class GeoJSONSource final : public Source { public: @@ -42,8 +57,10 @@ public: void setURL(const std::string& url); void setGeoJSON(const GeoJSON&); + void setGeoJSONData(std::shared_ptr<GeoJSONData>); optional<std::string> getURL() const; + const GeoJSONOptions& getOptions() const; class Impl; const Impl& impl() const; diff --git a/include/mbgl/style/style_property.hpp b/include/mbgl/style/style_property.hpp new file mode 100644 index 0000000000..fc34078dec --- /dev/null +++ b/include/mbgl/style/style_property.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include <mbgl/util/feature.hpp> + +namespace mbgl { +namespace style { + +/** + * @brief Generic representation of a style property. + */ +class StyleProperty { +public: + enum class Kind : uint8_t { Undefined, Constant, Expression, Transition }; + StyleProperty(Value value_, Kind kind_) : value(std::move(value_)), kind(kind_) {} + StyleProperty() = default; + const Value& getValue() const { return value; } + Value& getValue() { return value; } + Kind getKind() const { return kind; } + +private: + Value value; + Kind kind = Kind::Undefined; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/util/feature.hpp b/include/mbgl/util/feature.hpp index 390cc65720..5d8fe89e36 100644 --- a/include/mbgl/util/feature.hpp +++ b/include/mbgl/util/feature.hpp @@ -3,19 +3,33 @@ #include <mbgl/util/optional.hpp> #include <mbgl/util/string.hpp> -#include <mapbox/feature.hpp> +#include <mapbox/value.hpp> namespace mbgl { -using Value = mapbox::feature::value; -using NullValue = mapbox::feature::null_value_t; -using PropertyMap = mapbox::feature::property_map; +using Value = mapbox::base::Value; +using NullValue = mapbox::base::NullValue; +using PropertyMap = mapbox::base::ValueObject; using FeatureIdentifier = mapbox::feature::identifier; -using Feature = mapbox::feature::feature<double>; -using FeatureState = PropertyMap; +using GeoJSONFeature = mapbox::feature::feature<double>; +using FeatureState = mapbox::base::ValueObject; using FeatureStates = std::unordered_map<std::string, FeatureState>; // <featureID, FeatureState> using LayerFeatureStates = std::unordered_map<std::string, FeatureStates>; // <sourceLayer, FeatureStates> +class Feature : public GeoJSONFeature { +public: + std::string source; + std::string sourceLayer; + PropertyMap state; + + using GeometryType = mapbox::geometry::geometry<double>; + + Feature() = default; + Feature(const GeoJSONFeature& f) : GeoJSONFeature(f) {} + Feature(const GeometryType& geom_) : GeoJSONFeature(geom_) {} + Feature(GeometryType&& geom_) : GeoJSONFeature(std::move(geom_)) {} +}; + template <class T> optional<T> numericValue(const Value& value) { return value.match( diff --git a/include/mbgl/util/monotonic_timer.hpp b/include/mbgl/util/monotonic_timer.hpp new file mode 100644 index 0000000000..bdb167214b --- /dev/null +++ b/include/mbgl/util/monotonic_timer.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <chrono> +#include <functional> +#include <mbgl/util/noncopyable.hpp> +#include <memory> + +namespace mbgl { +namespace util { + +class MonotonicTimer { +public: + static std::chrono::duration<double> now(); + + template <typename F, typename... Args> + inline static std::chrono::duration<double> duration(F&& func, Args&&... args) { + auto start = now(); + func(std::forward<Args>(args)...); + return now() - start; + } +}; + +} // namespace util +} // namespace mbgl
\ No newline at end of file diff --git a/include/mbgl/util/platform.hpp b/include/mbgl/util/platform.hpp index 2e11e5f186..3544659740 100644 --- a/include/mbgl/util/platform.hpp +++ b/include/mbgl/util/platform.hpp @@ -16,9 +16,6 @@ std::string lowercase(const std::string &string); // Gets the name of the current thread. std::string getCurrentThreadName(); -std::string formatNumber(double number, const std::string& localeId, const std::string& currency, - uint8_t minFractionDigits, uint8_t maxFractionDigits); - // Set the name of the current thread, truncated at 15. void setCurrentThreadName(const std::string& name); diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp index 381e3ae213..5cde95a531 100644 --- a/include/mbgl/util/run_loop.hpp +++ b/include/mbgl/util/run_loop.hpp @@ -72,12 +72,9 @@ public: push(Priority::Default, task); return std::make_unique<WorkRequest>(task); } - - void schedule(std::weak_ptr<Mailbox> mailbox) override { - invoke([mailbox] () { - Mailbox::maybeReceive(mailbox); - }); - } + + void schedule(std::function<void()> fn) override { invoke(std::move(fn)); } + ::mapbox::base::WeakPtr<Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); } class Impl; @@ -125,6 +122,7 @@ private: std::mutex mutex; std::unique_ptr<Impl> impl; + ::mapbox::base::WeakPtrFactory<Scheduler> weakFactory{this}; }; } // namespace util diff --git a/include/mbgl/util/traits.hpp b/include/mbgl/util/traits.hpp index 5b9401aad7..e37144e60e 100644 --- a/include/mbgl/util/traits.hpp +++ b/include/mbgl/util/traits.hpp @@ -1,7 +1,9 @@ #pragma once +#include <array> #include <cstdint> #include <type_traits> +#include <vector> namespace mbgl { @@ -25,4 +27,12 @@ typename std::enable_if<is_utf16char_like<InChar>::value && is_utf16char_like_po return reinterpret_cast<OutPointer>(in); } +template <typename T> +struct is_linear_container : std::false_type {}; + +template <typename T, std::size_t N> +struct is_linear_container<std::array<T, N>> : std::true_type {}; +template <typename... Ts> +struct is_linear_container<std::vector<Ts...>> : std::true_type {}; + } // namespace mbgl |