Aria  2.8.0
ArArgumentParser Class Reference

Parse and store program command-line arguments for use by other ARIA classes. More...

#include <ArArgumentParser.h>

Public Member Functions

void addDefaultArgument (const char *argument, int position=-1)
 Adds a string as a default argument.
 
void addDefaultArgumentAsIs (const char *argument, int position=-1)
 Adds a string as a default argument as is (without touching spaces or what not)
 
 ArArgumentParser (int *argc, char **argv)
 Constructor, takes the argc argv. More...
 
 ArArgumentParser (ArArgumentBuilder *builder)
 Constructor, takes an argument builder. More...
 
bool checkArgument (const char *argument)
 Returns true if the argument was found. More...
 
bool checkArgumentVar (const char *argument,...)
 Returns true if the argument was found. More...
 
bool checkHelpAndWarnUnparsed (unsigned int numArgsOkay=0)
 Checks for the help strings and warns about unparsed arguments. More...
 
char * checkParameterArgument (const char *argument, bool returnFirst=false)
 Returns the word/argument after given argument. More...
 
bool checkParameterArgumentBool (const char *argument, bool *dest, bool *wasReallySet=NULL, bool returnFirst=false)
 Returns the word/argument after given argument. More...
 
bool checkParameterArgumentBoolVar (bool *wasReallySet, bool *dest, const char *argument,...)
 Returns the word/argument after given argument. More...
 
bool checkParameterArgumentDouble (const char *argument, double *dest, bool *wasReallySet=NULL, bool returnFirst=false)
 Returns the floating point number after given argument. More...
 
bool checkParameterArgumentDoubleVar (bool *wasReallySet, double *dest, const char *argument,...)
 Returns the double after given argument. More...
 
bool checkParameterArgumentFloat (const char *argument, float *dest, bool *wasReallySet=NULL, bool returnFirst=false)
 Returns the floating point number after given argument. More...
 
bool checkParameterArgumentFloatVar (bool *wasReallySet, float *dest, const char *argument,...)
 Returns the float after given argument. More...
 
bool checkParameterArgumentInteger (const char *argument, int *dest, bool *wasReallySet=NULL, bool returnFirst=false)
 Returns the integer after given argument. More...
 
bool checkParameterArgumentIntegerVar (bool *wasReallySet, int *dest, const char *argument,...)
 Returns the integer after given argument. More...
 
bool checkParameterArgumentString (const char *argument, const char **dest, bool *wasReallySet=NULL, bool returnFirst=false)
 Returns the word/argument after given argument. More...
 
bool checkParameterArgumentStringVar (bool *wasReallySet, const char **dest, const char *argument,...)
 Returns the word/argument after given argument. More...
 
char * checkParameterArgumentVar (const char *argument,...)
 Returns the word/argument after given argument. More...
 
const char * getArg (size_t whichArg) const
 Gets a specific argument.
 
size_t getArgc (void) const
 Gets how many arguments are left in this parser.
 
const ArArgumentBuildergetArgumentBuilder (void) const
 Gets the argument builder, if one is being used (may be NULL)
 
char ** getArgv (void) const
 Gets the argv.
 
const char * getStartingArguments (void) const
 Gets the arguments this parser started with (if possible, NULL otherwise)
 
bool getWasReallySetOnlyTrue (void)
 If we only set wasReallySet to true. More...
 
void loadDefaultArguments (int positon=1)
 Adds args from default files and environmental variables. More...
 
void log (void) const
 Prints out the arguments left in this parser.
 
void removeArg (size_t which)
 Internal function to remove an argument that was parsed.
 
void setWasReallySetOnlyTrue (bool wasReallySetOnlyTrue)
 If we should only set wasReallySet to true. More...
 
 ~ArArgumentParser ()
 Destructor.
 

Static Public Member Functions

static void addDefaultArgumentEnv (const char *env)
 Adds another file or environmental variable to the list of defaults. More...
 
static void addDefaultArgumentFile (const char *file)
 Adds another file or environmental variable to the list of defaults. More...
 
static void logDefaultArgumentLocations (void)
 Logs the default argument locations.
 

Protected Attributes

int * myArgc
 
char ** myArgv
 
ArArgumentBuildermyBuilder
 
char myEmptyArg [1]
 
bool myHelp
 
bool myOwnBuilder
 
bool myReallySetOnlyTrue
 
bool myUsingBuilder
 

Static Protected Attributes

static std::list< bool > ourDefaultArgumentLocIsFile
 
