From 33a1240f96eeb42337732cfecf5e27f70a7ade5f Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 1 Apr 2025 20:36:36 +0200 Subject: [PATCH] Migrate from fmt/format to std/format --- CMakeLists.txt | 1 - src/configconstraints_base.h | 22 ++++++++++------------ src/configconstraints_espchrono.h | 4 ---- src/configmanager_priv.h | 9 ++++++--- src/configwrapper_priv.h | 4 +--- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c891d4..7b13328 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ set(dependencies espwifistack date espchrono - fmt nvs_flash ) diff --git a/src/configconstraints_base.h b/src/configconstraints_base.h index eb4003d..c7236c1 100644 --- a/src/configconstraints_base.h +++ b/src/configconstraints_base.h @@ -3,9 +3,7 @@ // system includes #include #include - -// 3rdparty lib includes -#include +#include // local includes #include "configwrapper.h" @@ -16,7 +14,7 @@ template ConfigConstraintReturnType StringMaxSize(const std::string &str) { if (str.size() > MAX_LENGTH) - return std::unexpected(fmt::format("String length {} exceeds maximum {}", str.size(), MAX_LENGTH)); + return std::unexpected(std::format("String length {} exceeds maximum {}", str.size(), MAX_LENGTH)); return {}; } @@ -24,7 +22,7 @@ template ConfigConstraintReturnType StringMinMaxSize(const std::string &str) { if (str.size() < MIN_LENGTH || str.size() > MAX_LENGTH) - return std::unexpected(fmt::format("String length {} exceeds range {} to {}", str.size(), MIN_LENGTH, MAX_LENGTH)); + return std::unexpected(std::format("String length {} exceeds range {} to {}", str.size(), MIN_LENGTH, MAX_LENGTH)); return {}; } @@ -49,7 +47,7 @@ ConfigConstraintReturnType StringOr(const std::string &str) const auto result1 = callback1(str); if (result1) return {}; - return std::unexpected(fmt::format("None of the following 2 constraints succeded: {} | {}", result0.error(), result1.error())); + return std::unexpected(std::format("None of the following 2 constraints succeded: {} | {}", result0.error(), result1.error())); } template::ConstraintCallback callback0, ConfigWrapper::ConstraintCallback callback1, ConfigWrapper::ConstraintCallback callback2> @@ -64,7 +62,7 @@ ConfigConstraintReturnType StringOr(const std::string &str) const auto result2 = callback2(str); if (result2) return {}; - return std::unexpected(fmt::format("None of the following 3 constraints succeded: {} | {} | {}", result0.error(), result1.error(), result2.error())); + return std::unexpected(std::format("None of the following 3 constraints succeded: {} | {} | {}", result0.error(), result1.error(), result2.error())); } template::ConstraintCallback callback0, ConfigWrapper::ConstraintCallback callback1> @@ -101,7 +99,7 @@ template ConfigConstraintReturnType MinValue(typename ConfigWrapper::value_t val) { if (val < MIN_VALUE) - return std::unexpected(fmt::format("Value {} exceeds minimum {}", val, MIN_VALUE)); + return std::unexpected(std::format("Value {} exceeds minimum {}", val, MIN_VALUE)); return {}; } @@ -109,7 +107,7 @@ template ConfigConstraintReturnType MaxValue(typename ConfigWrapper::value_t val) { if (val > MAX_VALUE) - return std::unexpected(fmt::format("Value {} exceeds maximum {}", val, MAX_VALUE)); + return std::unexpected(std::format("Value {} exceeds maximum {}", val, MAX_VALUE)); return {}; } @@ -117,7 +115,7 @@ template ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper::value_t val) { if (val < MIN_VALUE || val > MAX_VALUE) - return std::unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); + return std::unexpected(std::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); return {}; } @@ -125,7 +123,7 @@ template ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper::value_t val, T MIN_VALUE, T MAX_VALUE) { if (val < MIN_VALUE || val > MAX_VALUE) - return std::unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); + return std::unexpected(std::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); return {}; } @@ -133,7 +131,7 @@ template ConfigConstraintReturnType MinMaxOrZeroValue(typename ConfigWrapper::value_t val) { if (val != 0 && (val < MIN_VALUE || val > MAX_VALUE)) - return std::unexpected(fmt::format("Value {} exceeds constraint 0 or range {} to {}", val, MIN_VALUE, MAX_VALUE)); + return std::unexpected(std::format("Value {} exceeds constraint 0 or range {} to {}", val, MIN_VALUE, MAX_VALUE)); return {}; } } // namespace espconfig diff --git a/src/configconstraints_espchrono.h b/src/configconstraints_espchrono.h index f1a05b8..d160fa0 100644 --- a/src/configconstraints_espchrono.h +++ b/src/configconstraints_espchrono.h @@ -1,12 +1,8 @@ #pragma once // system includes -#include #include -// 3rdparty lib includes -#include - // local includes #include "configwrapper.h" #include "espchrono.h" diff --git a/src/configmanager_priv.h b/src/configmanager_priv.h index 16f95e3..4cf652b 100644 --- a/src/configmanager_priv.h +++ b/src/configmanager_priv.h @@ -2,12 +2,15 @@ #include "configmanager.h" +// system includes +#include + // esp-idf includes #include #include -// local includes -#include "espchrono.h" +// 3rdparty lib includes +#include #define INSTANTIATE_CONFIGMANAGER_TEMPLATES(Type) \ namespace espconfig { \ @@ -167,7 +170,7 @@ ConfigStatusReturnType ConfigManager::reset() { if (!message.empty()) message.append(", "); - message.append(fmt::format("reset of {} failed: {}", config.nvsName(), result.error())); + message.append(std::format("reset of {} failed: {}", config.nvsName(), result.error())); } return false; // dont abort loop }); diff --git a/src/configwrapper_priv.h b/src/configwrapper_priv.h index 93609bc..224de75 100644 --- a/src/configwrapper_priv.h +++ b/src/configwrapper_priv.h @@ -9,13 +9,11 @@ // system includes #include #include +#include // esp-idf includes #include -// 3rdparty lib includes -#include - // local includes #include "configwrapper.h" #include "cpputils.h"