From df514f94b345d4d00827148fd43260b99ebe0ff9 Mon Sep 17 00:00:00 2001 From: MarcelPiNacy-CVC <169088301+MarcelPiNacy-CVC@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:07:51 +0200 Subject: [PATCH] Check for missing header. (#8176) --- .../Carla/Recorder/CarlaRecorderQuery.cpp | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp b/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp index b1e6232b0..16e5d7a5e 100644 --- a/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp +++ b/Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include @@ -22,39 +22,68 @@ #include +#if __has_include() +#define HAS_FORMAT +#include +#endif + template - requires ( -std::remove_reference_t::Dim <= 3) +requires ( + std::remove_reference_t::Dim <= 3) static std::string FormatVectorLike(V&& v) { + char buffer[256]; constexpr auto Dim = std::remove_reference_t::Dim; if constexpr (Dim == 1) { const auto& [x] = v; +#ifdef HAS_FORMAT return std::format("({})", x); +#else + auto n = snprintf(buffer, sizeof(buffer), "(%f)", (double)x); + if (n < 0) + return ""; + return std::string(buffer, n); +#endif } else if constexpr (Dim == 2) { const auto& [x, y] = v; +#ifdef HAS_FORMAT return std::format("({}, {})", x, y); +#else + auto n = snprintf(buffer, sizeof(buffer), "(%f, %f)", (double)x, (double)y); + if (n < 0) + return ""; + return std::string(buffer, n); +#endif } else if constexpr (Dim == 3) { const auto& [x, y, z] = v; +#ifdef HAS_FORMAT return std::format("({}, {}, {})", x, y, z); +#else + auto n = snprintf(buffer, sizeof(buffer), "(%f, %f, %f)", (double)x, (double)y, (double)z); + if (n < 0) + return ""; + return std::string(buffer, n); +#endif } } template static std::string FormatCurveLike(V&& v) { - std::string r; - r.reserve(4096); - r += "["; - for (auto& [x, y] : v) - r += std::format("({}, {}),", x, y); - r += "]"; - return r; + std::string r; + r += "["; + for (auto& point : v) + { + r += FormatVectorLike(point); + r += ','; + } + r += "]"; + return r; } inline bool CarlaRecorderQuery::ReadHeader(void)