From b1a1e8619e4c6857fcb490ee5b34088a3ca64b25 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 28 Sep 2023 11:23:46 +0200 Subject: [PATCH 1/2] Cleanup --- src/wrappers/mqtt_client.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wrappers/mqtt_client.h b/src/wrappers/mqtt_client.h index 7a8423f..14cfa47 100644 --- a/src/wrappers/mqtt_client.h +++ b/src/wrappers/mqtt_client.h @@ -11,21 +11,21 @@ namespace espcpputils { class mqtt_client { public: - mqtt_client() : handle{NULL} {} + mqtt_client() : handle{nullptr} {} - mqtt_client(const esp_mqtt_client_config_t *config) : handle{esp_mqtt_client_init(config)} {} + explicit mqtt_client(const esp_mqtt_client_config_t *config) : handle{esp_mqtt_client_init(config)} {} mqtt_client(const mqtt_client &) = delete; - mqtt_client(mqtt_client &&other) : handle{std::move(other.handle)} { other.handle = NULL; } + mqtt_client(mqtt_client &&other) noexcept : handle{other.handle} { other.handle = nullptr; } mqtt_client &operator=(const mqtt_client &) = delete; - mqtt_client &operator=(mqtt_client &&other) { if (handle) esp_mqtt_client_destroy(handle); handle = std::move(other.handle); other.handle = NULL; return *this; } + mqtt_client &operator=(mqtt_client &&other) noexcept { if (handle) esp_mqtt_client_destroy(handle); handle = other.handle; other.handle = nullptr; return *this; } ~mqtt_client() { if (handle) esp_mqtt_client_destroy(handle); } - operator bool() const { return handle != NULL; } + explicit operator bool() const { return handle != nullptr; } //esp_err_t set_uri (const char *uri) { return esp_mqtt_client_set_uri (handle, uri); } esp_err_t set_uri (std::string_view uri) { return esp_mqtt_client_set_uri (handle, uri.data()); } -- 2.50.1 From e0f77beadcc1eb92d6cfb83752c17a4fdda1f772 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 1 Apr 2025 20:36:53 +0200 Subject: [PATCH 2/2] Migrate from fmt/format to std/format --- CMakeLists.txt | 2 -- src/espstrutils.cpp | 12 +++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f2827c..bf9053b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,10 +34,8 @@ set(dependencies esp_hw_support esp_websocket_client tcp_transport - cpputils espchrono - fmt ) idf_component_register( diff --git a/src/espstrutils.cpp b/src/espstrutils.cpp index 684689a..1a7a377 100644 --- a/src/espstrutils.cpp +++ b/src/espstrutils.cpp @@ -5,13 +5,11 @@ // system includes #include +#include // esp-idf includes #include -// 3rdparty lib includes -#include - using namespace std::string_literals; namespace espcpputils { @@ -27,7 +25,7 @@ std::string toString(sntp_sync_mode_t val) case SNTP_SYNC_MODE_SMOOTH: return "SMOOTH"; default: ESP_LOGW(TAG, "unknown sntp_sync_mode_t(%i)", std::to_underlying(val)); - return fmt::format("Unknown sntp_sync_mode_t({})", std::to_underlying(val)); + return std::format("Unknown sntp_sync_mode_t({})", std::to_underlying(val)); } } @@ -40,7 +38,7 @@ std::string toString(sntp_sync_status_t val) case SNTP_SYNC_STATUS_IN_PROGRESS: return "IN_PROGRESS"; default: ESP_LOGW(TAG, "unknown sntp_sync_status_t(%i)", std::to_underlying(val)); - return fmt::format("Unknown sntp_sync_status_t({})", std::to_underlying(val)); + return std::format("Unknown sntp_sync_status_t({})", std::to_underlying(val)); } } @@ -56,7 +54,7 @@ std::string toString(esp_log_level_t val) case ESP_LOG_VERBOSE: return "VERBOSE"; default: ESP_LOGW(TAG, "unknown esp_log_level_t(%i)", std::to_underlying(val)); - return fmt::format("Unknown esp_log_level_t({})", std::to_underlying(val)); + return std::format("Unknown esp_log_level_t({})", std::to_underlying(val)); } } @@ -77,7 +75,7 @@ std::string toString(esp_reset_reason_t val) case ESP_RST_SDIO: return "SDIO"; default: ESP_LOGW(TAG, "unknown esp_reset_reason_t(%i)", std::to_underlying(val)); - return fmt::format("Unknown esp_reset_reason_t({})", std::to_underlying(val)); + return std::format("Unknown esp_reset_reason_t({})", std::to_underlying(val)); } } -- 2.50.1