Easy-to-use command line argument parser. More...
#include <command_line_arg_parser.h>

Public Member Functions | |
| CCommandLineArgParser () | |
| Class constructor.  More... | |
| virtual | ~CCommandLineArgParser () | 
| Class destructor.  More... | |
| void | AddFlag (char ch_short_option, const std::string &str_long_option, const std::string &str_description, bool &b_flag) | 
| Adds a flag to the parser.  More... | |
| template<typename T > | |
| void | AddArgument (char ch_short_option, const std::string &str_long_option, const std::string &str_description, T &t_buffer) | 
| Adds an argument to the parser.  More... | |
| virtual void | PrintUsage (CARGoSLog &c_log) | 
| Prints the arguments on the log.  More... | |
| virtual void | Parse (SInt32 n_argc, char **ppch_argv) | 
| Parses the arguments on the command line.  More... | |
Easy-to-use command line argument parser.
Example: you want to parse
$ program --flag --arg1 intvalue --arg2 stringvalue # GNU-style $ program -f -1 intvalue -2 stringvalue # short style
The code to do it:
int main(int argc, char** argv) { bool bIsFlag; // will be true if the flag was specified, false otherwise UInt32 unIntValue; // stores th parsed intvalue std::string strValue; // stores the parsed stringvalue
    // Create the parser
    CCommandLineArgParser cCLAP;
    // Add the flag
    cCLAP.AddFlag(
      'f',
      "--flag",
      "This is a flag",
      bIsFlag);
    // Add the int argument
    cCLAP.AddArgument<UInt32>(
      '1',
      "--arg1",
      "This is an int value",
      unIntValue);
    // Add the string argument
    cCLAP.AddArgument<std::string>(
      '2',
      "--arg2",
      "This is a string value",
      strValue);    // Parse the command line!
    // In case of errors, a CARGoSException is thrown
    try {
      cCLAP.Parse(argc, argv);
    }
    catch(CARGoSException& ex) {
      LOGERR << "Error: " << ex.what() << std::endl;
    }
 
Definition at line 90 of file command_line_arg_parser.h.
| argos::CCommandLineArgParser::CCommandLineArgParser | ( | ) | 
Class constructor.
Definition at line 15 of file command_line_arg_parser.cpp.
      
  | 
  virtual | 
Class destructor.
Definition at line 22 of file command_line_arg_parser.cpp.
      
  | 
  inline | 
Adds an argument to the parser.
| ch_short_option | A single character for the short option | 
| str_long_option | The long option | 
| str_description | The description shown by PrintUsage() | 
| t_buffer | The buffer variable to associate to this entry | 
Definition at line 132 of file command_line_arg_parser.h.
      
  | 
  inline | 
Adds a flag to the parser.
| ch_short_option | A single character for the short option | 
| str_long_option | The long option | 
| str_description | The description shown by PrintUsage() | 
| b_flag | The boolean variable to associate to this entry | 
Definition at line 111 of file command_line_arg_parser.h.
      
  | 
  virtual | 
Parses the arguments on the command line.
| n_argc | The number of arguments to parse | 
| ppch_argv | The string array containing the command line | 
Reimplemented in argos::CARGoSCommandLineArgParser.
Definition at line 48 of file command_line_arg_parser.cpp.
      
  | 
  virtual | 
Prints the arguments on the log.
If you want a better layout, you need to extend this method.
| c_log | The destination log: LOG or LOGERR | 
Reimplemented in argos::CARGoSCommandLineArgParser.
Definition at line 32 of file command_line_arg_parser.cpp.