diff --git a/modules/core/task/include/task.hpp b/modules/core/task/include/task.hpp index 2ca28f15..340fb97e 100644 --- a/modules/core/task/include/task.hpp +++ b/modules/core/task/include/task.hpp @@ -108,16 +108,16 @@ class Task { /// @brief Validates input data and task attributes before execution. /// @return True if validation is successful. virtual bool Validation() final { - InternalOrderTest(PPC_FUNC_NAME); + InternalOrderTest(ppc::util::FuncName()); return ValidationImpl(); } /// @brief Performs preprocessing on the input data. /// @return True if preprocessing is successful. virtual bool PreProcessing() final { - InternalOrderTest(PPC_FUNC_NAME); + InternalOrderTest(ppc::util::FuncName()); if (state_of_testing_ == StateOfTesting::kFunc) { - InternalTimeTest(PPC_FUNC_NAME); + InternalTimeTest(ppc::util::FuncName()); } return PreProcessingImpl(); } @@ -125,16 +125,16 @@ class Task { /// @brief Executes the main logic of the task. /// @return True if execution is successful. virtual bool Run() final { - InternalOrderTest(PPC_FUNC_NAME); + InternalOrderTest(ppc::util::FuncName()); return RunImpl(); } /// @brief Performs postprocessing on the output data. /// @return True if postprocessing is successful. virtual bool PostProcessing() final { - InternalOrderTest(PPC_FUNC_NAME); + InternalOrderTest(ppc::util::FuncName()); if (state_of_testing_ == StateOfTesting::kFunc) { - InternalTimeTest(PPC_FUNC_NAME); + InternalTimeTest(ppc::util::FuncName()); } return PostProcessingImpl(); } diff --git a/modules/core/util/include/util.hpp b/modules/core/util/include/util.hpp index a6fdea75..9d48d5b0 100644 --- a/modules/core/util/include/util.hpp +++ b/modules/core/util/include/util.hpp @@ -3,13 +3,12 @@ #include #include #include +#include #include #include #include "nlohmann/json_fwd.hpp" -#define PPC_FUNC_NAME __func__ - #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4459) @@ -27,6 +26,23 @@ using NlohmannJsonTypeError = nlohmann::json::type_error; namespace ppc::util { +/** + * @brief Returns the unqualified name of the current function. + * + * @param loc Source location, defaults to the current function. + * @return Function name without namespaces or parameters. + */ +inline std::string FuncName(const std::source_location& loc = std::source_location::current()) { + std::string s{loc.function_name()}; + if (auto p = s.find('('); p != std::string::npos) { + s.resize(p); // drop “(…)” + } + if (auto p = s.rfind("::"); p != std::string::npos) { + s.erase(0, p + 2); // drop namespaces + } + return s; +} + enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams }; std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);