Skip to content

Commit b9efa05

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

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

modules/core/task/include/task.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,13 @@ 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"}, {TypeOfTask::kMPI, "mpi"}, {TypeOfTask::kOMP, "omp"},
45+
{TypeOfTask::kSEQ, "seq"}, {TypeOfTask::kSTL, "stl"}, {TypeOfTask::kTBB, "tbb"},
46+
};
5047

51-
inline std::string_view TypeOfTaskToString(TypeOfTask type) {
52-
for (const auto& [key, value] : kTypeOfTaskStrings) {
48+
for (const auto &[key, value] : kTypeOfTaskStrings) {
5349
if (key == type) return value;
5450
}
5551
return "unknown";
@@ -80,7 +76,7 @@ inline std::string GetStringTaskStatus(StatusOfTask status_of_task) {
8076
/// @param settings_file_path Path to the JSON file containing task type strings.
8177
/// @return Formatted string combining the task type and its corresponding value from the file.
8278
/// @throws std::runtime_error If the file cannot be opened.
83-
inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string& settings_file_path) {
79+
inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string &settings_file_path) {
8480
std::ifstream file(settings_file_path);
8581
if (!file.is_open()) {
8682
throw std::runtime_error("Failed to open " + settings_file_path);
@@ -89,9 +85,9 @@ inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string&
8985
auto list_settings = ppc::util::InitJSONPtr();
9086
file >> *list_settings;
9187

92-
std::string type_str = std::string(TypeOfTaskToString(type_of_task));
88+
std::string type_str = TypeOfTaskToString(type_of_task);
9389
if (type_str == "unknown") {
94-
return "unknown";
90+
throw std::runtime_error("Unknown task type");
9591
}
9692

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

0 commit comments

Comments
 (0)