🛰️航天仿真算法库 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
28AST_NAMESPACE_BEGIN
29
36#define AST_PLUGIN_EXPORT A_DECL_EXPORT
37
42class AST_UTIL_API PluginInstance
43{
44public:
45 virtual ~PluginInstance() = default;
46};
47
49typedef 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
70template<class IFace>
72
76#define AST_DECLARE_INTERFACE(IFace, IID) \
77 template<> struct InterfaceId<IFace> { \
78 static constexpr const char* value() { return IID; } \
79 };
80
82template<class IFace>
83constexpr const char* aInterfaceId()
84{
86}
87
90template<class IFace>
91IFace* aPluginCast(PluginInstance* instance)
92{
93 return dynamic_cast<IFace*>(instance);
94}
95
98{
99 std::string iid{};
100 std::vector<std::string> keys{};
101};
102
105AST_NAMESPACE_END
插件根对象基类
定义 PluginInterface.hpp:43
IFace * aPluginCast(PluginInstance *instance)
把插件根对象转换为指定接口类型
定义 PluginInterface.hpp:91
constexpr const char * aInterfaceId()
获取接口 ID
定义 PluginInterface.hpp:83
接口 ID 特化模板
定义 PluginInterface.hpp:71
插件元数据中的一条 (接口, 索引键) 声明
定义 PluginInterface.hpp:98