#pragma once #include class Args { private: String *str; public: Args(String *str) : str(str) {} operator const char*() const { return str->c_str(); } String operator[](int pos) { char buf[64]; strncpy(buf, str->c_str(), sizeof(buf)); char *args = strtok(buf, " "); while (pos > 0 && args != NULL) { args = strtok(NULL, " "); pos--; } if (args == NULL) { return String(); } return String(args); } }; struct Task; struct Command { using Executor = void(Task::*)(Args&, Print&); template 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(const char* name, Executor func) : name(name), func(func) {} template Command(const char* name, MemberExecutor func) : name(name), func(static_cast(func)) {} };