add const context function execution for shell
This commit is contained in:
parent
3cb16a2279
commit
26e6c4012f
|
@ -58,7 +58,9 @@ class Shell {
|
|||
* Built-in commands have their own execute functions inside the shell
|
||||
*/
|
||||
enum e_exec_func_type {
|
||||
CONST_STANDARD,
|
||||
STANDARD,
|
||||
CONST_SHORT,
|
||||
SHORT,
|
||||
BUILTIN,
|
||||
MACRO,
|
||||
|
@ -93,8 +95,12 @@ class Shell {
|
|||
* 4. Marco function, which directly call a macro function without command parsing
|
||||
* Users just need to specify the function object and its type will be automatically inferred
|
||||
*/
|
||||
void set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(const T&, const Command&, const CommandContext&)> exec_func);
|
||||
void set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(T&, const Command&, const CommandContext&)> exec_func);
|
||||
void set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(const T&)> exec_func);
|
||||
void set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(T&)> exec_func);
|
||||
void set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
|
@ -156,8 +162,10 @@ class Shell {
|
|||
* 3. Built-in function, including only the shell envoriment variables
|
||||
* 4. Marco function, which directly call a macro function without command parsing
|
||||
*/
|
||||
vtr::vector<ShellCommandId, std::function<void(const T&, const Command&, const CommandContext&)>> command_const_execute_functions_;
|
||||
vtr::vector<ShellCommandId, std::function<void(T&, const Command&, const CommandContext&)>> command_standard_execute_functions_;
|
||||
vtr::vector<ShellCommandId, std::function<void(T&)>> command_short_execute_functions_;
|
||||
vtr::vector<ShellCommandId, std::function<void(const T&)>> command_short_const_execute_functions_;
|
||||
vtr::vector<ShellCommandId, std::function<void(T&)>> command_short_execute_functions_;
|
||||
vtr::vector<ShellCommandId, std::function<void()>> command_builtin_execute_functions_;
|
||||
vtr::vector<ShellCommandId, std::function<int(int, const char**)>> command_macro_execute_functions_;
|
||||
|
||||
|
|
|
@ -125,7 +125,9 @@ ShellCommandId Shell<T>::add_command(const Command& cmd, const char* descr) {
|
|||
command_description_.push_back(descr);
|
||||
command_classes_.push_back(ShellCommandClassId::INVALID());
|
||||
command_execute_function_types_.emplace_back();
|
||||
command_const_execute_functions_.emplace_back();
|
||||
command_standard_execute_functions_.emplace_back();
|
||||
command_short_const_execute_functions_.emplace_back();
|
||||
command_short_execute_functions_.emplace_back();
|
||||
command_builtin_execute_functions_.emplace_back();
|
||||
command_macro_execute_functions_.emplace_back();
|
||||
|
@ -150,6 +152,14 @@ void Shell<T>::set_command_class(const ShellCommandId& cmd_id, const ShellComman
|
|||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(const T&, const Command&, const CommandContext&)> exec_func) {
|
||||
VTR_ASSERT(true == valid_command_id(cmd_id));
|
||||
command_execute_function_types_[cmd_id] = CONST_STANDARD;
|
||||
command_standard_execute_functions_[cmd_id] = exec_func;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(T&, const Command&, const CommandContext&)> exec_func) {
|
||||
|
@ -158,6 +168,14 @@ void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
|
|||
command_standard_execute_functions_[cmd_id] = exec_func;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(const T&)> exec_func) {
|
||||
VTR_ASSERT(true == valid_command_id(cmd_id));
|
||||
command_execute_function_types_[cmd_id] = CONST_SHORT;
|
||||
command_short_execute_functions_[cmd_id] = exec_func;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Shell<T>::set_command_execute_function(const ShellCommandId& cmd_id,
|
||||
std::function<void(T&)> exec_func) {
|
||||
|
@ -379,9 +397,15 @@ void Shell<T>::execute_command(const char* cmd_line,
|
|||
|
||||
/* Execute the command depending on the type of function ! */
|
||||
switch (command_execute_function_types_[cmd_id]) {
|
||||
case CONST_STANDARD:
|
||||
command_const_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]);
|
||||
break;
|
||||
case STANDARD:
|
||||
command_standard_execute_functions_[cmd_id](common_context, commands_[cmd_id], command_contexts_[cmd_id]);
|
||||
break;
|
||||
case CONST_SHORT:
|
||||
command_short_const_execute_functions_[cmd_id](common_context);
|
||||
break;
|
||||
case SHORT:
|
||||
command_short_execute_functions_[cmd_id](common_context);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue