ADTF  3.18.2
cCommandLine

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...
 
cCommandLineoperator= (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 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 53 of file commandline.h.

Constructor & Destructor Documentation

◆ cCommandLine() [1/3]

cCommandLine ( const cString strCommandLine)

Constructor that parses a given command line string.

Parameters
strCommandLine[in] The command line string.

◆ cCommandLine() [2/3]

cCommandLine ( const cCommandLine oCommandLine)

Copy constructor.

Parameters
oCommandLine[in] The object to copy from.

◆ cCommandLine() [3/3]

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

◆ FreeArgs()

tResult FreeArgs ( )
protected

Frees the argument list.

Returns
Standard result.

◆ GetArg()

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.

◆ GetArgc()

tInt GetArgc ( ) const

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

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

◆ GetArgv()

const tChar** GetArgv ( ) const

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

Returns
An array of commandline parameters.

◆ GetBuffer()

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.\nSee @ref page_real_time_safe.\n

◆ GetFlag()

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.\nSee @ref page_real_time_safe.\n

◆ GetFlags()

const cStringList& GetFlags ( ) const

Returns a list of all specified flags.

Returns
A list of all specified flags.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetProperties()

const cStringMap& GetProperties ( ) const

Returns a map of all specified properties.

Returns
A map of all specified properties.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetProperty()

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.

◆ GetString()

cString GetString ( ) const

Builds a command line string by concatenating all parameters.

Returns
The command line string.

◆ GetValue()

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.

◆ GetValues()

const cStringList& GetValues ( ) const

Returns a list of all specified values.

Returns
A list of all specified values.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ Initialize()

tResult Initialize ( )
protected

Initializes internal parameters.

Returns
Standard result.

◆ operator=()

cCommandLine& operator= ( const cCommandLine oCommandLine)

Assignment operator.

Parameters
oCommandLine[in] The object to copy from.

◆ Parse()

tResult Parse ( )
protected

Parses the internal buffer.

Returns
Standard result.

◆ Set() [1/3]

tResult Set ( const cCommandLine oCommandLine)

Copy data from another command line objects.

Parameters
oCommandLine[in] The object to copy from.
Returns
Standard result.

◆ Set() [2/3]

tResult Set ( const cString strCommandLine)

Parses a given command line string.

Parameters
strCommandLine[in] The command line string.
Returns
Standard result.

◆ Set() [3/3]

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.