#include <ArArgumentParser.h>
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().
actionGroupExample.cpp, actsColorFollowingExample.cpp, auxSerialExample.cpp, configExample.cpp, demo.cpp, dpptuExample.cpp, gotoActionExample.cpp, gpsExample.cpp, gripperExample.cpp, robotConnectionCallbacks.cpp, and teleopActionsExample.cpp.
Definition at line 51 of file ArArgumentParser.h.
Public Member Functions | |
| void | addDefaultArgument (const char *argument, int position=-1) |
| Adds a string as a default argument. | |
| ArArgumentParser (ArArgumentBuilder *builder) | |
| Constructor, takes an argument builder. | |
| ArArgumentParser (int *argc, char **argv) | |
| Constructor, takes the argc argv. | |
| bool | checkArgument (const char *argument) |
| Returns true if the argument was found. | |
| bool | checkArgumentVar (char *argument,...) |
| Returns true if the argument was found. | |
| bool | checkHelpAndWarnUnparsed (unsigned int numArgsOkay=0) |
| Checks for the help strings and warns about unparsed arguments. | |
| char * | checkParameterArgument (char *argument, bool returnFirst=false) |
| Returns the word/argument after given argument. | |
| bool | checkParameterArgumentBool (char *argument, bool *dest, bool *wasReallySet=NULL, bool returnFirst=false) |
| Returns the word/argument after given argument. | |
| bool | checkParameterArgumentBoolVar (bool *wasReallySet, bool *dest, char *argument,...) |
| Returns the word/argument after given argument. | |
| bool | checkParameterArgumentFloat (char *argument, float *dest, bool *wasReallySet=NULL, bool returnFirst=false) |
| Returns the floating point number after given argument. | |
| bool | checkParameterArgumentInteger (char *argument, int *dest, bool *wasReallySet=NULL, bool returnFirst=false) |
| Returns the integer after given argument. | |
| bool | checkParameterArgumentIntegerVar (bool *wasReallySet, int *dest, char *argument,...) |
| Returns the integer after given argument. | |
| bool | checkParameterArgumentString (char *argument, const char **dest, bool *wasReallySet=NULL, bool returnFirst=false) |
| Returns the word/argument after given argument. | |
| bool | checkParameterArgumentStringVar (bool *wasReallySet, const char **dest, char *argument,...) |
| Returns the word/argument after given argument. | |
| char * | checkParameterArgumentVar (char *argument,...) |
| Returns the word/argument after given argument. | |
| 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. | |
| char ** | getArgv (void) const |
| Gets the argv. | |
| void | loadDefaultArguments (int positon=1) |
| Adds args from default files and environmental variables. | |
| 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. | |
| ~ArArgumentParser () | |
| Destructor. | |
Static Public Member Functions | |
| static void | addDefaultArgumentEnv (const char *env) |
| Adds another file or environmental variable to the list of defaults. | |
| static void | addDefaultArgumentFile (const char *file) |
| Adds another file or environmental variable to the list of defaults. | |
| static void | logDefaultArgumentLocations (void) |
| Logs the default argument locations. | |
Protected Attributes | |
| int * | myArgc |
| char ** | myArgv |
| ArArgumentBuilder * | myBuilder |
| char | myEmptyArg [1] |
| bool | myOwnBuilder |
| bool | myUsingBuilder |
Static Protected Attributes | |
| static std::list< bool > | ourDefaultArgumentLocIsFile |
| static std::list< std::string > | ourDefaultArgumentLocs |
| ArArgumentParser::ArArgumentParser | ( | int * | argc, | |
| char ** | argv | |||
| ) |
Constructor, takes the argc argv.
| argc | pointer to program argument count (e.g. argc from main()) | |
| argv | array of program arguments (e.g. arcv from main()) |
Definition at line 40 of file ArArgumentParser.cpp.
| ArArgumentParser::ArArgumentParser | ( | ArArgumentBuilder * | builder | ) |
Constructor, takes an argument builder.
| builder | an ArArgumentBuilder object containing arguments |
Definition at line 54 of file ArArgumentParser.cpp.
| 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.
| env | Name of the environment variable |
Definition at line 670 of file ArArgumentParser.cpp.
| 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.
| file | Name of the file |
Definition at line 658 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkArgument | ( | const char * | argument | ) |
Returns true if the argument was found.
| argument | the 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) |
Definition at line 91 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkArgumentVar | ( | char * | argument, | |
| ... | ||||
| ) |
Returns true if the argument was found.
Java and Python Wrappers: Not available in Java or Python wrapper libraries.
Definition at line 71 of file ArArgumentParser.cpp.
| 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.
| numArgsOkay | If 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. |
Definition at line 705 of file ArArgumentParser.cpp.
| char * ArArgumentParser::checkParameterArgument | ( | char * | argument, | |
| bool | returnFirst = false | |||
| ) |
Returns the word/argument after given argument.
| argument | the string to check for. If the argument is found, then it is removed from the argument list | |
| returnFirst | true 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) |
Definition at line 474 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkParameterArgumentBool | ( | 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
| dest | if 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 | |
| wasReallySet | the 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. | |
| returnFirst | if 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) | |
| argument | the argument string to search for. If the argument is found, it is removed from the list of arguments |
Definition at line 252 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkParameterArgumentBoolVar | ( | bool * | wasReallySet, | |
| bool * | dest, | |||
| char * | argument, | |||
| ... | ||||
| ) |
Returns the word/argument after given argument.
Java and Python Wrappers: Not available in Java or Python wrapper libraries.
Definition at line 216 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkParameterArgumentFloat | ( | char * | argument, | |
| float * | dest, | |||
| bool * | wasReallySet = NULL, |
|||
| bool | returnFirst = false | |||
| ) |
Returns the floating point number after given argument.
| argument | the argument to check for. if found, it is removed from the list of arguments | |
| dest | if 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. | |
| returnFirst | true if only the first instance of the argument given should be used, false if only the last (and all preceding instances discarded). | |
| wasReallySet | the 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. |
Definition at line 408 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkParameterArgumentInteger | ( | 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
| argument | the string to check for, if the argument is found its pulled from the list of arguments | |
| dest | if the parameter to the argument is found and is a valid integer then dest is set to the integer value | |
| returnFirst | if 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) | |
| wasReallySet | the 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. |
Definition at line 354 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkParameterArgumentIntegerVar | ( | bool * | wasReallySet, | |
| int * | dest, | |||
| char * | argument, | |||
| ... | ||||
| ) |
Returns the integer after given argument.
Java and Python Wrappers: Not available in Java or Python wrapper libraries.
Definition at line 320 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkParameterArgumentString | ( | 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
| argument | the string to check for, if the argument is found its pulled from the list of arguments | |
| dest | if the parameter to the argument is found then the dest is set to the parameter | |
| wasReallySet | the 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. | |
| returnFirst | if 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) |
Definition at line 166 of file ArArgumentParser.cpp.
| bool ArArgumentParser::checkParameterArgumentStringVar | ( | bool * | wasReallySet, | |
| const char ** | dest, | |||
| char * | argument, | |||
| ... | ||||
| ) |
Returns the word/argument after given argument.
Java and Python Wrappers: Not available in Java or Python wrapper libraries.
Definition at line 132 of file ArArgumentParser.cpp.
| char * ArArgumentParser::checkParameterArgumentVar | ( | char * | argument, | |
| ... | ||||
| ) |
Returns the word/argument after given argument.
Java and Python Wrappers: Not available in Java or Python wrapper libraries.
Definition at line 452 of file ArArgumentParser.cpp.
| 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.
Definition at line 598 of file ArArgumentParser.cpp.
1.4.7