Open 3D Engine EMotionFX Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
MCore::CommandLine Class Reference

#include <CommandLine.h>

Public Member Functions

 CommandLine ()=default
 
 CommandLine (const AZStd::string &commandLine)
 
void GetValue (const char *paramName, const char *defaultValue, AZStd::string *outResult) const
 
void GetValue (const char *paramName, const char *defaultValue, AZStd::string &outResult) const
 
int32 GetValueAsInt (const char *paramName, int32 defaultValue) const
 
float GetValueAsFloat (const char *paramName, float defaultValue) const
 
bool GetValueAsBool (const char *paramName, bool defaultValue) const
 
AZ::Vector3 GetValueAsVector3 (const char *paramName, const AZ::Vector3 &defaultValue) const
 
AZ::Vector4 GetValueAsVector4 (const char *paramName, const AZ::Vector4 &defaultValue) const
 
void GetValue (const char *paramName, Command *command, AZStd::string *outResult) const
 
void GetValue (const char *paramName, Command *command, AZStd::string &outResult) const
 
const AZStd::string & GetValue (const char *paramName, Command *command) const
 
AZ::Outcome< AZStd::string > GetValueIfExists (const char *paramName, Command *command) const
 
int32 GetValueAsInt (const char *paramName, Command *command) const
 
float GetValueAsFloat (const char *paramName, Command *command) const
 
bool GetValueAsBool (const char *paramName, Command *command) const
 
AZ::Vector3 GetValueAsVector3 (const char *paramName, Command *command) const
 
AZ::Vector4 GetValueAsVector4 (const char *paramName, Command *command) const
 
size_t GetNumParameters () const
 
const AZStd::string & GetParameterName (size_t nr) const
 
const AZStd::string & GetParameterValue (size_t nr) const
 
size_t FindParameterIndex (const char *paramName) const
 
bool CheckIfHasValue (const char *paramName) const
 
bool CheckIfHasParameter (const char *paramName) const
 
bool CheckIfHasParameter (const AZStd::string &paramName) const
 
void SetCommandLine (const AZStd::string &commandLine)
 
void Log (const char *debugName="") const
 

Detailed Description

A command line parser class. This class makes it very easy to parse values from a command/argument line. An example of a command line would be "-fullscreen true -xres 800 -yres 1024 -threshold 0.145 -culling false". All parameters must have a value. Use the GetValue, GetValueAsInt, GetValueAsFloat and GetValueAsBool methods to quickly extract values for any given parameter in the command line. A parameter here is for example "xres" or "yres". Each parameter can have a value associated with it.

Constructor & Destructor Documentation

◆ CommandLine() [1/2]

MCore::CommandLine::CommandLine ( )
default

The default constructor. This does not yet process any command line. You have to use the SetCommandLine method to specify the command line to parse.

◆ CommandLine() [2/2]

MCore::CommandLine::CommandLine ( const AZStd::string &  commandLine)
explicit

The extended constructor.

Parameters
commandLineThe command line to parse. This automatically calls the SetCommandLine function.

Member Function Documentation

◆ CheckIfHasParameter()

bool MCore::CommandLine::CheckIfHasParameter ( const char *  paramName) const

Check if the command line contains any parameter with a specified name. The parameter name is not case sensitive.

Parameters
paramNameThe parameter name to check.

◆ CheckIfHasValue()

bool MCore::CommandLine::CheckIfHasValue ( const char *  paramName) const

Check whether a given parameter has a value specified or not. A value is not specified for parameter that have been defined like "-fullscreen -xres 800 -yres 600". In this example command line, the parameter "fullscreen" has no value. Both "xres" and "yres" parameters have values set. The parameter name is not case sensitive.

Parameters
paramNameThe parameter name to check.

◆ FindParameterIndex()

size_t MCore::CommandLine::FindParameterIndex ( const char *  paramName) const

