Akifumi Takahashi / StrCommandHandler

Dependents:   Interference_Simple StrCommandHandler_Demo

Revision:
0:024213917a9f
Child:
1:1d46d90eb7bf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/StrCommandHandler.h	Thu Oct 31 02:48:35 2019 +0000
@@ -0,0 +1,54 @@
+#ifndef STR_COMMAND_HANDLER_H
+#define STR_COMMAND_HANDLER_H
+#include "mbed.h"
+#include <string>
+
+/** Maps strings and functions
+ *
+ *  This class can map strings(commands) and functions receiving no arguments
+ *  returning int.
+ */
+class StrCommandHandler
+{
+public:
+    StrCommandHandler(
+        int const arg_num_ofcommand = 10
+    );
+
+    int map(
+        const char * const   arg_command,
+        int (*arg_pfunc)(void)
+    );
+
+    int exe(
+        const char* const   arg_command
+    );
+
+    void list();
+
+    template<typename T>
+    T analyzeValue(
+        const char* const   arg_value_str
+    );
+
+private:
+    /** Array of commands' name
+     *
+     *   The length should be within 15 without last '\0'
+     */
+    char (*m_command_name)[16];
+
+    /** Array of pointers to functions
+     *
+     *   The length should be within 15 without last '\0'
+     */
+    int (**m_function)(void);
+
+    /** Numbers of commands registered in this.
+     *
+     *  If commands are registered over this value,
+     *  this value increase by 5, and arrays get reallocated.
+     */
+    int m_num_ofcommands;
+};
+#endif
\ No newline at end of file