ADTF
Loading...
Searching...
No Matches
cCommandLine

Command line processing. More...

#include <commandline.h>

Public Member Functions

 cCommandLine ()
 Default constructor.
 
 cCommandLine (const cString &strCommandLine)
 Constructor that parses a given command line string.
 
 cCommandLine (const cCommandLine &oCommandLine)
 Copy constructor.
 
cCommandLineoperator= (const cCommandLine &oCommandLine)
 Assignment operator.
 
 cCommandLine (int argc, const char **argv)
 Constructor for standard commandline parameters.
 
virtual ~cCommandLine ()
 Destructor.
 
tResult Set (const cString &strCommandLine)
 Parses a given command line string.
 
tResult Set (const cCommandLine &oCommandLine)
 Copy data from another command line objects.
 
tResult Set (int argc, const char **argv)
 Set data using standard commandline parameters.
 
cString GetString () const
 Builds a command line string by concatenating all parameters.
 
cString GetProperty (const cString &strName, const cString &strDefault=cString::Empty) const
 Returns a property (-propertyname=value).
 
tBool GetFlag (const cString &strName) const
 Returns whether a flag (-flagname) was specified or not.
 
cString GetValue (tInt nIdx, const cString &strDefault=cString::Empty) const
 Returns a command line parameter that is no flag or property.
 
cString GetArg (tInt nIdx, const cString &strDefault=cString::Empty) const
 Returns a command line argument.
 
const cStringGetBuffer () const
 Returns a reference to the internal commandline buffer.
 
const cStringListGetFlags () const
 Returns a list of all specified flags.
 
const cStringListGetValues () const
 Returns a list of all specified values.
 
const cStringMapGetProperties () const
 Returns a map of all specified properties.
 
const tChar ** GetArgv () const
 Returns a pointer to a standard style command line parameter array.
 
tInt GetArgc () const
 Returns the size of the array retreived by GetArgv().
 

Protected Member Functions

tResult Parse ()
 Parses the internal buffer.
 
tResult Initialize ()
 Initializes internal parameters.
 
tResult FreeArgs ()
 Frees the argument list.
 

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 51 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.

References cCommandLine().

◆ 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.

References string_base< cStackString >::Empty.

◆ 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.

References string_base< cStackString >::Empty.

◆ 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.

References string_base< cStackString >::Empty.

◆ 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.

References cCommandLine().

◆ 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.

References cCommandLine().

◆ 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.

Member Data Documentation

◆ m_lstArgv

std::list<cString> m_lstArgv
mutableprotected

Argument list.

Definition at line 66 of file commandline.h.

◆ m_lstFlags

cStringList m_lstFlags
protected

List of flags.

Definition at line 59 of file commandline.h.

◆ m_lstValues

cStringList m_lstValues
protected

List of values.

Definition at line 61 of file commandline.h.

◆ m_mapProperties

cStringMap m_mapProperties
protected

Property map of the commandline.

Definition at line 63 of file commandline.h.

◆ m_nArgc

tInt m_nArgc
mutableprotected

Argument count.

Definition at line 70 of file commandline.h.

◆ m_pArgv

const tChar** m_pArgv
mutableprotected

Argument pointer.

Definition at line 68 of file commandline.h.

◆ m_strBuffer

cString m_strBuffer
protected

Internal buffer.

Definition at line 57 of file commandline.h.