Find the parameter index for a parameter with a specific name. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to search for.
Returns
The index/number of the parameter, or MCORE_INVALIDINDEX32 when no parameter with the specific name has been found.

◆ GetNumParameters()

size_t MCore::CommandLine::GetNumParameters ( ) const

Get the number of parameters that have been detected from the command line string that has been passed to the extended constructor or to the SetCommandLine function.

Returns
The number of parameters that have been detected.

◆ GetParameterName()

const AZStd::string & MCore::CommandLine::GetParameterName ( size_t  nr) const

Get the name of a given parameter.

Parameters
nrThe parameter number, which must be in range of [0 .. GetNumParameters()-1].
Returns
The name of the parameter.

◆ GetParameterValue()

const AZStd::string & MCore::CommandLine::GetParameterValue ( size_t  nr) const

Get the value for a given parameter.

Parameters
nrThe parameter number, which must be in range of [0 .. GetNumParameters()-1].
Returns
The value of the parameter, or "" (an empty string) when no value has been specified.

◆ GetValue() [1/2]

void MCore::CommandLine::GetValue ( const char *  paramName,
Command command,
AZStd::string *  outResult 
) const

Get the value for a parameter with a specified name. If the parameter with the given name does not exist, the default value is returned. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "XRES".
commandThe command to retrieve the default value from (using the command syntax). Returns an empty string if the command syntax can't help.
outResultThe string that will contain the resulting value. This is not allowed to be nullptr.

◆ GetValue() [2/2]

void MCore::CommandLine::GetValue ( const char *  paramName,
const char *  defaultValue,
AZStd::string *  outResult 
) const

Get the value for a parameter with a specified name. If the parameter with the given name does not exist, the default value is returned. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "XRES".
defaultValueThe default value to return in case there is no such parameter with the given name, or if its value has not been specified.
outResultThe resulting value for the parameter. This is NOT allowed to be nullptr.
Returns
The value for the parameter with the specified name.

◆ GetValueAsBool() [1/2]

bool MCore::CommandLine::GetValueAsBool ( const char *  paramName,
bool  defaultValue 
) const

Get the value for a parameter with a specified name, as a boolean. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, true will be returned! This allows you to make command lines such as "-fullscreen -xres 800 -yres 600", where fullscreen has no value. However, since the parameter fullscreen exists, this most likely means it is a mode that needs to be enabled, so this is why true is being returned in such case. Now you can do things such as:

bool fullScreen = commandLine.GetValueAsBool("FullScreen", false);

Now when "-fullscreen" is not specified, false is returned. But when it has been specified, but without value, true is being used. It is also possible to specify "-fullscreen true" or "-fullscreen 1". The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "XRES".
defaultValueThe default value to return in case there is no such parameter with the given name, or if its value has not been specified.
Returns
The value for the parameter with the specified name.

◆ GetValueAsBool() [2/2]

bool MCore::CommandLine::GetValueAsBool ( const char *  paramName,
Command command 
) const

Get the value for a parameter with a specified name, as a boolean. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, true will be returned! This allows you to make command lines such as "-fullscreen -xres 800 -yres 600", where fullscreen has no value. However, since the parameter fullscreen exists, this most likely means it is a mode that needs to be enabled, so this is why true is being returned in such case. Now you can do things such as:

bool fullScreen = commandLine.GetValueAsBool("FullScreen", false);

Now when "-fullscreen" is not specified, false is returned. But when it has been specified, but without value, true is being used. It is also possible to specify "-fullscreen true" or "-fullscreen 1". The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "XRES".
commandThe command to retrieve the default value from (using the command syntax). Returns false if the command syntax can't help.
Returns
The value for the parameter with the specified name.

◆ GetValueAsFloat() [1/2]

float MCore::CommandLine::GetValueAsFloat ( const char *  paramName,
Command command 
) const

