PenetrateBase/PenetrateBasic/cmds.h

49 lines
1.3 KiB
C
Raw Normal View History

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-11 08:29:59 +00:00
public:
2024-11-17 14:08:08 +00:00
Cmd(const QString& name) : _name_value(name) {
auto g_inst = Inlet::CmdsImpl<(void*) func, Ret, Args...>::unique();
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-11 08:29:59 +00:00
public:
2024-11-17 14:08:08 +00:00
Event(const QString& name) : _name_value(name) {
auto g_inst = Inlet::EventsImpl<(void*)func, Ret, Args...>::unique();
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
}
};
};
}