figments: command: rewrite command api to use Task instances instead of static functions
This commit is contained in:
@ -1,7 +1,2 @@
|
||||
#include "./Command.h"
|
||||
|
||||
void
|
||||
doNothing(Args& args, Print& printer)
|
||||
{}
|
||||
|
||||
Command::Command() : func(doNothing) {}
|
||||
|
@ -21,13 +21,25 @@ class Args {
|
||||
}
|
||||
};
|
||||
|
||||
struct CommandList;
|
||||
struct Task;
|
||||
|
||||
struct Command {
|
||||
using Executor = std::function<void(Args&, Print& output)>;
|
||||
Executor func;
|
||||
const char* name = NULL;
|
||||
using Executor = void(Task::*)(Args&, Print&);
|
||||
|
||||
template<typename T>
|
||||
using MemberExecutor = void(T::*)(Args&, Print&);
|
||||
|
||||
const char* name = NULL;
|
||||
Executor func = NULL;
|
||||
|
||||
void invoke(Task* task, Args& args, Print& printer) const {
|
||||
if (func) {
|
||||
(*task.*func)(args, printer);
|
||||
}
|
||||
}
|
||||
|
||||
Command();
|
||||
Command(const char* name, Executor func) : name(name), func(func) {}
|
||||
|
||||
template<class T>
|
||||
Command(const char* name, MemberExecutor<T> func) : name(name), func(static_cast<Executor>(func)) {}
|
||||
};
|
||||
|
Reference in New Issue
Block a user