From bf04df2ff5bd54597f17b4c09489686fa552e8d7 Mon Sep 17 00:00:00 2001 From: Julien Rigal Date: Thu, 20 Aug 2026 10:18:43 +0200 Subject: [PATCH] Adding legacy macro and constructor to allow old CatchTimeSection to compile. --- include/MGIS/Profiling.hxx | 15 +++++++++++++++ src/Profiling.cxx | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/include/MGIS/Profiling.hxx b/include/MGIS/Profiling.hxx index ad15f040c..16e8fa27d 100644 --- a/include/MGIS/Profiling.hxx +++ b/include/MGIS/Profiling.hxx @@ -9,11 +9,23 @@ #define MGIS_CONCAT_INNER(a, b) a##b #define MGIS_VARNAME() MGIS_CONCAT(mgis_timer_, __COUNTER__) +/*Temporary macro to allow compiling (careful, the old CatchTimeSection(NAME) will not work)*/ +#define MGIS_CATCH_TIME_SECTION_1(NAME) \ + mgis::ProfilingSection MGIS_VARNAME()(NAME) + +#define MGIS_GET_CATCH_MACRO(_1, _2, MACRO_NAME, ...) MACRO_NAME +#define MGIS_EXPAND(x) x + +#define CatchTimeSection(...) \ + MGIS_EXPAND(MGIS_GET_CATCH_MACRO(__VA_ARGS__, MGIS_CATCH_TIME_SECTION_2, MGIS_CATCH_TIME_SECTION_1)(__VA_ARGS__)) + #define CatchTimeSection(CTX, NAME) \ mgis::ProfilingSection MGIS_VARNAME()(CTX, NAME, (CTX).isProfilingEnabled()) #define CatchLocalTimeSection(CTX, NAME, IS_ENABLED) \ mgis::ProfilingSection MGIS_VARNAME()(CTX, NAME, IS_ENABLED) + + namespace mgis { class Context; @@ -25,6 +37,9 @@ namespace mgis { std::string name, bool enabled) noexcept; + //! \brief dummy constructor for 1-argument CatchTimeSection + ProfilingSection(std::string name) noexcept; + //! \brief Default constructor (fallback, always inactive) ProfilingSection() noexcept : ctx_ptr(nullptr), active(false) {} diff --git a/src/Profiling.cxx b/src/Profiling.cxx index 484bcfb2b..f07f90265 100644 --- a/src/Profiling.cxx +++ b/src/Profiling.cxx @@ -19,6 +19,11 @@ namespace mgis { } } // end of ProfilingSection + ProfilingSection::ProfilingSection(std::string /* name */) noexcept + : ctx_ptr(nullptr), + active(false) { + } // end of legacy ProfilingSection + ProfilingSection::~ProfilingSection() noexcept { if (this->active && this->ctx_ptr != nullptr) { const auto end = std::chrono::high_resolution_clock::now();