HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
Command Class Reference

Parent class for the commands API implementations. More...

#include <common.h>

+ Inheritance diagram for Command:
+ Collaboration diagram for Command:

Public Member Functions

 Command (const char *__key, const char *__usage)
 Constructor. More...
 
const std::string & key () const
 Get the command key. More...
 
const std::string usage (bool format=false) const
 Get the command help documentation. More...
 
- Public Member Functions inherited from ICommand
virtual void run (std::vector< std::string > &args)=0
 Execute the command code. More...
 

Protected Attributes

const std::string _key
 Command key. More...
 
const std::string _usage
 Command help string. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ICommand
static void add (ICommand *command)
 Add a command to the registry. More...
 
static void remove (ICommand *command)
 Remove a command to the registry. More...
 
static void run (std::string &cmd, std::vector< std::string > &args)
 Find and run the command with the given key, using the arguments in args. More...
 
static std::ostream & help (std::ostream &stream)
 Generate the help screen, based on the commands in the registry. More...
 
- Static Protected Attributes inherited from ICommand
static std::map< std::string, ICommand * > registry
 Command registry.
 

Detailed Description

Parent class for the commands API implementations.

Definition at line 105 of file apps/common.h.

Constructor & Destructor Documentation

◆ Command()

Command::Command ( const char *  __key,
const char *  __usage 
)
inline

Constructor.

Parameters
__keycommand key.
__usagecommand help string.

Definition at line 120 of file apps/common.h.

120  :
121  _key(__key), _usage(__usage)
122  {}
const std::string _usage
Command help string.
Definition: apps/common.h:110
const std::string _key
Command key.
Definition: apps/common.h:109

Member Function Documentation

◆ key()

const std::string& Command::key ( ) const
inlinevirtual

Get the command key.

Returns
the string that represents the command key.

Implements ICommand.

Definition at line 124 of file apps/common.h.

References _key.

125  {
126  return _key;
127  }
const std::string _key
Command key.
Definition: apps/common.h:109

◆ usage()

const std::string Command::usage ( bool  format = false) const
inlinevirtual

Get the command help documentation.

Parameters
[in]formatif true the usage string SHOULD be formatted to be displayed to the user.
Returns
command help documentation.

Implements ICommand.

Definition at line 129 of file apps/common.h.

References _usage.

130  {
131  if (format)
132  {
133  std::string result = _usage;
134 
135  for (std::string::size_type pos = 0; (pos = result.find(":", pos)) != std::string::npos;
136  pos += 3 - 1)
137  {
138  result.replace(pos, 1, " : ");
139  }
140 
141  return result;
142  }
143  else
144  {
145  return _usage;
146  }
147  }
const std::string _usage
Command help string.
Definition: apps/common.h:110

Field Documentation

◆ _key

const std::string Command::_key
protected

Command key.

Definition at line 109 of file apps/common.h.

Referenced by key().

◆ _usage

const std::string Command::_usage
protected

Command help string.

Definition at line 110 of file apps/common.h.

Referenced by usage().


The documentation for this class was generated from the following file: