slight rework of RegisterPlugin (leave a pointer to the plugin info instead of a useless bool)

master
Zithia Satazaki 2022-03-28 18:15:32 -04:00
parent 5f1b9d03b4
commit 5385740516
4 changed files with 9 additions and 13 deletions

4
notes
View File

@ -35,8 +35,8 @@ TODO {
about-license info about-license info
} }
rework RegisterPlugin slightly to automatically give a file-scope access to the PluginInfo - rework RegisterPlugin slightly to automatically give a file-scope access to the PluginInfo
^ use in graph - ^ use in graph
- pool I guess - pool I guess

View File

@ -31,11 +31,11 @@ namespace { // clazy:excludeall=non-pod-global-static
}; };
} }
bool PluginRegistry::enqueueRegistration(std::function<void ()> f) { std::shared_ptr<PluginInfo> PluginRegistry::enqueueRegistration(std::function<void ()> f) {
auto& queue = regQueue(); auto& queue = regQueue();
queue.push_back(f); queue.push_back(f);
if (initialized()) f(); if (initialized()) f();
return true; return nullptr;
} }
void PluginRegistry::init() { void PluginRegistry::init() {

View File

@ -29,7 +29,7 @@ namespace Xybrid::Config {
}; };
namespace PluginRegistry { namespace PluginRegistry {
bool enqueueRegistration(std::function<void()>); std::shared_ptr<PluginInfo> enqueueRegistration(std::function<void()>);
void registerPlugin(std::shared_ptr<PluginInfo>); void registerPlugin(std::shared_ptr<PluginInfo>);
void init(); void init();
@ -39,7 +39,7 @@ namespace Xybrid::Config {
} }
#define RegisterPlugin(NAME, ...) \ #define RegisterPlugin(NAME, ...) \
namespace { bool _x___reg_##NAME = Xybrid::Config::PluginRegistry::enqueueRegistration([] { \ namespace { std::shared_ptr<Xybrid::Config::PluginInfo> _regInfo_##NAME = Xybrid::Config::PluginRegistry::enqueueRegistration([] { \
auto i = std::make_shared<Xybrid::Config::PluginInfo>();\ auto i = std::make_shared<Xybrid::Config::PluginInfo>();\
i->createInstance = []{ return std::make_shared<NAME>(); };\ i->createInstance = []{ return std::make_shared<NAME>(); };\
__VA_ARGS__ \ __VA_ARGS__ \

View File

@ -15,20 +15,16 @@ using namespace Xybrid::Config;
#include <QMetaType> #include <QMetaType>
#include <QMetaEnum> #include <QMetaEnum>
namespace { // clazy:excludeall=non-pod-global-static // clazy:excludeall=non-pod-global-static
std::shared_ptr<PluginInfo> inf;
}
RegisterPlugin(Graph, { RegisterPlugin(Graph, {
i->id = "graph"; i->id = "graph";
i->displayName = "Subgraph"; i->displayName = "Subgraph";
inf = i;
}) })
//std::string Graph::pluginName() const { return "Subgraph"; } //std::string Graph::pluginName() const { return "Subgraph"; }
Graph::Graph() { Graph::Graph() {
plugin = inf; // harder bind plugin = _regInfo_Graph;//inf; // harder bind
} }
// propagate // propagate
@ -119,7 +115,7 @@ void Graph::onParent(std::shared_ptr<Graph>) {
for (auto c : children) { for (auto c : children) {
c->project = project; c->project = project;
// let this handle the recursion for us, since this is all this function does // let this handle the recursion for us, since this is all this function does
if (c->plugin == inf) c->onParent(c->parent.lock()); if (c->plugin == _regInfo_Graph) c->onParent(c->parent.lock());
} }
} }