18 #ifndef HF_APP_COMMON_H 19 #define HF_APP_COMMON_H 42 static std::map<std::string, ICommand *>
registry;
51 virtual const std::string &
key()
const = 0;
61 virtual const std::string
usage(
bool format =
false)
const = 0;
68 virtual void run(std::vector<std::string> &args) = 0;
82 static void remove(
ICommand *command);
90 static void run(std::string &cmd, std::vector<std::string> &args);
99 static std::ostream &
help(std::ostream &stream);
120 Command(
const char *__key,
const char *__usage):
124 const std::string &
key()
const 129 const std::string
usage(
bool format =
false)
const 133 std::string result =
_usage;
135 for (std::string::size_type pos = 0; (pos = result.find(
":", pos)) != std::string::npos;
138 result.replace(pos, 1,
" : ");
153 #define COMMAND(_name, _key, _help) \ 154 struct Command_## _name: public Command \ 156 Command_##_name(): Command(_key, _help) {} \ 158 void run(std::vector<std::string>&args); \ 160 Command_##_name command##_name; \ 161 void Command_##_name::run(std::vector<std::string>&args) 166 #define COMMAND_ADD(_name) \ 168 ICommand::add(&command##_name); \ 176 #define STRTOL(X) strtol(X.c_str(), NULL, 10); 179 #define STRTOL_HEX(X) strtol(X.c_str(), NULL, 16); const std::string _usage
Command help string.
This is the top level include file for the HAN-FUN library.
static void add(ICommand *command)
Add a command to the registry.
const std::string & key() const
Get the command key.
Example application menu entry API.
const std::string _key
Command key.
const std::string usage(bool format=false) const
Get the command help documentation.
static std::map< std::string, ICommand * > registry
Command registry.
virtual void run(std::vector< std::string > &args)=0
Execute the command code.
Parent class for the commands API implementations.
virtual const std::string & key() const =0
Get the command key.
virtual const std::string usage(bool format=false) const =0
Get the command help documentation.
Command(const char *__key, const char *__usage)
Constructor.
static std::ostream & help(std::ostream &stream)
Generate the help screen, based on the commands in the registry.