49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#pragma once
|
|
#include "dispatch.h"
|
|
#include "cmds_basic.h"
|
|
|
|
namespace cmds {
|
|
template<typename... Types> struct T;
|
|
|
|
template<typename Ret, typename... Args> struct T<Ret(Args...)> {
|
|
template<Inlet::Callable<Ret, Args...> func> struct Cmd {
|
|
private:
|
|
QString _name_value;
|
|
dispatch::Dispatch* core = dispatch::Dispatch::unique();
|
|
Inlet::CmdsImpl<(void*) func, Ret, Args...> _g_inst;
|
|
|
|
public:
|
|
Cmd(const QString& name) : _name_value(name) {
|
|
core->registerCmd(_g_inst.address(), &_g_inst);
|
|
core->setCmdAlias(_g_inst.address(), name);
|
|
}
|
|
|
|
Ret operator()(Args... args) {
|
|
Inlet::CmdsImpl<(void*) func, Ret, Args...> new_inst(args...);
|
|
core->runWith(&new_inst);
|
|
return new_inst.result();
|
|
}
|
|
};
|
|
|
|
|
|
|
|
template<Inlet::Callable<Ret, Args...> func> struct Event {
|
|
private:
|
|
QString _name_value;
|
|
dispatch::Dispatch* core = dispatch::Dispatch::unique();
|
|
Inlet::EventsImpl<(void*) func, Ret, Args...> _g_inst;
|
|
|
|
public:
|
|
Event(const QString& name) : _name_value(name) {
|
|
core->registerEvent(_g_inst.address(), &_g_inst);
|
|
core->setEventAlias(_g_inst.address(), name);
|
|
}
|
|
|
|
void operator()(Args... args) {
|
|
Inlet::EventsImpl<(void*) func, Ret, Args...> new_inst(args...);
|
|
core->notifyWith(&new_inst);
|
|
}
|
|
};
|
|
};
|
|
}
|