Skip to content

Commit 59ae80a

Browse files
authored
Replace PPC_FUNC_NAME with ppc::util::FuncName() implementation (#460)
1 parent 579cc16 commit 59ae80a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

modules/core/task/include/task.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,33 +108,33 @@ class Task {
108108
/// @brief Validates input data and task attributes before execution.
109109
/// @return True if validation is successful.
110110
virtual bool Validation() final {
111-
InternalOrderTest(PPC_FUNC_NAME);
111+
InternalOrderTest(ppc::util::FuncName());
112112
return ValidationImpl();
113113
}
114114

115115
/// @brief Performs preprocessing on the input data.
116116
/// @return True if preprocessing is successful.
117117
virtual bool PreProcessing() final {
118-
InternalOrderTest(PPC_FUNC_NAME);
118+
InternalOrderTest(ppc::util::FuncName());
119119
if (state_of_testing_ == StateOfTesting::kFunc) {
120-
InternalTimeTest(PPC_FUNC_NAME);
120+
InternalTimeTest(ppc::util::FuncName());
121121
}
122122
return PreProcessingImpl();
123123
}
124124

125125
/// @brief Executes the main logic of the task.
126126
/// @return True if execution is successful.
127127
virtual bool Run() final {
128-
InternalOrderTest(PPC_FUNC_NAME);
128+
InternalOrderTest(ppc::util::FuncName());
129129
return RunImpl();
130130
}
131131

132132
/// @brief Performs postprocessing on the output data.
133133
/// @return True if postprocessing is successful.
134134
virtual bool PostProcessing() final {
135-
InternalOrderTest(PPC_FUNC_NAME);
135+
InternalOrderTest(ppc::util::FuncName());
136136
if (state_of_testing_ == StateOfTesting::kFunc) {
137-
InternalTimeTest(PPC_FUNC_NAME);
137+
InternalTimeTest(ppc::util::FuncName());
138138
}
139139
return PostProcessingImpl();
140140
}

modules/core/util/include/util.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#include <cstdint>
44
#include <cstdlib>
55
#include <memory>
6+
#include <source_location>
67
#include <string>
78
#include <string_view>
89

910
#include "nlohmann/json_fwd.hpp"
1011

11-
#define PPC_FUNC_NAME __func__
12-
1312
#ifdef _MSC_VER
1413
#pragma warning(push)
1514
#pragma warning(disable : 4459)
@@ -27,6 +26,23 @@ using NlohmannJsonTypeError = nlohmann::json::type_error;
2726

2827
namespace ppc::util {
2928

29+
/**
30+
* @brief Returns the unqualified name of the current function.
31+
*
32+
* @param loc Source location, defaults to the current function.
33+
* @return Function name without namespaces or parameters.
34+
*/
35+
inline std::string FuncName(const std::source_location& loc = std::source_location::current()) {
36+
std::string s{loc.function_name()};
37+
if (auto p = s.find('('); p != std::string::npos) {
38+
s.resize(p); // drop “(…)”
39+
}
40+
if (auto p = s.rfind("::"); p != std::string::npos) {
41+
s.erase(0, p + 2); // drop namespaces
42+
}
43+
return s;
44+
}
45+
3046
enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
3147

3248
std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);

0 commit comments

Comments
 (0)