🛰️航天仿真算法库 SpaceAST 0.4.0
载入中...
搜索中...
未找到
PluginRegistry.hpp
浏览该文件的文档.
1
21
22#pragma once
23
24#include "AstGlobal.h"
25#include "AstUtil/Span.hpp"
26#include "AstUtil/StringView.hpp"
27#include "PluginInterface.hpp"
28#include "PluginLoader.hpp"
29#include <map>
30#include <memory>
31#include <mutex>
32#include <set>
33#include <string>
34#include <utility>
35#include <vector>
36
37AST_NAMESPACE_BEGIN
38
46class AST_UTIL_API PluginRegistry
47{
48public:
50 static PluginRegistry* Instance();
51
57 errc_t scanDirectory(StringView dir, StringView namePrefix = StringView());
58
64 errc_t scanDirectory(StringView dir, Span<const StringView> namePrefixes);
65
68 PluginInstance* find(StringView iid, StringView key);
69
70 template<class IFace>
71 IFace* find(StringView key)
72 {
73 PluginInstance* instance = find(aInterfaceId<IFace>(), key);
74 return aPluginCast<IFace>(instance);
75 }
76
78 void keys(StringView iid, std::vector<std::string>& keys) const;
79 std::vector<std::string> keys(StringView iid) const;
80
81 template<class IFace>
82 std::vector<std::string> keys() const
83 {
84 return this->keys(aInterfaceId<IFace>());
85 }
86
87 template<class IFace>
88 void keys(std::vector<std::string>& keys) const
89 {
90 this->keys(aInterfaceId<IFace>(), keys);
91 }
92
94 size_t pluginCount() const;
95
97 size_t entryCount() const;
98
101 void clear();
102
103private:
104 PluginRegistry() = default;
105 ~PluginRegistry() = default;
106
107 A_DISABLE_COPY(PluginRegistry)
108
109
110 void loadPlugin(const std::string& filepath);
111
112private:
113 std::vector<std::unique_ptr<PluginLoader>> loaders_{};
114 std::map<std::pair<std::string, std::string>, PluginLoader*> index_{};
115 std::set<std::string> scannedDirs_{};
116};
117
120{
121 return *PluginRegistry::Instance();
122}
123
132AST_UTIL_API errc_t aScanPlugins();
133
136AST_NAMESPACE_END
通用插件接口定义
单个插件动态库的加载与元数据读取
插件根对象基类
定义 PluginInterface.hpp:43
单个插件动态库加载器
定义 PluginLoader.hpp:42
插件注册表(进程级单例)
定义 PluginRegistry.hpp:47
非拥有的连续对象序列视图
定义 Span.hpp:74
A_ALWAYS_INLINE PluginRegistry & aPluginRegistry()
获取插件注册表全局单例
定义 PluginRegistry.hpp:119