From 32bdd0911dcd05ff520148a01ab56178fe6fe2e9 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Mon, 27 Feb 2023 17:27:04 +0100 Subject: [PATCH] Updated to new esp-idf --- CMakeLists.txt | 1 - src/espchrono.cpp | 10 +++++----- src/espchrono.h | 6 +++--- test/espchronotestutils.cpp | 2 +- test/espchronotestutils.h | 4 ++-- test/tst_espchrono.cpp | 8 ++++---- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b96c43c..babc969 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ set(dependencies cpputils date - expected fmt ) diff --git a/src/espchrono.cpp b/src/espchrono.cpp index d2bb17a..d73a031 100644 --- a/src/espchrono.cpp +++ b/src/espchrono.cpp @@ -187,7 +187,7 @@ LocalDateTime toDateTime(local_clock::time_point ts) return dateTime; } -tl::expected parseDateTime(std::string_view str) +std::expected parseDateTime(std::string_view str) { // both valid: // 2020-11-10T21:31 @@ -206,7 +206,7 @@ tl::expected parseDateTime(std::string_view str) constexpr auto dateTimeFormat = "%4d-%2u-%2uT%2hhu:%2hhu:%2hhu.%3hu.%3hu"; if (const auto scanned = std::sscanf(str.data(), dateTimeFormat, &year, &month, &day, &hour, &minute, &second, &millisecond, µsecond); scanned < 5) - return tl::make_unexpected(fmt::format("invalid DateTime ({})", str)); + return std::unexpected(fmt::format("invalid DateTime ({})", str)); return DateTime{ .date=date::year_month_day{date::year{year}, date::month{month}, date::day{day}}, @@ -218,16 +218,16 @@ tl::expected parseDateTime(std::string_view str) }; } -tl::expected parseDaypoint(std::string_view str) +std::expected parseDaypoint(std::string_view str) { int8_t hour, minute, second{}; constexpr auto daypointFormat = "%2hhd:%2hhd:%2hhd"; if (const auto scanned = std::sscanf(str.data(), daypointFormat, &hour, &minute, &second); scanned < 2) - return tl::make_unexpected(fmt::format("invalid daypoint ({})", str)); + return std::unexpected(fmt::format("invalid daypoint ({})", str)); if (hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) - return tl::make_unexpected(fmt::format("invalid daypoint ({})", str)); + return std::unexpected(fmt::format("invalid daypoint ({})", str)); return std::chrono::hours{hour} + std::chrono::minutes{minute} + std::chrono::seconds{second}; } diff --git a/src/espchrono.h b/src/espchrono.h index ef1569d..17d7624 100644 --- a/src/espchrono.h +++ b/src/espchrono.h @@ -12,10 +12,10 @@ #include #include #include +#include // 3rdparty lib includes #include -#include // local includes #include "cpptypesafeenum.h" @@ -193,9 +193,9 @@ local_clock::time_point utcToLocal(utc_clock::time_point ts); DateTime toDateTime(utc_clock::time_point ts); LocalDateTime toDateTime(local_clock::time_point ts); -tl::expected parseDateTime(std::string_view str); +std::expected parseDateTime(std::string_view str); -tl::expected parseDaypoint(std::string_view str); +std::expected parseDaypoint(std::string_view str); std::string toString(const DateTime &dateTime); diff --git a/test/espchronotestutils.cpp b/test/espchronotestutils.cpp index 9671e67..75c9c82 100644 --- a/test/espchronotestutils.cpp +++ b/test/espchronotestutils.cpp @@ -76,7 +76,7 @@ char *toString(const espchrono::seconds32 &val) } template<> -char *toString(const tl::expected &val) +char *toString(const std::expected &val) { return val ? ::QTest::toString(*val) : ::QTest::toString("(invalid)"); } diff --git a/test/espchronotestutils.h b/test/espchronotestutils.h index c42027f..0c9936d 100644 --- a/test/espchronotestutils.h +++ b/test/espchronotestutils.h @@ -25,7 +25,7 @@ Q_DECLARE_METATYPE(espchrono::utc_clock::time_point) Q_DECLARE_METATYPE(espchrono::local_clock::time_point) Q_DECLARE_METATYPE(espchrono::DateTime) Q_DECLARE_METATYPE(espchrono::LocalDateTime) -using X = tl::expected; +using X = std::expected; Q_DECLARE_METATYPE(X) extern const espchrono::time_zone testTimeZone; @@ -85,5 +85,5 @@ template<> char *toString(const espchrono::seconds32 &val); template<> -char *toString(const tl::expected &val); +char *toString(const std::expected &val); } // namespace QTest diff --git a/test/tst_espchrono.cpp b/test/tst_espchrono.cpp index d331a91..fe6941d 100644 --- a/test/tst_espchrono.cpp +++ b/test/tst_espchrono.cpp @@ -227,13 +227,13 @@ private slots: void test_parseDaypoint_data() { - using result_t = tl::expected; + using result_t = std::expected; QTest::addColumn("input"); QTest::addColumn("expected"); - QTest::addRow("bullshit") << "bullshit"s << result_t{tl::make_unexpected("invalid daypoint (bullshit)")}; - QTest::addRow("missing_minute") << "00:"s << result_t{tl::make_unexpected("invalid daypoint (00:)")}; + QTest::addRow("bullshit") << "bullshit"s << result_t{std::unexpected("invalid daypoint (bullshit)")}; + QTest::addRow("missing_minute") << "00:"s << result_t{std::unexpected("invalid daypoint (00:)")}; QTest::addRow("zero") << "00:00"s << result_t{0s}; QTest::addRow("zero3") << "00:00:00"s << result_t{0s}; QTest::addRow("random") << "12:34:56"s << result_t{12h+34min+56s}; @@ -244,7 +244,7 @@ private slots: void test_parseDaypoint() { - using result_t = tl::expected; + using result_t = std::expected; QFETCH(std::string, input); QFETCH(result_t, expected);