2024-11-11 08:29:59 +00:00
|
|
|
#pragma once
|
|
|
|
#include "dispatch.h"
|
|
|
|
#include "cmds_basic.h"
|
|
|
|
|
|
|
|
namespace cmds {
|
|
|
|
template<typename... Types> struct T;
|
2024-11-17 14:08:08 +00:00
|
|
|
|
2024-11-11 08:29:59 +00:00
|
|
|
template<typename Ret, typename... Args> struct T<Ret(Args...)> {
|
|
|
|
template<Inlet::Callable<Ret, Args...> func> struct Cmd {
|
|
|
|
private:
|
|
|
|
QString _name_value;
|
2024-11-17 14:08:08 +00:00
|
|
|
dispatch::Dispatch* core = dispatch::Dispatch::unique();
|
2024-11-20 10:50:44 +00:00
|
|
|
Inlet::CmdsImpl<(void*) func, Ret, Args...> _g_inst;
|
2024-11-11 08:29:59 +00:00
|
|
|
|
|
|
|
public:
|
2024-11-17 14:08:08 +00:00
|
|
|
Cmd(const QString& name) : _name_value(name) {
|
2024-11-20 10:50:44 +00:00
|
|
|
core->registerCmd(_g_inst.address(), &_g_inst);
|
|
|
|
core->setCmdAlias(_g_inst.address(), name);
|
2024-11-11 08:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ret operator()(Args... args) {
|
|
|
|
Inlet::CmdsImpl<(void*) func, Ret, Args...> new_inst(args...);
|
2024-11-17 14:08:08 +00:00
|
|
|
core->runWith(&new_inst);
|
2024-11-11 08:29:59 +00:00
|
|
|
return new_inst.result();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-11-17 14:08:08 +00:00
|
|
|
|
|
|
|
|
2024-11-11 08:29:59 +00:00
|
|
|
template<Inlet::Callable<Ret, Args...> func> struct Event {
|
|
|
|
private:
|
|
|
|
QString _name_value;
|
2024-11-17 14:08:08 +00:00
|
|
|
dispatch::Dispatch* core = dispatch::Dispatch::unique();
|
2024-11-20 10:50:44 +00:00
|
|
|
Inlet::EventsImpl<(void*) func, Ret, Args...> _g_inst;
|
2024-11-11 08:29:59 +00:00
|
|
|
|
|
|
|
public:
|
2024-11-17 14:08:08 +00:00
|
|
|
Event(const QString& name) : _name_value(name) {
|
2024-11-20 10:50:44 +00:00
|
|
|
core->registerEvent(_g_inst.address(), &_g_inst);
|
|
|
|
core->setEventAlias(_g_inst.address(), name);
|
2024-11-11 08:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(Args... args) {
|
2024-11-17 14:08:08 +00:00
|
|
|
Inlet::EventsImpl<(void*) func, Ret, Args...> new_inst(args...);
|
|
|
|
core->notifyWith(&new_inst);
|
2024-11-11 08:29:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|