Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArArgumentParser Class Reference

Class for parsing arguments. More...

#include <ArArgumentParser.h>

List of all members.

Public Member Functions

void addDefaultArgument (const char *argument)
 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 (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 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 (void)
 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
ArArgumentBuildermyBuilder
char myEmptyArg [1]
bool myOwnBuilder
bool myUsingBuilder

Static Protected Attributes

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


Detailed Description

Class for parsing arguments.

This class is made for parsing arguments form an argc/argv set, an argument builder or just a string (for winmain)

It will also load up some default arguments you call loadDefaultArguments. You can add files or environmental variables to the list of default argument locations with addDefaultArgumentLocation.

Definition at line 43 of file ArArgumentParser.h.


Constructor & Destructor Documentation

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

Constructor, takes the argc argv.

Parameters:
argc a pointer to the argc used
argv argv

Definition at line 41 of file ArArgumentParser.cpp.

ArArgumentParser::ArArgumentParser ArArgumentBuilder builder  ) 
 

Constructor, takes an argument builder.

Parameters:
argc a pointer to the argc used
argv argv

Definition at line 56 of file ArArgumentParser.cpp.


Member Function Documentation

void ArArgumentParser::addDefaultArgumentEnv const char *  env  )  [static]
 

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

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

Definition at line 583 of file ArArgumentParser.cpp.

Referenced by Aria::init().

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.

Definition at line 572 of file ArArgumentParser.cpp.

Referenced by Aria::init().

bool ArArgumentParser::checkArgument char *  argument  ) 
 

Returns true if the argument was found.

Parameters:
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)
Returns:
true if the argument was found, false otherwise

Definition at line 92 of file ArArgumentParser.cpp.

References getArgc(), getArgv(), and removeArg().

Referenced by checkArgumentVar(), checkHelpAndWarnUnparsed(), and ArDaemonizer::daemonize().

bool ArArgumentParser::checkHelpAndWarnUnparsed unsigned int  numArgsOkay = 0  ) 
 

Checks for the help strings and warns about unparsed arguments.

This function returns false if there was a help request in the parser (so the program should show the help and exit) and also warns about unhandled arguments (it doesn't mind them, just says they're around).

Definition at line 613 of file ArArgumentParser.cpp.

References checkArgument(), getArg(), getArgc(), and ArLog::log().

char * ArArgumentParser::checkParameterArgument char *  argument,
bool  returnFirst = false
 

Returns the word/argument after given argument.

Parameters:
argument the string to check for, if the argument is found its pulled from the list of arguments
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)
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 '' again if the argument after the one given isn't there

Definition at line 396 of file ArArgumentParser.cpp.

References getArgc(), getArgv(), and removeArg().

Referenced by checkParameterArgumentBool(), checkParameterArgumentInteger(), checkParameterArgumentString(), and checkParameterArgumentVar().

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

Parameters:
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 bool (true, false, 1, 0) then dest is set to the bool 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)
Returns:
true if either this argument wasn't there or if the argument was there with a valid parameter

Definition at line 229 of file ArArgumentParser.cpp.

References checkParameterArgument(), and ArLog::log().

Referenced by checkParameterArgumentBoolVar().

bool ArArgumentParser::checkParameterArgumentBoolVar bool *  wasReallySet,
bool *  dest,
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

Parameters:
... the extra string to feed into the argument for parsing (like printf)
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 bool (true, false, 1, 0) then dest is set to the bool value
Returns:
true if either this argument wasn't there or if the argument was there with a valid parameter

Definition at line 200 of file ArArgumentParser.cpp.

References checkParameterArgumentBool().

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

Parameters:
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)
Returns:
true if either this argument wasn't there or if the argument was there with a valid parameter

Definition at line 321 of file ArArgumentParser.cpp.

References checkParameterArgument(), and ArLog::log().

Referenced by checkParameterArgumentIntegerVar().

bool ArArgumentParser::checkParameterArgumentIntegerVar bool *  wasReallySet,
int *  dest,
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

Parameters:
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
... 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

Definition at line 292 of file ArArgumentParser.cpp.

References checkParameterArgumentInteger().

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

Parameters:
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
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)
Returns:
true if either this argument wasn't there or if the argument was there with a valid parameter

Definition at line 157 of file ArArgumentParser.cpp.

References checkParameterArgument(), and ArLog::log().

Referenced by checkParameterArgumentStringVar().

bool ArArgumentParser::checkParameterArgumentStringVar bool *  wasReallySet,
const char **  dest,
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

Parameters:
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
... 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

Definition at line 128 of file ArArgumentParser.cpp.

References checkParameterArgumentString().

char * ArArgumentParser::checkParameterArgumentVar char *  argument,
  ...
 

Returns the word/argument after given argument.

Parameters:
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)
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 '' again if the argument after the one given isn't there

Definition at line 374 of file ArArgumentParser.cpp.

References checkParameterArgument().

void ArArgumentParser::loadDefaultArguments void   ) 
 

Adds args from default files and environmental variables.

NOTE, if you use this function your normal argc (from main) won't reflect reality anymore, you'll have to use the parser.getArgc() to get the actual argument count. This is a little wierd but is this way so lots of people don't have to change lots of code.

This goes through the list of default argument locations, if the string is an environmental variable it adds the value of the variable to the list of defaults, otherwise it tries to load a string from the file and add that to the list. You can add more default locations with addDefaultArgumentLocation.

Definition at line 521 of file ArArgumentParser.cpp.

References ArArgumentBuilder::addPlain(), ArArgumentBuilder::addStrings(), and ArLog::log().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:43 2005 for Aria by  doxygen 1.4.0