static std::list< std::string > ourDefaultArgumentLocs
 

Detailed Description

Parse and store program command-line arguments for use by other ARIA classes.

This class is made for parsing arguments from the argv and argc variables passed into a program's main() function by the operating system, from an ArArgumentBuilder object, or just from a string (e.g. provided by WinMain() in a Windows MFC program.)

It will also load default argument values if you call loadDefaultArguments(). Aria::init() adds the file /etc/Aria.args and the environment variable ARIAARGS as locations for argument defaults, so loadDefaultArguments() will always search those. You can use this mechanism to avoid needing to always supply command line parameters to all programs. For example, if you use different serial ports than the defaults for the robot and laser, you can put a -robotPort or -laserPort argument in /etc/Aria.args for all programs that call loadDefaultArguments() to use. You can add other files or environment variables to the list of default argument locations with addDefaultArgumentFile() and addDefaultArgumentEnv().

Note that the wasReallySet behavior has changed. It used to set the variable to false or to true, now it will only set it to false if 'setWasReallySetOnlyTrue' is set to false. By default that is set to false, but you can just set it to true after you make the parser with no ill effects since all of the built in Aria parsers will play nicely with this value, setting it to true or false while they parse but then setting it to whatever it was when they started. This change in behavior is so that checking for two things (like -robotPort and -rp) can work without a lot of extra work.

Examples:
actionGroupExample.cpp, actsColorFollowingExample.cpp, auxSerialExample.cpp, cameraPTZExample.cpp, configExample.cpp, demo.cpp, directMotionExample.cpp, dpptuExample.cpp, gotoActionExample.cpp, gpsExample.cpp, gpsRobotTaskExample.cpp, gripperExample.cpp, gyroExample.cpp, imuExample.cpp, laserConnect.cpp, lasers.cpp, moduleExample.cpp, mtxIO.cpp, mtxLCDDisplay.cpp, mtxPowerControl.cpp, mtxWheelLights.cpp, robotConnectionCallbacks.cpp, seekurPower.cpp, simpleConnect.cpp, simpleMotionCommands.cpp, teleopActionsExample.cpp, and wander.cpp.

Constructor & Destructor Documentation

◆ ArArgumentParser() [1/2]

ArArgumentParser::ArArgumentParser ( int *  argc,
char **  argv 
)

Constructor, takes the argc argv.

Parameters
argcpointer to program argument count (e.g. argc from main())
argvarray of program arguments (e.g. arcv from main())

◆ ArArgumentParser() [2/2]

ArArgumentParser::ArArgumentParser ( ArArgumentBuilder builder)

Constructor, takes an argument builder.

Parameters
builderan ArArgumentBuilder object containing arguments

Member Function Documentation

◆ addDefaultArgumentEnv()

void ArArgumentParser::addDefaultArgumentEnv ( const char *  env)
static

Adds another file or environmental variable to the list of defaults.

This adds an environment variable to the list of default argument locations.

Parameters
envName of the environment variable

◆ addDefaultArgumentFile()

void ArArgumentParser::addDefaultArgumentFile ( const char *  file)
static

Adds another file or environmental variable to the list of defaults.

This adds a file to the list of default argument locations.

Parameters
fileName of the file

◆ checkArgument()

bool ArArgumentParser::checkArgument ( const char *  argument)

Returns true if the argument was found.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
...the extra string to feed into the argument for parsing (like printf)
Returns
true if the argument was found, false otherwise
Examples:
configExample.cpp, gpsExample.cpp, and seekurPower.cpp.

◆ checkArgumentVar()

bool ArArgumentParser::checkArgumentVar ( const char *  argument,
  ... 
)

Returns true if the argument was found.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

◆ checkHelpAndWarnUnparsed()

bool ArArgumentParser::checkHelpAndWarnUnparsed ( unsigned int  numArgsOkay = 0)

Checks for the help strings and warns about unparsed arguments.

Check whether a special "help" flag was given in the arguments, and also print a warning (Using ArLog at Normal log level) if any unparsed arguments were found.

The following are the help flags: -help, -h, –help, /?, /h.

