mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 18:20:39 +08:00
refactor: 用 concepts 优化 static_assert
This commit is contained in:
@@ -41,10 +41,8 @@ namespace asst
|
||||
|
||||
template<typename PluginType>
|
||||
std::shared_ptr<PluginType> register_plugin()
|
||||
requires(std::is_base_of_v<AbstractTaskPlugin, PluginType>) // Plugin must inherit AbstractTaskPlugin
|
||||
{
|
||||
static_assert(std::is_base_of_v<AbstractTaskPlugin, PluginType>,
|
||||
"Plugin must inherit AbstractTaskPlugin");
|
||||
|
||||
auto plugin = std::make_shared<PluginType>(m_callback, m_callback_arg, m_task_chain);
|
||||
m_plugins.emplace(plugin);
|
||||
return plugin;
|
||||
|
||||
@@ -232,7 +232,7 @@ void Assistant::working_proc()
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
if (!m_thread_idle && !m_tasks_list.empty()) {
|
||||
const auto [id, task_ptr] = m_tasks_list.front();
|
||||
const auto& [id, task_ptr] = m_tasks_list.front();
|
||||
lock.unlock();
|
||||
|
||||
json::value callback_json = json::object{
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace asst
|
||||
const std::unordered_set<std::string>& get_templ_required() const noexcept;
|
||||
|
||||
template<typename TargetTaskInfoType = TaskInfo>
|
||||
requires(std::is_base_of_v<TaskInfo, TargetTaskInfoType>) // Parameter must be a TaskInfo
|
||||
std::shared_ptr<TargetTaskInfoType> get(const std::string& name)
|
||||
{
|
||||
auto it = m_all_tasks_info.find(name);
|
||||
@@ -33,15 +34,7 @@ namespace asst
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<TaskInfo, TargetTaskInfoType>) {
|
||||
return it->second;
|
||||
}
|
||||
else if constexpr (std::is_base_of_v<TaskInfo, TargetTaskInfoType>) {
|
||||
return std::dynamic_pointer_cast<TargetTaskInfoType>(it->second);
|
||||
}
|
||||
else {
|
||||
static_assert(!sizeof(TargetTaskInfoType), "Parameter must be a TaskInfo");
|
||||
}
|
||||
return std::dynamic_pointer_cast<TargetTaskInfoType>(it->second);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user