ezEngine  Milestone 7
ezCommandLineUtils Class Reference

This is a helper class to parse command lines. More...

#include <CommandLineUtils.h>

Public Member Functions

void SetCommandLine (ezUInt32 argc, const char **argv)
 Initializes ezCommandLineUtils from the parameter arguments that were passed to the application.
 
ezUInt32 GetParameterCount () const
 Returns the total number of command line parameters (excluding the program path, which is often passed as the first parameter).
 
const char * GetParameter (ezUInt32 uiParam) const
 Returns the n-th parameter string that was passed to the application.
 
ezInt32 GetOptionIndex (const char *szOption, bool bCaseSensitive=false) const
 Returns the index at which the given option string can be found in the parameter list. More...
 
ezUInt32 GetStringOptionArguments (const char *szOption, bool bCaseSensitive=false) const
 Returns how many arguments follow behind the option with the name szOption. More...
 
const char * GetStringOption (const char *szOption, ezUInt32 uiArgument=0, const char *szDefault="", bool bCaseSensitive=false) const
 Returns the n-th parameter to the command line option with the name szOption. More...
 
bool GetBoolOption (const char *szOption, bool bDefault=false, bool bCaseSensitive=false) const
 Returns a boolean interpretation of the option szOption or bDefault if it cannot be found. More...
 
ezInt32 GetIntOption (const char *szOption, ezInt32 iDefault=0, bool bCaseSensitive=false) const
 Returns an integer interpretation of the option szOption or iDefault if it cannot be found. More...
 
double GetFloatOption (const char *szOption, double fDefault=0.0, bool bCaseSensitive=false) const
 Returns a float interpretation of the option szOption or fDefault if it cannot be found. More...
 

Static Public Member Functions

static ezCommandLineUtilsGetInstance ()
 Returns one global instance of ezCommandLineUtils.
 

Private Attributes

ezDynamicArray< ezStringm_Commands
 

Detailed Description

This is a helper class to parse command lines.

Initialize it using SetCommandLine(). Then query for command line options using GetStringOption(), GetBoolOption(), GetIntOption() or GetFloatOption()

Member Function Documentation

bool ezCommandLineUtils::GetBoolOption ( const char *  szOption,
bool  bDefault = false,
bool  bCaseSensitive = false 
) const

Returns a boolean interpretation of the option szOption or bDefault if it cannot be found.

Parameters
szOptionThe name of the option to search for. All option-names must start with a hyphen.
bDefaultThe default value to use when no other value can be derived.
bCaseSensitiveWhether it should be searched case-sensitive for the option with name szOption.
Returns
If an option with the name szOption can be found, which has no parameters, it is interpreted as 'true'. If there is one parameter following, it is interpreted using ezConversionUtils::StringToBool(). If that conversion fails, bDefault is returned.
double ezCommandLineUtils::GetFloatOption ( const char *  szOption,
double  fDefault = 0.0,
bool  bCaseSensitive = false 
) const

Returns a float interpretation of the option szOption or fDefault if it cannot be found.

Parameters
szOptionThe name of the option to search for. All option-names must start with a hyphen.
fDefaultThe default value to use when no other value can be derived.
bCaseSensitiveWhether it should be searched case-sensitive for the option with name szOption.
Returns
If an option with the name szOption can be found, and there is one parameter following, it is interpreted using ezConversionUtils::StringToFloat(). If that conversion fails or there is no such option or no parameter follows it, fDefault is returned.
ezInt32 ezCommandLineUtils::GetIntOption ( const char *  szOption,
ezInt32  iDefault = 0,
bool  bCaseSensitive = false 
) const

Returns an integer interpretation of the option szOption or iDefault if it cannot be found.

Parameters
szOptionThe name of the option to search for. All option-names must start with a hyphen.
iDefaultThe default value to use when no other value can be derived.
bCaseSensitiveWhether it should be searched case-sensitive for the option with name szOption.
Returns
If an option with the name szOption can be found, and there is one parameter following, it is interpreted using ezConversionUtils::StringToInt(). If that conversion fails or there is no such option or no parameter follows it, iDefault is returned.
ezInt32 ezCommandLineUtils::GetOptionIndex ( const char *  szOption,
bool  bCaseSensitive = false 
) const

Returns the index at which the given option string can be found in the parameter list.

Parameters
szOptionThe name of the command line option. Must start with a hyphen (-)
bCaseSensitiveWhether the option name szOption shall be searched case sensitive.
Returns
-1 When no option with the given name is found. Otherwise the index at which the option can be found. This can be passed to GetParameter() or GetStringOptionArguments().
const char * ezCommandLineUtils::GetStringOption ( const char *  szOption,
ezUInt32  uiArgument = 0,
const char *  szDefault = "",
bool  bCaseSensitive = false 
) const

Returns the n-th parameter to the command line option with the name szOption.

If the option does not exist or does not have that many parameters, szDefault is returned.

ezUInt32 ezCommandLineUtils::GetStringOptionArguments ( const char *  szOption,
bool  bCaseSensitive = false 
) const

Returns how many arguments follow behind the option with the name szOption.

Everything that does not start with a hyphen is considered to be an additional parameter for the option.


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