mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
perf: 加强读取资源类的约束,增加单例 concept
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "AsstRanges.hpp"
|
||||
#include "AsstUtils.hpp"
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace asst
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
requires std::is_base_of_v<AbstractResource, T>
|
||||
requires std::is_base_of_v<AbstractResource, T> && Singleton<T>
|
||||
bool load_resource(const std::filesystem::path& path)
|
||||
{
|
||||
if (!std::filesystem::exists(path)) {
|
||||
@@ -29,7 +29,7 @@ namespace asst
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_base_of_v<AbstractConfigerWithTempl, T>
|
||||
requires std::is_base_of_v<AbstractConfigerWithTempl, T> && Singleton<T>
|
||||
bool load_resource_with_templ(const std::filesystem::path& path, const std::filesystem::path& templ_dir)
|
||||
{
|
||||
if (!load_resource<T>(path)) {
|
||||
|
||||
@@ -23,4 +23,7 @@ namespace asst
|
||||
protected:
|
||||
SingletonHolder() = default;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
concept Singleton = std::is_base_of_v<SingletonHolder<T>, T>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user