Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Interference_Simple StrCommandHandler_Demo
StrCommandHandler.h
00001 #ifndef STR_COMMAND_HANDLER_H 00002 #define STR_COMMAND_HANDLER_H 00003 #include "mbed.h" 00004 #include <string> 00005 00006 /** Maps strings and functions 00007 * 00008 * This class can map strings(commands) and functions receiving no arguments 00009 * returning int. 00010 */ 00011 class StrCommandHandler 00012 { 00013 public: 00014 StrCommandHandler( 00015 int const arg_num_ofcommand = 10 00016 ); 00017 00018 /** Maps strings and functions 00019 * 00020 * This maps strings(commands) and functions receiving own command, 00021 * returning something of pointer. 00022 */ 00023 void map( 00024 const char * const arg_command, 00025 void * (*arg_pfunc)(const char * const) 00026 ); 00027 00028 /** Analyzes a command input and executs a function corresponding to it. 00029 * 00030 * This analyzes a string(commands) and executs a corresponding function. 00031 * If an error occur, the function returns an error code 00032 * Error code: 00033 * - Exception of NULL pointer returns 0xFFFFFFFF 00034 * - Exception of Null character returna 0xFFFFFFFE 00035 * - Exception of Over length returns 0xFFFFFFFD 00036 * - Exception of Not registered Command returns 0xFFFFFFFC; 00037 */ 00038 void * exe( 00039 const char* const arg_command 00040 ); 00041 00042 /** Lists commands registered 00043 * 00044 * This lists commands registered by users. 00045 */ 00046 void list(); 00047 00048 00049 static char const * const ARROW_UP; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x41 00050 static char const * const ARROW_DOWN; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x42 00051 static char const * const ARROW_RIGHT; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x43 00052 static char const * const ARROW_LEFT; /// ascii code series arrow-up symbol 0x1b 0x5b, 0x44 00053 00054 private: 00055 /** Array of commands' name 00056 * 00057 * The length should be within 15 without last '\0' 00058 * The number of the array is (int)m_numofcommands 00059 */ 00060 char (*m_command_name)[16]; 00061 00062 /** Array of pointers to functions 00063 * 00064 * The number of the array is (int)m_numofcommands 00065 */ 00066 void * (**m_function)(const char * const); 00067 00068 /** Numbers of commands registered in this. 00069 * 00070 * If commands are registered over this value, 00071 * this value increase by 5, and arrays get reallocated. 00072 */ 00073 int m_num_ofcommands; 00074 00075 /** Result code of exe() 00076 * 00077 * This is supposed to be offered by pointer 00078 */ 00079 int m_rescode; 00080 }; 00081 #endif
Generated on Tue Jul 12 2022 23:49:56 by
1.7.2