Aria  2.8.0
ArArgumentBuilder Class Reference

This class is to build arguments for things that require argc and argv. More...

#include <ArArgumentBuilder.h>

Public Member Functions

void add (const char *str,...)
 Adds the given string, with varargs, separates if there are spaces. More...
 
void addPlain (const char *str, int position=-1)
 Adds the given string, without varargs (wrapper for java) More...
 
void addPlainAsIs (const char *str, int position=-1)
 Adds the given string, without varargs and without touching the str. More...
 
void addStrings (char **argv, int argc, int position=-1)
 Adds the given string thats divided. More...
 
void addStrings (int argc, char **argv, int position=-1)
 Adds the given string thats divided. More...
 
void addStringsAsIs (int argc, char **argv, int position=-1)
 Adds the given string thats divided (but doesn't touch the strings) More...
 
 ArArgumentBuilder (size_t argvLen=512, char extraSpaceChar='\0', bool ignoreNormalSpaces=false, bool isPreCompressQuotes=false)
 Constructor. More...
 
 ArArgumentBuilder (const ArArgumentBuilder &builder)
 Copy Constructor.
 
void compressQuoted (bool stripQuotationMarks=false)
 Combines quoted arguments into one.
 
const char * getArg (size_t whichArg) const
 Gets a specific argument as a string.
 
bool getArgBool (size_t whichArg, bool *ok=NULL) const
 Gets the value of an argument as a boolean. More...
 
size_t getArgc (void) const
 Gets the argc.
 
double getArgDouble (size_t whichArg, bool *ok=NULL) const
 Gets the value of an argument as a double. More...
 
int getArgInt (size_t whichArg, bool *ok=NULL, bool forceHex=false) const
 Gets the value of an argument as an integer. More...
 
int getArgLongLongInt (size_t whichArg, bool *ok=NULL) const
 Gets the value of an argument as a long long integer. More...
 
char ** getArgv (void) const
 Gets the argv.
 
const char * getExtraString (void) const
 Gets the extra string of the input, used differently by different things.
 
const char * getFullString (void) const
 Gets the original string of the input.
 
bool isArgBool (size_t whichArg) const
 Sees if an argument is a bool.
 
bool isArgDouble (size_t whichArg) const
 Sees if an argument is a double.
 
bool isArgInt (size_t whichArg, bool forceHex=false) const
 Sees if an argument is an int. More...
 
bool isArgLongLongInt (size_t whichArg) const
 Sees if an argument is a long long int.
 
void log (void) const
 Prints out the arguments.
 
ArArgumentBuilderoperator= (const ArArgumentBuilder &builder)
 
void removeArg (size_t which, bool isRebuildFullString=false)
 Delete a particular arg, you MUST finish adding before you can remove.
 
void setExtraString (const char *str)
 Sets the extra string of the input, used differently by different things.
 
void setFullString (const char *str)
 Sets the full string (this is so you can have a more raw full string)
 
void setQuiet (bool isQuiet)
 Turn on this flag to reduce the number of verbose log messages.
 
virtual ~ArArgumentBuilder ()
 Destructor.
 

Protected Types

enum  ArgSeparatorType { SPACE = 1, SPECIAL = SPACE << 1, ANY_SPACE = SPACE | SPECIAL, QUOTE = SPECIAL << 1 }
 Characters that may be used to separate arguments; bitwise flags so QUOTE can be combined with spaces.
 

Protected Member Functions

size_t getArgvLen (void) const
 
void internalAdd (const char *str, int position=-1)
 Internal function that adds a string starting at some given space. More...
 
void internalAddAsIs (const char *str, int position=-1)
 
bool isEndArg (const char *buf, int len, int &indexInOut, int endArgFlags)
 Determines whether the current buffer position marks the end of an argument. More...
 
bool isSpace (char c)
 Determines whether the specified character is an acceptable space (either normal or extra)
 
bool isStartArg (const char *buf, int len, int index, int *endArgFlagsOut)
 Determines whether the current buffer position marks the start of an argument. More...
 
void rebuildFullString ()
 

Protected Attributes

size_t myArgc
 
char ** myArgv
 
size_t myArgvLen
 
char myExtraSpace
 
std::string myExtraString
 
bool myFirstAdd
 
std::string myFullString
 
bool myIgnoreNormalSpaces
 
bool myIsPreCompressQuotes
 Whether to treat double-quotes as arg delimiters (preserving spaces within)
 
bool myIsQuiet
 
size_t myOrigArgc
 

Detailed Description

This class is to build arguments for things that require argc and argv.

Constructor & Destructor Documentation

◆ ArArgumentBuilder()

ArArgumentBuilder::ArArgumentBuilder ( size_t  argvLen = 512,
char  extraSpaceChar = '\0',
bool  ignoreNormalSpaces = false,
bool  isPreCompressQuotes = false 
)

Constructor.

Parameters
argvLenthe largest number of arguments to parse
extraSpaceCharif not NULL, then this character will also be used to break up arguments (in addition to whitespace)
ignoreNormalSpacesa bool set to true if only the extraSpaceChar should be used to separate arguments
isPreCompressQuotesa bool set to true if strings enclosed in double-quotes should be parsed as a single argument (such strings must be surrounded by spaces). This is roughly equivalent to calling ArArgumentBuilder::compressQuoted(false) on the resulting builder, but is more efficient and handles embedded spaces better. The default value is false and preserves the original behavior where each argument is a space-separated alphanumeric string.

Member Function Documentation

◆ add()

void ArArgumentBuilder::add ( const char *  str,
  ... 
)

Adds the given string, with varargs, separates if there are spaces.

Java and Python Wrappers: Not available

◆ addPlain()

void ArArgumentBuilder::addPlain ( const char *  str,
int  position = -1 
)

Adds the given string, without varargs (wrapper for java)

Parameters
strthe string to add
positionthe position to add the string at, a position less than 0 means to add at the end, if this number is greater than how many positions exist then it will also be added at the end

◆ addPlainAsIs()

void ArArgumentBuilder::addPlainAsIs ( const char *  str,
int  position = -1 
)

Adds the given string, without varargs and without touching the str.

Parameters
strthe string to add
positionthe position to add the string at, a position less than 0 means to add at the end, if this number is greater than how many positions exist then it will also be added at the end

◆ addStrings() [1/2]

void ArArgumentBuilder::addStrings ( char **  argv,
int  argc,
int  position = -1 
)

Adds the given string thats divided.

Parameters
argchow many arguments to add
argvthe strings to add
positionthe position to add the string at, a position less than 0 means to add at the end, if this number is greater than how many positions exist then it will also be added at the end

◆ addStrings() [2/2]

void ArArgumentBuilder::addStrings ( int  argc,
char **  argv,
int  position = -1 
)

Adds the given string thats divided.

Parameters
argchow many arguments to add
argvthe strings to add
positionthe position to add the string at, a position less than 0 means to add at the end, if this number is greater than how many positions exist then it will also be added at the end

◆ addStringsAsIs()

void ArArgumentBuilder::addStringsAsIs ( int  argc,
char **  argv,
int  position = -1 
)

Adds the given string thats divided (but doesn't touch the strings)

Parameters
argchow many arguments to add
argvthe strings to add
positionthe position to add the string at, a position less than 0 means to add at the end, if this number is greater than how many positions exist then it will also be added at the end

◆ getArgBool()

bool ArArgumentBuilder::getArgBool ( size_t  whichArg,
bool *  ok = NULL 
) const

Gets the value of an argument as a boolean.

Valid boolean values are "true" and "false", and "1" and "0". There are two ways to to verify that the specified argument is a bool. Either call isArgBool() before calling this method, or specify a non-NULL ok parameter value. The latter is somewhat more efficient since the argument string is checked only once.

Parameters
whichArgthe size_t index of the arg to retrieve; must be >= 0 and less than getArgc()
okan optional pointer to a bool that will be set to true if the arg was successfully retrieved or to false if an error occurred
Returns
bool the retrieved argument value; valid only if ok or isArgBool is true

◆ getArgDouble()

double ArArgumentBuilder::getArgDouble ( size_t  whichArg,
bool *  ok = NULL 
) const

Gets the value of an argument as a double.

There are two ways to to verify that the specified argument is a double. Either call isArgDouble() before calling this method, or specify a non-NULL ok parameter value. The latter is somewhat more efficient because the digit status of each character is checked only once.

Parameters
whichArgthe size_t index of the arg to retrieve; must be >= 0 and less than getArgc()
okan optional pointer to a bool that will be set to true if the arg was successfully retrieved or to false if an error occurred
Returns
double the retrieved argument value; valid only if ok or isArgDouble is true

◆ getArgInt()

int ArArgumentBuilder::getArgInt ( size_t  whichArg,
bool *  ok = NULL,
bool  forceHex = false 
) const

Gets the value of an argument as an integer.

There are two ways to to verify that the specified argument is an integer. Either call isArgInt() before calling this method, or specify a non-NULL ok parameter value. The latter is somewhat more efficient because the digit status of each character is checked only once.

Parameters
whichArgthe size_t index of the arg to retrieve; must be >= 0 and less than getArgc()
okan optional pointer to a bool that will be set to true if the arg was successfully retrieved or to false if an error occurred
forceHexif true this makes it find the int in base 16 instead of 10
Returns
int the retrieved argument value; valid only if ok or isArgInt is true

◆ getArgLongLongInt()

int ArArgumentBuilder::getArgLongLongInt ( size_t  whichArg,
bool *  ok = NULL 
) const

Gets the value of an argument as a long long integer.

There are two ways to to verify that the specified argument is an integer. Either call isArgInt() before calling this method, or specify a non-NULL ok parameter value. The latter is somewhat more efficient because the digit status of each character is checked only once.

Parameters
whichArgthe size_t index of the arg to retrieve; must be >= 0 and less than getArgc()
okan optional pointer to a bool that will be set to true if the arg was successfully retrieved or to false if an error occurred
Returns
int the retrieved argument value; valid only if ok or isArgInt is true

◆ internalAdd()

void ArArgumentBuilder::internalAdd ( const char *  str,
int  position = -1 
)
protected

Internal function that adds a string starting at some given space.

Parameters
strthe string to add
positionthe position to add the string at, a position less than 0 means to add at the end, if this number is greater than how many positions exist then it will also be added at the end

◆ isArgInt()

bool ArArgumentBuilder::isArgInt ( size_t  whichArg,
bool  forceHex = false 
) const

Sees if an argument is an int.

Parameters
whichArgthe size_t index of the arg to retrieve; must be >= 0 and less than getArgc()
forceHexif true this makes it find the int in base 16 instead of 10

◆ isEndArg()

bool ArArgumentBuilder::isEndArg ( const char *  buf,
int  len,
int &  indexInOut,
int  endArgFlags 
)
protected

Determines whether the current buffer position marks the end of an argument.

This method should only be called when an argument is currently being parsed (i.e. isStartArg returned true).

Parameters
bufthe char * buffer that is being parsed; must be non-NULL
lenthe maximum number of characters in the buffer
indexInOutthe input/output int buffer position of the character to be tested; if the argument ends with a quote-space, then the index will be incremented to mark the space; otherwise, it will remain unchanged
endArgFlagsan int that indicates which separators mark the end of the argument. If quotes are being pre-processed, and the current argument started with space-quote, then the argument must end with a quote-space.

◆ isStartArg()

bool ArArgumentBuilder::isStartArg ( const char *  buf,
int  len,
int  index,
int *  endArgFlagsOut 
)
protected

Determines whether the current buffer position marks the start of an argument.

This method should only be called when an argument is not currently being parsed (i.e. the previous character was a space).

Parameters
bufthe char * buffer that is being parsed; must be non-NULL
lenthe maximum number of characters in the buffer
indexthe int buffer position of the character to be tested
endArgFlagsOuta pointer to an output int that will indicate which separators will mark the end of the argument. If quotes are being pre-processed, and the current argument starts with space-quote, then the argument must end with a quote-space.

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