🛰️航天仿真算法库 SpaceAST
0.4.0
载入中...
搜索中...
未找到
PluginInterface.hpp
浏览该文件的文档.
1
20
21
#pragma once
22
23
#include "AstGlobal.h"
24
#include "AstUtil/StringView.hpp"
25
#include <string>
26
#include <vector>
27
28
AST_NAMESPACE_BEGIN
29
36
#define AST_PLUGIN_EXPORT A_DECL_EXPORT
37
42
class
AST_UTIL_API
PluginInstance
43
{
44
public
:
45
virtual
~PluginInstance
() =
default
;
46
};
47
49
typedef
PluginInstance
* (*FPluginInstance)();
50
51
52
// 插件动态库导出符号名称
53
54
#define AST_PLUGIN_IID_NAME ast_plugin_iid
55
#define AST_PLUGIN_KEYS_NAME ast_plugin_keys
56
#define AST_PLUGIN_INSTANCE_NAME ast_plugin_instance
57
58
#define AST_PLUGIN_IID_NAMESTR A_STRINGIZE(AST_PLUGIN_IID_NAME)
59
#define AST_PLUGIN_KEYS_NAMESTR A_STRINGIZE(AST_PLUGIN_KEYS_NAME)
60
#define AST_PLUGIN_INSTANCE_NAMESTR A_STRINGIZE(AST_PLUGIN_INSTANCE_NAME)
61
62
#define AST_PLUGIN_INSTANCE(Type) extern "C" AST_PLUGIN_EXPORT PluginInstance* AST_PLUGIN_INSTANCE_NAME(){static Type instance; return &instance;}
63
// 带初始化的变量不能直接写成 `extern "C" ... = ...`
64
// GCC 会报"initialized and declared 'extern'"
65
// 改用 extern "C" { } 代码块承载定义
66
#define AST_PLUGIN_IID(IFace) extern "C" { AST_PLUGIN_EXPORT const char* AST_PLUGIN_IID_NAME = aInterfaceId<IFace>(); }
67
#define AST_PLUGIN_KEYS(...) extern "C" { AST_PLUGIN_EXPORT const char* AST_PLUGIN_KEYS_NAME[] = {__VA_ARGS__, nullptr}; }
68
70
template
<
class
IFace>
71
struct
InterfaceId
;
72
76
#define AST_DECLARE_INTERFACE(IFace, IID) \
77
template<> struct InterfaceId<IFace> { \
78
static constexpr const char* value() { return IID; } \
79
};
80
82
template
<
class
IFace>
83
constexpr
const
char
*
aInterfaceId
()
84
{
85
return
InterfaceId<IFace>::value
();
86
}
87
90
template
<
class
IFace>
91
IFace*
aPluginCast
(
PluginInstance
* instance)
92
{
93
return
dynamic_cast<
IFace*
>
(instance);
94
}
95
97
struct
PluginEntry
98
{
99
std::string iid{};
100
std::vector<std::string> keys{};
101
};
102
105
AST_NAMESPACE_END
ast::PluginInstance
插件根对象基类
定义
PluginInterface.hpp:43
ast::aPluginCast
IFace * aPluginCast(PluginInstance *instance)
把插件根对象转换为指定接口类型
定义
PluginInterface.hpp:91
ast::aInterfaceId
constexpr const char * aInterfaceId()
获取接口 ID
定义
PluginInterface.hpp:83
ast::InterfaceId
接口 ID 特化模板
定义
PluginInterface.hpp:71
ast::PluginEntry
插件元数据中的一条 (接口, 索引键) 声明
定义
PluginInterface.hpp:98
src
AstUtil
Plugin
PluginInterface.hpp
制作者
1.12.0