ADTF
3.18.2
|
Command line processing. More...
Public Member Functions | |
cCommandLine () | |
Default constructor. | |
cCommandLine (const cString &strCommandLine) | |
Constructor that parses a given command line string. More... | |
cCommandLine (const cCommandLine &oCommandLine) | |
Copy constructor. More... | |
cCommandLine & | operator= (const cCommandLine &oCommandLine) |
Assignment operator. More... | |
cCommandLine (int argc, const char **argv) | |
Constructor for standard commandline parameters. More... | |
virtual | ~cCommandLine () |
Destructor. | |
tResult | Set (const cString &strCommandLine) |
Parses a given command line string. More... | |
tResult | Set (const cCommandLine &oCommandLine) |
Copy data from another command line objects. More... | |
tResult | Set (int argc, const char **argv) |
Set data using standard commandline parameters. More... | |
cString | GetString () const |
Builds a command line string by concatenating all parameters. More... | |
cString | GetProperty (const cString &strName, const cString &strDefault=cString::Empty) const |
Returns a property (-propertyname=value). More... | |
tBool | GetFlag (const cString &strName) const |
Returns whether a flag (-flagname) was specified or not. More... | |
cString | GetValue (tInt nIdx, const cString &strDefault=cString::Empty) const |
Returns a command line parameter that is no flag or property. More... | |
cString | GetArg (tInt nIdx, const cString &strDefault=cString::Empty) const |
Returns a command line argument. More... | |
const cString & | GetBuffer () const |
Returns a reference to the internal commandline buffer. More... | |
const cStringList & | GetFlags () const |
Returns a list of all specified flags. More... | |
const cStringList & | GetValues () const |
Returns a list of all specified values. More... | |
const cStringMap & | GetProperties () const |
Returns a map of all specified properties. More... | |
const tChar ** | GetArgv () const |
Returns a pointer to a standard style command line parameter array. More... | |
tInt | GetArgc () const |
Returns the size of the array retreived by GetArgv(). More... | |
Protected Member Functions | |
tResult | Parse () |
Parses the internal buffer. More... | |
tResult | Initialize () |
Initializes internal parameters. More... | |
tResult | FreeArgs () |
Frees the argument list. More... | |
Protected Attributes | |
cString | m_strBuffer |
Internal buffer. | |
cStringList | m_lstFlags |
List of flags. | |
cStringList | m_lstValues |
List of values. | |
cStringMap | m_mapProperties |
Property map of the commandline. | |
std::list< cString > | m_lstArgv |
Argument list. | |
const tChar ** | m_pArgv |
Argument pointer. | |
tInt | m_nArgc |
Argument count. | |
Command line processing.
Important things to be aware of:
Backslashes are considered escape characters and may lead to unexpected behavior if used incorrectly in the input of cCommandLine. Particular care should be taken when backslashes are used before quote characters. For example in the command line
the backslash after "Test" will escape the double quotes, which will lead to "path" incorrectly becoming the only property and with an incorrect value. To remedy this, the backslash after "Test" needs to be escaped itself using another backslash before it:
The same problem affects single quotes after backslashes, for example:
When no quotes are used, parameter values ending in backslashes are not a problem, for example the following will be parsed correctly:
Summary:
If you want to use backslashes in a commandline, then either use NO quotes or DOUBLE backslashes to escape it (at least directly before a quote character).
Definition at line 53 of file commandline.h.
cCommandLine | ( | const cString & | strCommandLine | ) |
Constructor that parses a given command line string.
strCommandLine | [in] The command line string. |
cCommandLine | ( | const cCommandLine & | oCommandLine | ) |
Copy constructor.
oCommandLine | [in] The object to copy from. |
cCommandLine | ( | int | argc, |
const char ** | argv | ||
) |
Constructor for standard commandline parameters.
argc | [in] The size of the argv array. |
argv | [in] The array of commandline parameters. |
|
protected |
Frees the argument list.
cString GetArg | ( | tInt | nIdx, |
const cString & | strDefault = cString::Empty |
||
) | const |
Returns a command line argument.
nIdx | [in] The index of the argument to retrieve. |
strDefault | [in] A default value that is returned if no argument with the index was specified. |
tInt GetArgc | ( | ) | const |
const tChar** GetArgv | ( | ) | const |
Returns a pointer to a standard style command line parameter array.
const cString& GetBuffer | ( | ) | const |
Returns a reference to the internal commandline buffer.
Returns whether a flag (-flagname) was specified or not.
strName | [in] The name of the flag. |
const cStringList& GetFlags | ( | ) | const |
Returns a list of all specified flags.
const cStringMap& GetProperties | ( | ) | const |
Returns a map of all specified properties.
cString GetProperty | ( | const cString & | strName, |
const cString & | strDefault = cString::Empty |
||
) | const |
Returns a property (-propertyname=value).
strName | [in] The name of the property. |
strDefault | [in] A default value that is returned if the property was not specified on the commandline. |
cString GetString | ( | ) | const |
Builds a command line string by concatenating all parameters.
cString GetValue | ( | tInt | nIdx, |
const cString & | strDefault = cString::Empty |
||
) | const |
Returns a command line parameter that is no flag or property.
nIdx | [in] The index of the parameter to retrieve. |
strDefault | [in] A default value that is returned if no parameter with the index was specified. |
const cStringList& GetValues | ( | ) | const |
Returns a list of all specified values.
|
protected |
Initializes internal parameters.
cCommandLine& operator= | ( | const cCommandLine & | oCommandLine | ) |
Assignment operator.
oCommandLine | [in] The object to copy from. |
|
protected |
Parses the internal buffer.
tResult Set | ( | const cCommandLine & | oCommandLine | ) |
Copy data from another command line objects.
oCommandLine | [in] The object to copy from. |
Parses a given command line string.
strCommandLine | [in] The command line string. |
tResult Set | ( | int | argc, |
const char ** | argv | ||
) |
Set data using standard commandline parameters.
argc | [in] The size of the argv array. |
argv | [in] An array of commandline parameters. |