From 811b18b74ee7f31aadf5b3ebad1fd8616d27d639 Mon Sep 17 00:00:00 2001 From: Tadej Novak Date: Tue, 19 Oct 2021 17:53:23 +0200 Subject: [PATCH] [win] Additional fixes for MSVC and MinGW (#142) --- include/mbgl/style/conversion_impl.hpp | 5 +++++ include/mbgl/style/expression/value.hpp | 6 ++++-- include/mbgl/util/chrono.hpp | 10 ++++++++++ .../default/src/mbgl/storage/mbtiles_file_source.cpp | 2 +- platform/default/src/mbgl/util/compression.cpp | 2 +- src/mbgl/style/conversion/function.cpp | 2 +- test/util/thread.test.cpp | 11 ++--------- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index 11d3bae9c..468ed6d14 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -350,6 +350,11 @@ struct ValueFactory { static Value make(const Rotation& rotation) { return {rotation.getAngle()}; } }; +template <> +struct ValueFactory { + static Value make(float f) { return f; } +}; + template Value makeValue(T&& arg) { return ValueFactory>::make(std::forward(arg)); diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index 3dbb7a800..8e91927f4 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -33,10 +33,12 @@ using ValueBase = variant>>; struct Value : ValueBase { using ValueBase::ValueBase; - + + VARIANT_INLINE Value() : ValueBase() {} + template VARIANT_INLINE Value(T&& val) : ValueBase(val) {} - + // Javascript's Number.MAX_SAFE_INTEGER static uint64_t maxSafeInteger() { return 9007199254740991ULL; } diff --git a/include/mbgl/util/chrono.hpp b/include/mbgl/util/chrono.hpp index d736b4f82..1404da2c5 100644 --- a/include/mbgl/util/chrono.hpp +++ b/include/mbgl/util/chrono.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace mbgl { @@ -35,12 +36,21 @@ Timestamp parseTimestamp(const char *); Timestamp parseTimestamp(int32_t timestamp); // C++17 polyfill +#if defined(_MSC_VER) && !defined(__clang__) +template ::is_signed, int> = 0> +_NODISCARD constexpr std::chrono::duration<_Rep, _Period> abs(const std::chrono::duration<_Rep, _Period> _Dur) noexcept( + std::is_arithmetic_v<_Rep>) /* strengthened */ { + // create a duration with count() the absolute value of _Dur.count() + return _Dur < std::chrono::duration<_Rep, _Period>::zero() ? std::chrono::duration<_Rep, _Period>::zero() - _Dur : _Dur; +} +#else template ::min() < std::chrono::duration::zero()>> constexpr std::chrono::duration abs(std::chrono::duration d) { return d >= d.zero() ? d : -d; } +#endif } // namespace util diff --git a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp index 10f7ba264..b89014af8 100644 --- a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp +++ b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp @@ -17,7 +17,7 @@ #include -#if defined(__QT__) && defined(_WIN32) && !defined(__GNUC__) +#if defined(__QT__) && defined(_WIN32) #include #else #include diff --git a/platform/default/src/mbgl/util/compression.cpp b/platform/default/src/mbgl/util/compression.cpp index a71c21bcf..a6b5b4acf 100644 --- a/platform/default/src/mbgl/util/compression.cpp +++ b/platform/default/src/mbgl/util/compression.cpp @@ -1,6 +1,6 @@ #include -#if defined(__QT__) && defined(_WIN32) && !defined(__GNUC__) +#if defined(__QT__) && defined(_WIN32) #include #else #include diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index 19ad643a2..9008e3d15 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -80,7 +80,7 @@ std::unique_ptr convertTokenStringToExpression(const std::string& so case 0: return literal(source); case 1: - return toString(std::move(inputs[0])); + return expression::dsl::toString(std::move(inputs[0])); default: return concat(std::move(inputs)); } diff --git a/test/util/thread.test.cpp b/test/util/thread.test.cpp index 9990aea31..6fb5801fb 100644 --- a/test/util/thread.test.cpp +++ b/test/util/thread.test.cpp @@ -9,10 +9,6 @@ #include #include -#if defined(WIN32) -#include -#endif - using namespace mbgl; using namespace mbgl::util; @@ -202,11 +198,8 @@ TEST(Thread, ReferenceCanOutliveThread) { worker.invoke(&TestWorker::send, [&] { ADD_FAILURE() << "Should never happen"; }); } -#if defined(WIN32) - Sleep(10); -#else - usleep(10000); -#endif + using namespace std::literals; + std::this_thread::sleep_for(10s); } TEST(Thread, DeletePausedThread) {