diff --git a/src/MeoAssistant/Task/Sub/ProcessTask.cpp b/src/MeoAssistant/Task/Sub/ProcessTask.cpp index 2937b198f8..7adf40f76c 100644 --- a/src/MeoAssistant/Task/Sub/ProcessTask.cpp +++ b/src/MeoAssistant/Task/Sub/ProcessTask.cpp @@ -156,10 +156,10 @@ bool ProcessTask::_run() info["details"] = json::object { { "task", cur_name }, - { "action", std::to_string(m_cur_task_ptr->action) }, + { "action", enum_to_string(m_cur_task_ptr->action) }, { "exec_times", exec_times }, { "max_times", max_times }, - { "algorithm", std::to_string(m_cur_task_ptr->algorithm) }, + { "algorithm", enum_to_string(m_cur_task_ptr->algorithm) }, }; callback(AsstMsg::SubTaskStart, info); diff --git a/src/MeoAssistant/Utils/AsstTypes.h b/src/MeoAssistant/Utils/AsstTypes.h index b842231589..81d238e96c 100644 --- a/src/MeoAssistant/Utils/AsstTypes.h +++ b/src/MeoAssistant/Utils/AsstTypes.h @@ -255,6 +255,21 @@ namespace asst return AlgorithmType::Invalid; } + inline std::string enum_to_string(AlgorithmType algo) + { + static const std::unordered_map algorithm_map = { + { AlgorithmType::Invalid, "Invalid" }, + { AlgorithmType::JustReturn, "JustReturn" }, + { AlgorithmType::MatchTemplate, "MatchTemplate" }, + { AlgorithmType::OcrDetect, "OcrDetect" }, + { AlgorithmType::Hash, "Hash" }, + }; + if (auto it = algorithm_map.find(algo); it != algorithm_map.end()) { + return it->second; + } + return "Invalid"; + } + enum class ProcessTaskAction { Invalid = 0, @@ -291,60 +306,28 @@ namespace asst } return ProcessTaskAction::Invalid; } -} -namespace std -{ - inline std::string to_string(asst::AlgorithmType algo) + inline std::string enum_to_string(ProcessTaskAction action) { - static const std::unordered_map algorithm_map = { - { asst::AlgorithmType::Invalid, "Invalid" }, - { asst::AlgorithmType::JustReturn, "JustReturn" }, - { asst::AlgorithmType::MatchTemplate, "MatchTemplate" }, - { asst::AlgorithmType::OcrDetect, "OcrDetect" }, - { asst::AlgorithmType::Hash, "Hash" }, - }; - if (auto it = algorithm_map.find(algo); it != algorithm_map.end()) { - return it->second; - } - return "Invalid"; - } - - inline std::string to_string(asst::ProcessTaskAction action) - { - static const std::unordered_map action_map = { - { asst::ProcessTaskAction::Invalid, "Invalid" }, - { asst::ProcessTaskAction::BasicClick, "BasicClick" }, - { asst::ProcessTaskAction::ClickSelf, "ClickSelf" }, - { asst::ProcessTaskAction::ClickRect, "ClickRect" }, - { asst::ProcessTaskAction::ClickRand, "ClickRand" }, - { asst::ProcessTaskAction::DoNothing, "DoNothing" }, - { asst::ProcessTaskAction::Stop, "Stop" }, - { asst::ProcessTaskAction::BasicSwipe, "BasicSwipe" }, - { asst::ProcessTaskAction::SwipeToTheLeft, "SwipeToTheLeft" }, - { asst::ProcessTaskAction::SwipeToTheRight, "SwipeToTheRight" }, - { asst::ProcessTaskAction::SlowlySwipeToTheLeft, "SlowlySwipeToTheLeft" }, - { asst::ProcessTaskAction::SlowlySwipeToTheRight, "SlowlySwipeToTheRight" }, + static const std::unordered_map action_map = { + { ProcessTaskAction::Invalid, "Invalid" }, + { ProcessTaskAction::BasicClick, "BasicClick" }, + { ProcessTaskAction::ClickSelf, "ClickSelf" }, + { ProcessTaskAction::ClickRect, "ClickRect" }, + { ProcessTaskAction::ClickRand, "ClickRand" }, + { ProcessTaskAction::DoNothing, "DoNothing" }, + { ProcessTaskAction::Stop, "Stop" }, + { ProcessTaskAction::BasicSwipe, "BasicSwipe" }, + { ProcessTaskAction::SwipeToTheLeft, "SwipeToTheLeft" }, + { ProcessTaskAction::SwipeToTheRight, "SwipeToTheRight" }, + { ProcessTaskAction::SlowlySwipeToTheLeft, "SlowlySwipeToTheLeft" }, + { ProcessTaskAction::SlowlySwipeToTheRight, "SlowlySwipeToTheRight" }, }; if (auto it = action_map.find(action); it != action_map.end()) { return it->second; } return "Invalid"; } - /* - template - requires requires() { asst::to_string(std::declval()); } - std::string to_string(const T& type) - { - return asst::to_string(type); - } - template - requires requires() { std::declval().to_string(); } - std::string to_string(const T& type) - { - return type.to_string(); - } - */ } namespace asst diff --git a/src/MeoAssistant/Utils/Logger.hpp b/src/MeoAssistant/Utils/Logger.hpp index 5be0e8b3e9..459bcce5e2 100644 --- a/src/MeoAssistant/Utils/Logger.hpp +++ b/src/MeoAssistant/Utils/Logger.hpp @@ -27,6 +27,8 @@ namespace asst { template concept has_stream_insertion_operator = requires { std::declval() << std::declval(); }; + template + concept enum_could_to_string = requires { asst::enum_to_string(std::declval()); }; // is_reference_wrapper template @@ -296,7 +298,7 @@ namespace asst #endif // END _WIN32 s << buff; } - else if constexpr (std::is_enum_v) { + else if constexpr (std::is_enum_v && enum_could_to_string) { s << std::to_string(std::forward(v)); } else if constexpr (has_stream_insertion_operator) {