ADTF  v2.14.3
cCommandLine Class Reference

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 (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 cStringGetBuffer () const
 Returns a reference to the internal commandline buffer. More...
 
const cStringListGetFlags () const
 Returns a list of all specified flags. More...
 
const cStringListGetValues () const
 Returns a list of all specified values. More...
 
const cStringMapGetProperties () 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< cStringm_lstArgv
 Argument list.
 
const tChar ** m_pArgv
 Argument pointer.
 
tInt m_nArgc
 Argument count.
 

Detailed Description

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

-path="C:\Test\" -output="C:\Output"

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:

-path="C:\Test\\" -output="C:\Output"

The same problem affects single quotes after backslashes, for example:

-path='C:\Test\' -output='C:\Output'

When no quotes are used, parameter values ending in backslashes are not a problem, for example the following will be parsed correctly:

-path=C:\Test\ -output="C:\Output"

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 61 of file commandline.h.

Constructor & Destructor Documentation

cCommandLine ( const cString strCommandLine)

Constructor that parses a given command line string.

Parameters
strCommandLine[in] The command line string.
cCommandLine ( const cCommandLine oCommandLine)

Copy constructor.

Parameters
oCommandLine[in] The object to copy from.
cCommandLine ( int  argc,
const char **  argv 
)

Constructor for standard commandline parameters.

Parameters
argc[in] The size of the argv array.
argv[in] The array of commandline parameters.

Member Function Documentation

tResult FreeArgs ( )
protected

Frees the argument list.

Returns
Standard result.
cString GetArg ( tInt  nIdx,
const cString strDefault = cString::Empty 
) const

Returns a command line argument.

Parameters
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.
Returns
[in] The commandline argument.
tInt GetArgc ( ) const

Returns the size of the array retreived by GetArgv().

Returns
The size of the array retreived by GetArgv().
const tChar** GetArgv ( ) const

Returns a pointer to a standard style command line parameter array.

Returns
An array of commandline parameters.
const cString& GetBuffer ( ) const

Returns a reference to the internal commandline buffer.

Returns
A reference to the internal commandline buffer.
This method is real-time safe.
See The ADTF Real-Time Extension.
tBool GetFlag ( const cString strName) const

Returns whether a flag (-flagname) was specified or not.

Parameters
strName[in] The name of the flag.
Returns
tTrue if the flag was specified, tFalse otherwise.
This method is real-time safe.
See The ADTF Real-Time Extension.
const cStringList& GetFlags ( ) const

Returns a list of all specified flags.

Returns
A list of all specified flags.
This method is real-time safe.
See The ADTF Real-Time Extension.
const cStringMap& GetProperties ( ) const

Returns a map of all specified properties.

Returns
A map of all specified properties.
This method is real-time safe.
See The ADTF Real-Time Extension.
cString GetProperty ( const cString strName,
const cString strDefault = cString::Empty 
) const

Returns a property (-propertyname=value).

Parameters
strName[in] The name of the property.
strDefault[in] A default value that is returned if the property was not specified on the commandline.
Returns
The property value.
cString GetString ( ) const

Builds a command line string by concatenating all parameters.

Returns
The command line string.
cString GetValue ( tInt  nIdx,
const cString strDefault = cString::Empty 
) const

Returns a command line parameter that is no flag or property.

Parameters
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.
Returns
[in] The commandline parameter.
const cStringList& GetValues ( ) const

Returns a list of all specified values.

Returns
A list of all specified values.
This method is real-time safe.
See The ADTF Real-Time Extension.
tResult Initialize ( )
protected

Initializes internal parameters.

Returns
Standard result.
tResult Parse ( )
protected

Parses the internal buffer.

Returns
Standard result.
tResult Set ( const cString strCommandLine)

Parses a given command line string.

Parameters
strCommandLine[in] The command line string.
Returns
Standard result.
tResult Set ( const cCommandLine oCommandLine)

Copy data from another command line objects.

Parameters
oCommandLine[in] The object to copy from.
Returns
Standard result.
tResult Set ( int  argc,
const char **  argv 
)

Set data using standard commandline parameters.

Parameters
argc[in] The size of the argv array.
argv[in] An array of commandline parameters.
Returns
Standard result.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Fri Mar 22 2019 by doxygen 1.8.10)