diff --git a/Sming/Libraries/CommandProcessing/src/CommandProcessing/Command.h b/Sming/Libraries/CommandProcessing/src/CommandProcessing/Command.h index b0562f653f..2c7394998f 100644 --- a/Sming/Libraries/CommandProcessing/src/CommandProcessing/Command.h +++ b/Sming/Libraries/CommandProcessing/src/CommandProcessing/Command.h @@ -47,8 +47,6 @@ struct Info { */ using Callback = Delegate; -#ifdef CMDPROC_FLASHSTRINGS - operator bool() const { return strings; @@ -61,27 +59,17 @@ struct Info { String get(StringIndex index) const { +#ifdef CMDPROC_FLASHSTRINGS return strings ? CStringArray(*strings)[unsigned(index)] : nullptr; +#else + return strings[unsigned(index)]; +#endif } +#ifdef CMDPROC_FLASHSTRINGS const FlashString* strings{}; - #else - - operator bool() const - { - return name; - } - - bool operator==(const String& name) const - { - return name == this->name; - } - - String name; - String help; - String group; - + CStringArray strings; #endif Callback callback; @@ -100,9 +88,6 @@ class Command : public Info { } - Command(const Info& info) : Info(info), name{*this}, help{*this}, group{*this} - { - } #else /** Instantiate a command delegate using set of wiring Strings * @param name Command name - the text a user types to invoke the command @@ -110,30 +95,20 @@ class Command : public Info * @param group The command group to which this command belongs * @param callback Delegate that should be invoked (triggered) when the command is entered by a user */ - Command(String name, String help, String group, Callback callback) : Info{name, help, group, callback} - { - } - - Command(const Info& info) : Info(info) + Command(const String& name, const String& help, const String& group, Callback callback) + : Command({nullptr, callback}) { + strings.reserve(name.length() + help.length() + group.length() + 3); + strings += name; + strings += help; + strings += group; } #endif - /** - * @brief Invoke registered callback - * @retval bool false if no callback registered - */ - bool operator()(String commandLine, ReadWriteStream& commandOutput) const + Command(const Info& info) : Info(info), name{*this}, help{*this}, group{*this} { - if(!callback) { - return false; - } - - callback(commandLine, commandOutput); - return true; } -#ifdef CMDPROC_FLASHSTRINGS /** * @brief Helper class for accessing individual strings */ @@ -149,7 +124,6 @@ class Command : public Info const StringAccessor name; const StringAccessor help; const StringAccessor group; -#endif }; } // namespace CommandProcessing diff --git a/Sming/Libraries/CommandProcessing/src/CommandProcessing/Handler.cpp b/Sming/Libraries/CommandProcessing/src/CommandProcessing/Handler.cpp index 1c5b0ff2b3..a5d82f487f 100644 --- a/Sming/Libraries/CommandProcessing/src/CommandProcessing/Handler.cpp +++ b/Sming/Libraries/CommandProcessing/src/CommandProcessing/Handler.cpp @@ -136,7 +136,7 @@ bool Handler::registerCommand(const Command& command) return false; } - registeredCommands.addElement(new Info{command}); + registeredCommands.add(command); debug_d("[CH] Command '%s' registered", name.c_str()); return true; }