-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandLineEngine.h
76 lines (54 loc) · 2 KB
/
CommandLineEngine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef __COMMANDLINE_COMMANDLINEENGINE__
#define __COMMANDLINE_COMMANDLINEENGINE__
#undef min
#undef max
#include <vector>
namespace CommandEngine {
class CommandLineEngine
{
public:
enum FunctionFlags {
FF_HelpText, // The function was called by the help function
FF_Normal // The function was called normally
};
// User function definition:
// [IN] Print *: never is null. If no printer is specified a nullprinter will be sent which will
// consume the bytes without any output.
// [IN] Tokens &: The command tokenized and macros expanded for you
// [IN] FunctionFlags: One of flags defined in the enum FunctionFlags
typedef void (*UserFunction)(Print *, Tokens &, FunctionFlags);
// Register your function with the class
void registerFunction( String funcName, UserFunction func );
// Allow you to register a macro from code
void registerMacro( String macroName, String value );
// Call this when a string needs to be executed.
// [IN] String cmdLine: the string of text that you want processed
// [IN] Print * printer: the class that will act as your output. If not specified
// a NullPrinter will be used instead. (see the cpp file for more info)
bool execute( String cmdLine, Print * printer = nullptr );
protected:
// Internal Commands
// They could be defined in the mUserFunctions but makes it much harder
// as they need to access internal data structures
void help(Print * printer, Tokens & tk, FunctionFlags ff);
void set(Print * printer, Tokens & tk, FunctionFlags ff);
// Helpers
void doMacros(Tokens & tk);
struct UserFunctionDef {
String name;
UserFunction func;
};
struct UserMacroDef {
String name; // Stored without the dollar sign
String value;
};
typedef std::vector< UserFunctionDef > UserFunctions;
typedef std::vector< UserMacroDef > UserMacros;
UserFunctions mUserFunctions;
UserMacros mUserMacros;
// Helper Functinos for the vectors
UserMacros::iterator findMacro(String txt);
UserFunctions::iterator findFunction(String txt);
};
};
#endif