Returns
false if a help flag was found or unparsed arguments were found, true otherwise.
Parameters
numArgsOkayIf you plan on checking for additional arguments later in the program, you can specify the number of arguments expected here, which prevents this method from warning about them being unparsed yet.
Examples:
actionGroupExample.cpp, auxSerialExample.cpp, cameraPTZExample.cpp, demo.cpp, directMotionExample.cpp, dpptuExample.cpp, gotoActionExample.cpp, gpsExample.cpp, gpsRobotTaskExample.cpp, gripperExample.cpp, imuExample.cpp, laserConnect.cpp, lasers.cpp, mtxIO.cpp, mtxLCDDisplay.cpp, mtxPowerControl.cpp, mtxWheelLights.cpp, robotConnectionCallbacks.cpp, simpleConnect.cpp, simpleMotionCommands.cpp, teleopActionsExample.cpp, and wander.cpp.

◆ checkParameterArgument()

char * ArArgumentParser::checkParameterArgument ( const char *  argument,
bool  returnFirst = false 
)

Returns the word/argument after given argument.

Parameters
argumentthe string to check for. If the argument is found, then it is removed from the argument list
returnFirsttrue if we should just take the first matching argument, or false if we should iterate through the list and only use the last one (default is false, use true if you want to use the same parameter multiple times)
Returns
NULL if the argument wasn't found; the value given after the found argument; or at empty string (with a NULL first character) if the argument was found but no value followed the argument flag.

◆ checkParameterArgumentBool()

bool ArArgumentParser::checkParameterArgumentBool ( const char *  argument,
bool *  dest,
bool *  wasReallySet = NULL,
bool  returnFirst = false 
)

Returns the word/argument after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Parameters
destif argument is found and is followed by a recognized string representation of a boolean value ("true", "false", "1", or "0"), then dest is set to the appropriate value
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
returnFirstif we should go just take the first argument (true) or if we should through the list and pull up the last one (default is false, use true if you want to use the same parameter multiple times)
argumentthe argument string to search for. If the argument is found, it is removed from the list of arguments
Returns
false if argument was found but was not followed by a recognized value (an error), or true if argument was not found, or if the argument was there with a valid parameter

◆ checkParameterArgumentBoolVar()

bool ArArgumentParser::checkParameterArgumentBoolVar ( bool *  wasReallySet,
bool *  dest,
const char *  argument,
  ... 
)

Returns the word/argument after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

Parameters
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the boolean value, or false if argument was not found and dest was not changed.
destif argument is found and is followed by a recognized string representation of a boolean value ("true", "false", "1", or "0"), then dest is set to the appropriate value
argumentthe argument string to search for. If the argument is found, it is removed from the list of arguments
...if argument contains format codes (like printf()), provide the values to substitute following argument.
Returns
false if argument was found but was not followed by a recognized value (an error), or true if argument was not found, or if the argument was there with a valid parameter

◆ checkParameterArgumentDouble()

bool ArArgumentParser::checkParameterArgumentDouble ( const char *  argument,
double *  dest,
bool *  wasReallySet = NULL,
bool  returnFirst = false 
)

Returns the floating point number after given argument.

Parameters
argumentthe argument to check for. if found, it is removed from the list of arguments
destif the parameter given after the argument is found and is a valid double, then the target of this pointer is assigned to the found value.
returnFirsttrue if only the first instance of the argument given should be used, false if only the last (and all preceding instances discarded).
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
Returns
false if the argument was given but an error occurred while parsing the double parameter (i.e. no parameter given, or it was not a parsable double).

◆ checkParameterArgumentDoubleVar()

bool ArArgumentParser::checkParameterArgumentDoubleVar ( bool *  wasReallySet,
double *  dest,
const char *  argument,
  ... 
)

Returns the double after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
destif the parameter to the argument is found and is a valid integer then dest is set to the integer value
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
...the extra string to feed into the argument for parsing (like printf)
Returns
true if either this argument wasn't there or if the argument was there with a valid parameter

◆ checkParameterArgumentFloat()

bool ArArgumentParser::checkParameterArgumentFloat ( const char *  argument,
float *  dest,
bool *  wasReallySet = NULL,
bool  returnFirst = false 
)

Returns the floating point number after given argument.

Parameters
argumentthe argument to check for. if found, it is removed from the list of arguments
destif the parameter given after the argument is found and is a valid float, then the target of this pointer is assigned to the found value.
returnFirsttrue if only the first instance of the argument given should be used, false if only the last (and all preceding instances discarded).
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
Returns
false if the argument was given but an error occurred while parsing the float parameter (i.e. no parameter given, or it was not a parsable float).

◆ checkParameterArgumentFloatVar()

bool ArArgumentParser::checkParameterArgumentFloatVar ( bool *  wasReallySet,
float *  dest,
const char *  argument,
  ... 
)

