The command arguments parser base class. More...
#include "murl_util_environment.h"
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 | StringListArrayParameter |
The string list 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 , NUM_PARAMETER_TYPES } |
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. | |
Bool | mAcceptFreeParameters |
The accept free parameters, default false. | |
ParameterType | mFreeParametersType |
The free parameters type, default PARAMETER_TYPE_OPTIONAL. | |
StringArray | mFreeParameters |
The free parameters. | |
String | mLastError |
The last error parameter. | |
Detailed Description
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:
Member Enumeration Documentation
◆ ParameterType
|
protected |
Member Function Documentation
◆ Create() [1/3]
Initialize and parse the command arguments.
Calls DeInit(), deletes all registered parameters, calls Init() and ParseParameters().
- Parameters
-
argC The number of arguments. argV The argument string values.
- Returns
- false if ParseParameters() failed, otherwise the result from IsValid() is returned.
◆ Create() [2/3]
Forward to Create(SInt32 argC, const char** argV).
- Parameters
-
argC The number of arguments. argV The argument string values.
- Returns
- false if ParseParameters() failed, otherwise the result from IsValid() is returned.
◆ Create() [3/3]
|
virtual |
Initialize and parse the command arguments.
See Create(SInt32 argC, const char** argV).
- Parameters
-
args A string array containing the arguments.
- Returns
- false if ParseParameters() failed, otherwise the result from IsValid() is returned.
◆ GetFreeParameters()
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().
- Returns
- The free parameters string array.
◆ Validate()
|
virtual |
Check if all mandatory parameters are set.
- Returns
- true if all mandatory parameters are set.
◆ GetUsage()
|
virtual |
Get the usage string of all registered parameters.
- Returns
- The usage string of all registered parameters.
◆ GetLastError()
|
virtual |
Get the last error parameter.
- Returns
- The last error parameter string.
◆ Register() [1/5]
|
inlineprotected |
Register a new allocated parameter object.
All registered parameter objects are deleted automatically at environment class destruction or when calling Create().
- Parameters
-
param The new allocated parameter object.
- Returns
- The registered parameter object.
References mParameters.
Referenced by Register().
◆ ParseParameters()
|
protectedvirtual |
Parse the command arguments and convert the argument values into the corresponding registered parameter objects.
- Parameters
-
argC The number of arguments. argV The argument string values.
- Returns
- true if successful.
◆ SetAcceptFreeParameters()
|
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.
- Parameters
-
accept true to accept free parameters. type The type of the parameter.
◆ Register() [2/5]
|
inlineprotected |
Create and register a parameter class.
- Parameters
-
type The type of the parameter. longId The long parameter identifier string. shortId The short parameter identifier string. description The parameter description string.
- Template Parameters
-
ParamType The parameter class type to create.
- Returns
- The registered parameter object.
References Register().
◆ Register() [3/5]
|
inlineprotected |
Create and register a parameter class with a default value.
- Parameters
-
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.
- Template Parameters
-
ParamType The parameter class type to create. DataType The default value class type.
- Returns
- The registered parameter object.
References Register().
◆ Register() [4/5]
|
inlineprotected |
Create and register an enumeration parameter class.
- Parameters
-
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.
- Template Parameters
-
ParamType The parameter class type to create. EnumType The enumeration class type.
- Returns
- The registered parameter object.
References Register().
◆ Register() [5/5]
|
inlineprotected |
Create and register an enumeration parameter class with a default value.
- Parameters
-
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.
- Template Parameters
-
ParamType The parameter class type to create. EnumType The enumeration class type.
- Returns
- The registered parameter object.
References Register().
The documentation for this class was generated from the following file:
- murl_util_environment.h