![]() |
Murl Engine API
Version 2018.3
|
The command arguments parser base class. More...
#include <murl_util_environment.h>
The command arguments parser base class.
To create and register command arguments, you must derive from the base class and implement Init() e.g.:
To get the command arguments simply call Create(), e.g. assuming an instance mMyEnvironment exists:
Classes | |
class | ColorParameter |
The color parameter class. More... | |
class | DoubleArrayParameter |
The floating point array parameter class. More... | |
class | DoubleParameter |
The floating point parameter class. More... | |
class | EnumArrayParameter |
The enumeration array parameter template class. More... | |
class | EnumParameter |
The enumeration parameter template class. More... | |
class | Parameter |
The parameter base class. More... | |
class | SInt32ArrayParameter |
The integer array parameter class. More... | |
class | SInt32Parameter |
The integer parameter class. More... | |
class | StringArrayParameter |
The string array parameter class. More... | |
class | StringPairArrayParameter |
The string pair array parameter class. More... | |
class | StringParameter |
The string parameter class. More... | |
class | SwitchParameter |
The boolean parameter class. More... | |
Public Member Functions | |
Environment () | |
The default constructor. | |
virtual | ~Environment () |
The destructor. | |
virtual Bool | Create (SInt32 argC, const char **argV) |
Initialize and parse the command arguments. More... | |
virtual Bool | Create (SInt32 argC, char **argV) |
Forward to Create(SInt32 argC, const char** argV). More... | |
virtual Bool | Create (const StringArray &args) |
Initialize and parse the command arguments. More... | |
const StringArray & | GetFreeParameters () const |
Get the free parameters string array. More... | |
virtual Bool | Validate () |
Check if all mandatory parameters are set. More... | |
virtual String | GetUsage () const |
Get the usage string of all registered parameters. More... | |
virtual const String & | GetLastError () const |
Get the last error parameter. More... | |
Protected Types | |
enum | ParameterType { PARAMETER_TYPE_MANDATORY, PARAMETER_TYPE_OPTIONAL } |
Definition of the parameter types. More... | |
Protected Member Functions | |
virtual void | Init ()=0 |
Overload to initialize and register parameters. | |
virtual void | DeInit () |
Overload to de-initialize, default implementation is empty. | |
template<class ParamType > | |
const ParamType * | Register (ParamType *param) |
Register a new allocated parameter object. More... | |
virtual Bool | ParseParameters (SInt32 argC, const char **argV) |
Parse the command arguments and convert the argument values into the corresponding registered parameter objects. More... | |
void | SetAcceptFreeParameters (Bool accept, ParameterType type) |
Set the free parameters acceptance. More... | |
template<class ParamType > | |
const ParamType * | Register (ParameterType type, const String &longId, const String &shortId, const String &description) |
Create and register a parameter class. More... | |
template<class ParamType , class DataType > | |
const ParamType * | Register (ParameterType type, const String &longId, const String &shortId, const String &description, const DataType &defaultValue) |
Create and register a parameter class with a default value. More... | |
template<class ParamType , class EnumType > | |
const ParamType * | Register (ParameterType type, const String &longId, const String &shortId, const String &description, const Enum< EnumType > &enumClass) |
Create and register an enumeration parameter class. More... | |
template<class ParamType , class EnumType > | |
const ParamType * | Register (ParameterType type, const String &longId, const String &shortId, const String &description, const Enum< EnumType > &enumClass, EnumType defaultValue) |
Create and register an enumeration parameter class with a default value. More... | |
Protected Attributes | |
Array< Parameter::AutoPtr > | mParameters |
The registered parameter objects. More... | |
Bool | mAcceptFreeParameters |
The accept free parameters, default false. More... | |
ParameterType | mFreeParametersType |
The free parameters type, default PARAMETER_TYPE_OPTIONAL. More... | |
StringArray | mFreeParameters |
The free parameters. More... | |
String | mLastError |
The last error parameter. More... | |
|
protected |
Initialize and parse the command arguments.
Calls DeInit(), deletes all registered parameters, calls Init() and ParseParameters().
argC | The number of arguments. |
argV | The argument string values. |
Forward to Create(SInt32 argC, const char** argV).
argC | The number of arguments. |
argV | The argument string values. |
|
virtual |
Initialize and parse the command arguments.
See Create(SInt32 argC, const char** argV).
args | A string array containing the arguments. |
const StringArray& Murl::Util::Environment::GetFreeParameters | ( | ) | const |
Get the free parameters string array.
Free parameters are parameters which have no leading '-' option, e.g. a list of file names. To accept this kind of parameters SetAcceptFreeParameters() must be called before Create() or during Init().
|
virtual |
Check if all mandatory parameters are set.
|
virtual |
Get the usage string of all registered parameters.
|
virtual |
Get the last error parameter.
|
inlineprotected |
Register a new allocated parameter object.
All registered parameter objects are deleted automatically at environment class destruction or when calling Create().
param | The new allocated parameter object. |
|
protectedvirtual |
Parse the command arguments and convert the argument values into the corresponding registered parameter objects.
argC | The number of arguments. |
argV | The argument string values. |
|
protected |
Set the free parameters acceptance.
Free parameters are parameters which have no leading '-' option, e.g. a list of file names. To accept this kind of parameters this method must be called before Create() or during Init().
Use GetFreeParameters() to read the parameters after parsing.
accept | true to accept free parameters. |
type | The type of the parameter. |
|
inlineprotected |
Create and register a parameter class.
type | The type of the parameter. |
longId | The long parameter identifier string. |
shortId | The short parameter identifier string. |
description | The parameter description string. |
ParamType | The parameter class type to create. |
|
inlineprotected |
Create and register a parameter class with a default value.
type | The type of the parameter. |
longId | The long parameter identifier string. |
shortId | The short parameter identifier string. |
description | The parameter description string. |
defaultValue | The parameter default value. |
ParamType | The parameter class type to create. |
DataType | The default value class type. |
|
inlineprotected |
Create and register an enumeration parameter class.
type | The type of the parameter. |
longId | The long parameter identifier string. |
shortId | The short parameter identifier string. |
description | The parameter description string. |
enumClass | The enumeration string mapping class. |
ParamType | The parameter class type to create. |
EnumType | The enumeration class type. |
|
inlineprotected |
Create and register an enumeration parameter class with a default value.
type | The type of the parameter. |
longId | The long parameter identifier string. |
shortId | The short parameter identifier string. |
description | The parameter description string. |
enumClass | The enumeration string mapping class. |
defaultValue | The parameter default value. |
ParamType | The parameter class type to create. |
EnumType | The enumeration class type. |
|
protected |
The registered parameter objects.
|
protected |
The accept free parameters, default false.
|
protected |
The free parameters type, default PARAMETER_TYPE_OPTIONAL.
|
protected |
The free parameters.
|
protected |
The last error parameter.