RXtoRINEX  V2.1
RXtoRINEX provides tools to collect data from GPS / GNSS receivers in mobile devices, convert them to RINEX or RTK formats, and process RINEX files.
Public Member Functions | Friends | List of all members
ArgParser Class Reference

#include <ArgParser.h>

Public Member Functions

 ArgParser (void)
 
 ~ArgParser (void)
 
int addOption (char *, char *, char *, char *, char *)
 
int addOption (char *, char *, char *, char *, bool)
 
int addOperator (char *)
 
bool getBoolOpt (int)
 
string getStrOpt (int)
 
string getOperator (int)
 
void usage (string, string)
 
void parseArgs (int, char **)
 
string showOptValues ()
 
string showOpeValues ()
 

Friends

class Option
 

Detailed Description

ArgParser class defines a data container for options and operators passed as arguments in the command line. A program using ArgParser would perform the following steps after declaring an ArgParser object:

  1. Define each option the program can accept using the addOption method. Data to be provided for each one are:
    • its short name in the form -x (like "-f")
    • its long name in the form –x{x} (like "--file")
    • a word describing the option value (like "INFILE")
    • a explanation for usage of this option (like "binary input file name")
    • default value for the option (like "data.dat" if it is a string, or true if it is boolean)
  2. Define each operand the program can accept using the addOperator method. For each one a default value has to be provided
  3. Process arguments in the command line using the method parseArgs. User should catch any error detected and provide information to user with the usage method
  4. Get values of options using the getBoolOpt or getStrOpt methods, and of operands using getOperator

Constructor & Destructor Documentation

ArgParser::ArgParser ( void  )

Constructs an empty ArgParser object.

ArgParser::~ArgParser ( void  )

Destructs ArgParser objects.

Member Function Documentation

int ArgParser::addOperator ( char *  v)

addOperator adds an operator with the give default string value to the ArgParser object.

Parameters
vdefault value of the operator
Returns
the index assigned to the operator (0 to the 1st, 1 to the 2nd, ...)
int ArgParser::addOption ( char *  s,
char *  l,
char *  d,
char *  u,
char *  sv 
)

addOption adds a string type option to the ArgParser object.

Parameters
sshort name for the option (-x)
llong name for the option (–xxxxx)
da word describing the option value
uan explanation on usage of this option
svdefault string value for the option
Returns
the identification assigned to the option
int ArgParser::addOption ( char *  s,
char *  l,
char *  d,
char *  u,
bool  bv 
)

addOption adds a boolean type option to the ArgParser object.

Parameters
sshort name for the option (-x)
llong name for the option (–xxxxx)
da word describing the option value
uan explanation on usage of this option. Note that if default value is positive, explanation has to be stated in negative terms, like "Don't ..."
bvdefault boolean value for the option
Returns
the identification assigned to the option
bool ArgParser::getBoolOpt ( int  id)

getBoolOpt gets the current value of the boolean type option with the given identification.

Parameters
ididentification of the option
Returns
the current value of the option requested
Exceptions
errorstring with message, when it cannot find the option
string ArgParser::getOperator ( int  index)

getOperator gets the value of the string operator located in the given index.

Parameters
indexof the operator requested in the operators vector (0 to the 1st, 1 to the 2nd, ...)
Returns
the current string value of the operator requested
Exceptions
errorstring with a message, when the operator does not exist
string ArgParser::getStrOpt ( int  id)

getStrOpt gets the current value of the string type option with the given identification.

Parameters
ididentification of the option
Returns
the current value of the option requested
Exceptions
errorstring with message, when it cannot find the option
void ArgParser::parseArgs ( int  argc,
char **  argv 
)

parseArgs parses the argument list extracting Options and Operands to the ArgParser container. Parsing starts from argv[1], and stops when the last argument is parsed or an error is detected. Correct options and / or operands parsed from correct arguments are stored in the ArgParser object. When error is detected the parsing stops, and an exception is raised. The caller shall catch it.

Parameters
argcnumber of arguments passed (as per main)
argvthe command line argument as provided to the program
Exceptions
errorstring with a message describing the argument error
string ArgParser::showOpeValues ( )

showOpeValues provides the values of operators.

Returns
a text description with the current values of operators
string ArgParser::showOptValues ( )

showOptValues provides a text description of options and their current values.

Returns
a text description with name and value of options
void ArgParser::usage ( string  message,
string  howUse 
)

usage provides information through cerr on usage using data from the options definition.

Parameters
messageargument error to be displayed
howUsetext describing how to use the command line

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