Get the value for a parameter with a specified name, as a floating point value. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "THRESHOLD".
commandThe command to retrieve the default value from (using the command syntax). Returns 0.0 if the command syntax can't help.
Returns
The value for the parameter with the specified name.

◆ GetValueAsFloat() [2/2]

float MCore::CommandLine::GetValueAsFloat ( const char *  paramName,
float  defaultValue 
) const

Get the value for a parameter with a specified name, as a floating point value. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "THRESHOLD".
defaultValueThe default value to return in case there is no such parameter with the given name, or if its value has not been specified.
Returns
The value for the parameter with the specified name.

◆ GetValueAsInt() [1/2]

int32 MCore::CommandLine::GetValueAsInt ( const char *  paramName,
Command command 
) const

Get the value for a parameter with a specified name, as an integer value. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "XRES".
commandThe command to retrieve the default value from (using the command syntax). Returns MCORE_INVALIDINDEX32 if the command syntax can't help.
Returns
The value for the parameter with the specified name.

◆ GetValueAsInt() [2/2]

int32 MCore::CommandLine::GetValueAsInt ( const char *  paramName,
int32  defaultValue 
) const

Get the value for a parameter with a specified name, as an integer value. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "XRES".
defaultValueThe default value to return in case there is no such parameter with the given name, or if its value has not been specified.
Returns
The value for the parameter with the specified name.

◆ GetValueAsVector3() [1/2]

AZ::Vector3 MCore::CommandLine::GetValueAsVector3 ( const char *  paramName,
Command command 
) const

Get the value for a parameter with a specified name, as a three component vector. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "THRESHOLD".
commandThe command to retrieve the default value from (using the command syntax). Returns a zero vector if the command syntax can't help.
Returns
The value for the parameter with the specified name.

◆ GetValueAsVector3() [2/2]

AZ::Vector3 MCore::CommandLine::GetValueAsVector3 ( const char *  paramName,
const AZ::Vector3 &  defaultValue 
) const

Get the value for a parameter with a specified name, as a three component vector. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "THRESHOLD".
defaultValueThe default value to return in case there is no such parameter with the given name, or if its value has not been specified.
Returns
The value for the parameter with the specified name.

◆ GetValueAsVector4() [1/2]

AZ::Vector4 MCore::CommandLine::GetValueAsVector4 ( const char *  paramName,
Command command 
) const

Get the value for a parameter with a specified name, as a four component vector. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "THRESHOLD".
commandThe command to retrieve the default value from (using the command syntax). Returns a zero vector if the command syntax can't help.
Returns
The value for the parameter with the specified name.

◆ GetValueAsVector4() [2/2]

AZ::Vector4 MCore::CommandLine::GetValueAsVector4 ( const char *  paramName,
const AZ::Vector4 &  defaultValue 
) const

Get the value for a parameter with a specified name, as a four component vector. If the parameter with the given name does not exist, the default value is returned. If the parameter value exists, but the value specified is empty, the default value is returned as well. The parameter name is not case sensitive.

Parameters
paramNameThe name of the parameter to get the value for, for example this can be "THRESHOLD".
defaultValueThe default value to return in case there is no such parameter with the given name, or if its value has not been specified.
Returns
The value for the parameter with the specified name.

◆ Log()

void MCore::CommandLine::Log ( const char *  debugName = "") const

Logs the contents using MCore::LogInfo. This is useful for debugging sometimes.

Parameters
debugNameThe name of this command line, to make it easier to identify this command line when logging multiple ones.

◆ SetCommandLine()

void MCore::CommandLine::SetCommandLine ( const AZStd::string &  commandLine)

Specify the command line string that needs to be parsed. The extended constructor, which takes a command line string as parameter already automatically calls this method. Before you can use any other methods of this class, you should make a call to this function. The command line string can be something like "-fullscreen -xres 800 -yres 1024 -threshold 0.145 -culling false".

Parameters
commandLineThe command line string to parse.

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