48 lines
1.2 KiB
C
48 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...)> {
|
||
|
public:
|
||
|
template<Inlet::Callable<Ret, Args...> func> struct Cmd {
|
||
|
private:
|
||
|
dispatch::Dispatch* _core_bind;
|
||
|
QString _name_value;
|
||
|
|
||
|
public:
|
||
|
Cmd(dispatch::Dispatch* core, const QString& name)
|
||
|
: _core_bind(core), _name_value(name) {
|
||
|
auto inst = Inlet::CmdsImpl<(void*) func, Ret, Args...>::global();
|
||
|
core->registerCmd(inst->address(), inst, name);
|
||
|
}
|
||
|
|
||
|
Ret operator()(Args... args) {
|
||
|
Inlet::CmdsImpl<(void*) func, Ret, Args...> new_inst(args...);
|
||
|
_core_bind->runWith(&new_inst);
|
||
|
return new_inst.result();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
template<Inlet::Callable<Ret, Args...> func> struct Event {
|
||
|
private:
|
||
|
dispatch::Dispatch* _core_bind;
|
||
|
QString _name_value;
|
||
|
|
||
|
public:
|
||
|
Event(dispatch::Dispatch* core, const QString& name)
|
||
|
: _core_bind(core), _name_value(name) {
|
||
|
auto inst = Inlet::EventsImpl<(void*) func, Ret, Args...>::global();
|
||
|
core->registerEvent(inst->address(), inst, name);
|
||
|
}
|
||
|
|
||
|
void operator()(Args... args) {
|
||
|
Inlet::EventsImpl<(void*)func, Ret, Args...> new_inst(args...);
|
||
|
_core_bind->notifyWith(&new_inst);
|
||
|
}
|
||
|
};
|
||
|
};
|
||
|
|
||
|
}
|