#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 ¶mName) const |
void | SetCommandLine (const AZStd::string &commandLine) |
void | Log (const char *debugName="") const |
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.
|
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.
|
explicit |
The extended constructor.
commandLine | The command line to parse. This automatically calls the SetCommandLine function. |
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.
paramName | The parameter name to check. |
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.
paramName | The parameter name to check. |
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.
paramName | The name of the parameter to search for. |
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.
const AZStd::string & MCore::CommandLine::GetParameterName | ( | size_t | nr | ) | const |
Get the name of a given parameter.
nr | The parameter number, which must be in range of [0 .. GetNumParameters()-1]. |
const AZStd::string & MCore::CommandLine::GetParameterValue | ( | size_t | nr | ) | const |
Get the value for a given parameter.
nr | The parameter number, which must be in range of [0 .. GetNumParameters()-1]. |
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.
paramName | The name of the parameter to get the value for, for example this can be "XRES". |
command | The command to retrieve the default value from (using the command syntax). Returns an empty string if the command syntax can't help. |
outResult | The string that will contain the resulting value. This is not allowed to be nullptr. |
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.
paramName | The name of the parameter to get the value for, for example this can be "XRES". |
defaultValue | The default value to return in case there is no such parameter with the given name, or if its value has not been specified. |
outResult | The resulting value for the parameter. This is NOT allowed to be nullptr. |
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.
paramName | The name of the parameter to get the value for, for example this can be "XRES". |
defaultValue | The default value to return in case there is no such parameter with the given name, or if its value has not been specified. |
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.
paramName | The name of the parameter to get the value for, for example this can be "XRES". |
command | The command to retrieve the default value from (using the command syntax). Returns false if the command syntax can't help. |
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.
paramName | The name of the parameter to get the value for, for example this can be "THRESHOLD". |
command | The command to retrieve the default value from (using the command syntax). Returns 0.0 if the command syntax can't help. |
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.
paramName | The name of the parameter to get the value for, for example this can be "THRESHOLD". |
defaultValue | The default value to return in case there is no such parameter with the given name, or if its value has not been specified. |
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.
paramName | The name of the parameter to get the value for, for example this can be "XRES". |
command | The command to retrieve the default value from (using the command syntax). Returns MCORE_INVALIDINDEX32 if the command syntax can't help. |
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.
paramName | The name of the parameter to get the value for, for example this can be "XRES". |
defaultValue | The default value to return in case there is no such parameter with the given name, or if its value has not been specified. |
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.
paramName | The name of the parameter to get the value for, for example this can be "THRESHOLD". |
command | The command to retrieve the default value from (using the command syntax). Returns a zero vector if the command syntax can't help. |
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.
paramName | The name of the parameter to get the value for, for example this can be "THRESHOLD". |
defaultValue | The default value to return in case there is no such parameter with the given name, or if its value has not been specified. |
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.
paramName | The name of the parameter to get the value for, for example this can be "THRESHOLD". |
command | The command to retrieve the default value from (using the command syntax). Returns a zero vector if the command syntax can't help. |
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.
paramName | The name of the parameter to get the value for, for example this can be "THRESHOLD". |
defaultValue | The default value to return in case there is no such parameter with the given name, or if its value has not been specified. |
void MCore::CommandLine::Log | ( | const char * | debugName = "" | ) | const |
Logs the contents using MCore::LogInfo. This is useful for debugging sometimes.
debugName | The name of this command line, to make it easier to identify this command line when logging multiple ones. |
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".
commandLine | The command line string to parse. |