Skip to content

Commit 6e080e7

Browse files
committed
refactor Task module: replace kTypeOfTaskStrings with inline TypeOfTaskToString function, improve error handling for unknown task type
1 parent 5093418 commit 6e080e7

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

modules/core/task/include/task.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ enum TypeOfTask : uint8_t {
3939
kUnknown
4040
};
4141

42-
constexpr std::pair<TypeOfTask, std::string_view> kTypeOfTaskStrings[] = {
43-
{TypeOfTask::kALL, "all"},
44-
{TypeOfTask::kMPI, "mpi"},
45-
{TypeOfTask::kOMP, "omp"},
46-
{TypeOfTask::kSEQ, "seq"},
47-
{TypeOfTask::kSTL, "stl"},
48-
{TypeOfTask::kTBB, "tbb"},
49-
};
42+
inline std::string TypeOfTaskToString(TypeOfTask type) {
43+
constexpr std::pair<TypeOfTask, std::string> kTypeOfTaskStrings[] = {
44+
{TypeOfTask::kALL, "all"},
45+
{TypeOfTask::kMPI, "mpi"},
46+
{TypeOfTask::kOMP, "omp"},
47+
{TypeOfTask::kSEQ, "seq"},
48+
{TypeOfTask::kSTL, "stl"},
49+
{TypeOfTask::kTBB, "tbb"},
50+
};
5051

51-
inline std::string_view TypeOfTaskToString(TypeOfTask type) {
5252
for (const auto& [key, value] : kTypeOfTaskStrings) {
5353
if (key == type) return value;
5454
}
@@ -89,9 +89,9 @@ inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string&
8989
auto list_settings = ppc::util::InitJSONPtr();
9090
file >> *list_settings;
9191

92-
std::string type_str = std::string(TypeOfTaskToString(type_of_task));
92+
std::string type_str = TypeOfTaskToString(type_of_task);
9393
if (type_str == "unknown") {
94-
return "unknown";
94+
throw std::runtime_error("Unknown task type");
9595
}
9696

9797
return type_str + "_" + std::string((*list_settings)["tasks"][type_str]);

0 commit comments

Comments
 (0)