Returns the float after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
destif the parameter to the argument is found and is a valid integer then dest is set to the integer value
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
...the extra string to feed into the argument for parsing (like printf)
Returns
true if either this argument wasn't there or if the argument was there with a valid parameter

◆ checkParameterArgumentInteger()

bool ArArgumentParser::checkParameterArgumentInteger ( const char *  argument,
int *  dest,
bool *  wasReallySet = NULL,
bool  returnFirst = false 
)

Returns the integer after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
destif the parameter to the argument is found and is a valid integer then dest is set to the integer value
returnFirstif we should go just take the first argument (true) or if we should through the list and pull up the last one (default is false, use true if you want to use the same parameter multiple times)
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
Returns
true if either this argument wasn't there or if the argument was there with a valid parameter

◆ checkParameterArgumentIntegerVar()

bool ArArgumentParser::checkParameterArgumentIntegerVar ( bool *  wasReallySet,
int *  dest,
const char *  argument,
  ... 
)

Returns the integer after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
destif the parameter to the argument is found and is a valid integer then dest is set to the integer value
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
...the extra string to feed into the argument for parsing (like printf)
Returns
true if either this argument wasn't there or if the argument was there with a valid parameter

◆ checkParameterArgumentString()

bool ArArgumentParser::checkParameterArgumentString ( const char *  argument,
const char **  dest,
bool *  wasReallySet = NULL,
bool  returnFirst = false 
)

Returns the word/argument after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
destif the parameter to the argument is found then the dest is set to the parameter
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
returnFirstif we should go just take the first argument (true) or if we should through the list and pull up the last one (default is false, use true if you want to use the same parameter multiple times)
Returns
true if either this argument wasn't there or if the argument was there with a valid parameter

◆ checkParameterArgumentStringVar()

bool ArArgumentParser::checkParameterArgumentStringVar ( bool *  wasReallySet,
const char **  dest,
const char *  argument,
  ... 
)

Returns the word/argument after given argument.

This is like checkParameterArgument but lets you fail out if the argument is there but the parameter for it is not.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
destif the parameter to the argument is found then the dest is set to the parameter
wasReallySetthe target of this pointer is set to true if argument was found followed by a valid value, and dest was set to the value, or false if argument was not found and dest was not changed.
...the extra string to feed into the argument for parsing (like printf)
Returns
true if either this argument wasn't there or if the argument was there with a valid parameter

◆ checkParameterArgumentVar()

char * ArArgumentParser::checkParameterArgumentVar ( const char *  argument,
  ... 
)

Returns the word/argument after given argument.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

Parameters
argumentthe string to check for, if the argument is found its pulled from the list of arguments
...the extra string to feed into the argument for parsing (like printf)
Returns
NULL if the argument wasn't found, the argument after the one given if the argument was found, or a string with the first char as NULL again if the argument after the one given isn't there

◆ getWasReallySetOnlyTrue()

bool ArArgumentParser::getWasReallySetOnlyTrue ( void  )

If we only set wasReallySet to true.

See the description for the class for more information about this.

◆ loadDefaultArguments()

void ArArgumentParser::loadDefaultArguments ( int  position = 1)

Adds args from default files and environmental variables.

Search all locations for argument defaults and parse them.

These locations may be environment variables to read argument varues from, or files to read.

See also
addDefaultArgumentLocation
Note
If you use this function your normal argc (passed into main()) will have been modified, and won't reflect reality anymore. You'll have to use getArgc() to get the actual original argument count. This is a little wierd but is this way so lots of people don't have to change lots of code.
Examples:
actionGroupExample.cpp, actsColorFollowingExample.cpp, auxSerialExample.cpp, cameraPTZExample.cpp, configExample.cpp, demo.cpp, directMotionExample.cpp, dpptuExample.cpp, gotoActionExample.cpp, gpsExample.cpp, gpsRobotTaskExample.cpp, gripperExample.cpp, gyroExample.cpp, imuExample.cpp, laserConnect.cpp, lasers.cpp, mtxIO.cpp, mtxLCDDisplay.cpp, mtxPowerControl.cpp, mtxWheelLights.cpp, seekurPower.cpp, simpleConnect.cpp, simpleMotionCommands.cpp, teleopActionsExample.cpp, and wander.cpp.

◆ setWasReallySetOnlyTrue()

void ArArgumentParser::setWasReallySetOnlyTrue ( bool  wasReallySetOnlyTrue)

If we should only set wasReallySet to true.

See the description for the class for more information about this.


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