This class can map strings(commands) and functions receiving no arguments returning an int value.

Dependents:   Interference_Simple StrCommandHandler_Demo

Committer:
aktk
Date:
Thu Oct 31 02:48:35 2019 +0000
Revision:
0:024213917a9f
Child:
1:1d46d90eb7bf
first publish;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 0:024213917a9f 1 #ifndef STR_COMMAND_HANDLER_H
aktk 0:024213917a9f 2 #define STR_COMMAND_HANDLER_H
aktk 0:024213917a9f 3 #include "mbed.h"
aktk 0:024213917a9f 4 #include <string>
aktk 0:024213917a9f 5
aktk 0:024213917a9f 6 /** Maps strings and functions
aktk 0:024213917a9f 7 *
aktk 0:024213917a9f 8 * This class can map strings(commands) and functions receiving no arguments
aktk 0:024213917a9f 9 * returning int.
aktk 0:024213917a9f 10 */
aktk 0:024213917a9f 11 class StrCommandHandler
aktk 0:024213917a9f 12 {
aktk 0:024213917a9f 13 public:
aktk 0:024213917a9f 14 StrCommandHandler(
aktk 0:024213917a9f 15 int const arg_num_ofcommand = 10
aktk 0:024213917a9f 16 );
aktk 0:024213917a9f 17
aktk 0:024213917a9f 18 int map(
aktk 0:024213917a9f 19 const char * const arg_command,
aktk 0:024213917a9f 20 int (*arg_pfunc)(void)
aktk 0:024213917a9f 21 );
aktk 0:024213917a9f 22
aktk 0:024213917a9f 23 int exe(
aktk 0:024213917a9f 24 const char* const arg_command
aktk 0:024213917a9f 25 );
aktk 0:024213917a9f 26
aktk 0:024213917a9f 27 void list();
aktk 0:024213917a9f 28
aktk 0:024213917a9f 29 template<typename T>
aktk 0:024213917a9f 30 T analyzeValue(
aktk 0:024213917a9f 31 const char* const arg_value_str
aktk 0:024213917a9f 32 );
aktk 0:024213917a9f 33
aktk 0:024213917a9f 34 private:
aktk 0:024213917a9f 35 /** Array of commands' name
aktk 0:024213917a9f 36 *
aktk 0:024213917a9f 37 * The length should be within 15 without last '\0'
aktk 0:024213917a9f 38 */
aktk 0:024213917a9f 39 char (*m_command_name)[16];
aktk 0:024213917a9f 40
aktk 0:024213917a9f 41 /** Array of pointers to functions
aktk 0:024213917a9f 42 *
aktk 0:024213917a9f 43 * The length should be within 15 without last '\0'
aktk 0:024213917a9f 44 */
aktk 0:024213917a9f 45 int (**m_function)(void);
aktk 0:024213917a9f 46
aktk 0:024213917a9f 47 /** Numbers of commands registered in this.
aktk 0:024213917a9f 48 *
aktk 0:024213917a9f 49 * If commands are registered over this value,
aktk 0:024213917a9f 50 * this value increase by 5, and arrays get reallocated.
aktk 0:024213917a9f 51 */
aktk 0:024213917a9f 52 int m_num_ofcommands;
aktk 0:024213917a9f 53 };
aktk 0:024213917a9f 54 #endif