ConfigurationHelper Class Reference

The class containing some helper function for configuration parameters. More...

Static Public Member Functions

static bool getBool (ConfigurationParameters &params, QString paramPath, bool def=false)
 Return the value of parameter as boolean, if the parameter has not been setted or the value is not a boolean, it will return the defaul value specified The valid value converted in boolean are:
 
static QVector< bool > getBoolVector (ConfigurationParameters &params, QString paramPath, QString def=QString())
 Returns a vector of booleans from the specified parameter.
 
static QStringList getDescribedParameterNames (QString type, QString prefix=QString())
 return the list of all parameter's type described in Factory::getTypeDescriptions()
 
static QStringList getDescribedSubgroupNames (QString type, QString prefix=QString())
 return the list of all subgroup's type described in Factory::getTypeDescriptions()
 
static double getDouble (ConfigurationParameters &params, QString paramPath, double def=0)
 Return the value of parameter as double, if the parameter has not been setted or the value is not an double, it will return the defaul value specified.
 
static int getInt (ConfigurationParameters &params, QString paramPath, int def=0)
 Return the value of parameter as integer, if the parameter has not been setted or the value is not an integer, it will return the defaul value specified.
 
static QVector< int > getIntegerVector (ConfigurationParameters &params, QString paramPath, QString def=QString())
 Returns a vector of integers from the specified parameter.
 
static QStringList getParameterEnumValues (QString type, QString paramName)
 return the possible enum values as QStringList for the parameter
 
static QString getParameterTypeName (QString type, QString paramName)
 return the type of the parameter as declared in Factory::getTypeDescriptions()
 
static QString getString (ConfigurationParameters &params, QString paramPath, QString def=QString())
 Return the value of parameter as QString, if the parameter has not been setted, it will return the default value specified.
 
static QStringList getStringList (ConfigurationParameters &params, QString paramPath, QString delimiter=QString(" "))
 Return the value of parameter as QStringList, if the parameter has not been setted, it will return an empty QStringList.
 
static unsigned int getUnsignedInt (ConfigurationParameters &params, QString paramPath, unsigned int def=0)
 Return the value of parameter as unsigned integer, if the parameter has not been setted or the value is not an unsigned integer, it will return the defaul value specified.
 
static QVector< unsigned int > getUnsignedIntegerVector (ConfigurationParameters &params, QString paramPath, QString def=QString())
 Returns a vector of unsigned integers from the specified parameter.
 
static QVector< double > getVector (ConfigurationParameters &params, QString paramPath, QString def=QString())
 Return a QVector of double from the parameters specified It helps on parsing parameters like:
 
static bool hasGroup (ConfigurationParameters &params, QString group)
 Return true if the group exists.
 
static bool hasParameter (ConfigurationParameters &params, QString group, QString paramName)
 Return true if the parameter exist and is not empty into the group.
 
static bool isRuntimeParameter (QString type, QString paramName)
 Returns true if the parameter can be modified at runtime using ParameterSettable::setRuntimeParameter.
 
static bool parameterIsDouble (QString type, QString paramName)
 return true if the real parameter is double, otherwise return false
 
static void throwUserConfigError (QString paramName, QString paramValue, QString description)
 A utility function to ease throwing the exception UserDefinedCheckFailureException.
 
static void throwUserMissingResourceError (QString resourceName, QString description)
 A utility function to ease throwing the exception UserRequiredResourceMissingException.
 

Detailed Description

The class containing some helper function for configuration parameters.

Definition at line 34 of file configurationhelper.h.

Member Function Documentation

bool getBool ( ConfigurationParameters params,
QString  paramPath,
bool  def = false 
)
static

Return the value of parameter as boolean, if the parameter has not been setted or the value is not a boolean, it will return the defaul value specified The valid value converted in boolean are:

param = true
param = false
param = T ; <- converted as TRUE
param = F ; <- converted as FALSE
; any case of the above values are correctly converted
param = 1 ; <- converted as TRUE
param = 0 ; <- converted as FALSE

Any other values are not accepted.

Parameters
paramPathis the full path to the parameter; i.e. prefix + "paramName" in a typical use of configure method
defis the default value returned if the conversion fails

Definition at line 59 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

Referenced by ConfigurationHelper::isRuntimeParameter().

QVector< bool > getBoolVector ( ConfigurationParameters params,
QString  paramPath,
QString  def = QString() 
)
static

Returns a vector of booleans from the specified parameter.

This transforms the string value of the parameter to a vector of booleans with true corresponding to ones in the string and false to zeros. The string must be made up only of "0" and "1"

Parameters
paramsthe configuration parameters object
paramPatha string with only 0 and 1
defthe string to use if the parameter is not present
Returns
a vector of bools. If the string contains characters other than 0 or 1 returns an empty vector

Definition at line 136 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

QStringList getDescribedParameterNames ( QString  type,
QString  prefix = QString() 
)
static

return the list of all parameter's type described in Factory::getTypeDescriptions()

This function return the name of all parameter's type described in the Factory::getTypeDescriptions() corresponding to the type specified

Parameters
typethe type name of the object (or the full path where the type description is)
prefixis the subgroup prefix to get the parameters described in a subgroup
Returns
a list of parameter's name

Definition at line 181 of file configurationhelper.cpp.

References ParameterSettable::fullSubgroupDescriptionPath(), ConfigurationParameters::getGroupsList(), and Factory::getTypeDescriptions().

QStringList getDescribedSubgroupNames ( QString  type,
QString  prefix = QString() 
)
static

return the list of all subgroup's type described in Factory::getTypeDescriptions()

This function return the name of all subgroup's type described in the Factory::getTypeDescriptions() corresponding to the type specified

Parameters
typethe type name of the object (or the full path where the type description is)
prefixis the subgroup prefix to get the subgroups described into another subgroup
Returns
a list of subgroup's name

Definition at line 186 of file configurationhelper.cpp.

References ParameterSettable::fullSubgroupDescriptionPath(), ConfigurationParameters::getGroupsList(), and Factory::getTypeDescriptions().

double getDouble ( ConfigurationParameters params,
QString  paramPath,
double  def = 0 
)
static

Return the value of parameter as double, if the parameter has not been setted or the value is not an double, it will return the defaul value specified.

Parameters
paramPathis the full path to the parameter; i.e. prefix + "paramName" in a typical use of configure method
defis the default value returned if the conversion fails

Definition at line 48 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

int getInt ( ConfigurationParameters params,
QString  paramPath,
int  def = 0 
)
static

Return the value of parameter as integer, if the parameter has not been setted or the value is not an integer, it will return the defaul value specified.

Parameters
paramPathis the full path to the parameter; i.e. prefix + "paramName" in a typical use of configure method
defis the default value returned if the conversion fails

Definition at line 26 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

QVector< int > getIntegerVector ( ConfigurationParameters params,
QString  paramPath,
QString  def = QString() 
)
static

Returns a vector of integers from the specified parameter.

This function helps parsing parameters like:

[GROUP]
param = 10 -3 4 23 -12

The value of the parameter should be a space-separated list of integers

Parameters
paramsthe configuration parameters object
paramPaththe name of the parameter to parse
defthe string to use if the parameter is not present
Returns
a vector of integers. If the parameter contains some non-numeric string, a 0 is returned in the corresponding position

Definition at line 98 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

QStringList getParameterEnumValues ( QString  type,
QString  paramName 
)
static

return the possible enum values as QStringList for the parameter

Parameters
typethe type name of the object (or the full path where the type description is)
paramNameis the name of the parameter
Warning
it return an empty QStringList if the parameter is not an enum type

Definition at line 213 of file configurationhelper.cpp.

References ParameterSettable::fullParameterDescriptionPath(), ConfigurationHelper::getStringList(), and Factory::getTypeDescriptions().

QString getParameterTypeName ( QString  type,
QString  paramName 
)
static

return the type of the parameter as declared in Factory::getTypeDescriptions()

Parameters
typethe type name of the object (or the full path where the type description is)
paramNameis the name of the parameter
Returns
the type name; the possible values are (case-sensitive):

string

int

real

bool

enum

object

missing

Note
the value 'missing' is returned when the type is not specified in the parameter's description

Definition at line 191 of file configurationhelper.cpp.

References ParameterSettable::fullParameterDescriptionPath(), ConfigurationHelper::getString(), and Factory::getTypeDescriptions().

QString getString ( ConfigurationParameters params,
QString  paramPath,
QString  def = QString() 
)
static

Return the value of parameter as QString, if the parameter has not been setted, it will return the default value specified.

Parameters
paramPathis the full path to the parameter; i.e. prefix + "paramName" in a typical use of configure method
defis the default value returned if the parameters does not exists
Note
If this method is called with def equal to QString(), then it behaves exactly as ConfigurationParameters::getValue

Definition at line 71 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

Referenced by RuntimeParameterSetter::get(), ConfigurationHelper::getParameterTypeName(), ConfigurationHelper::parameterIsDouble(), and RuntimeParameterSetter::set().

QStringList getStringList ( ConfigurationParameters params,
QString  paramPath,
QString  delimiter = QString(" ") 
)
static

Return the value of parameter as QStringList, if the parameter has not been setted, it will return an empty QStringList.

Parameters
paramPathis the full path to the parameter; i.e. prefix + "paramName" in a typical use of configure method
delimiteris the string that delimits the elements of the QStringList

Definition at line 79 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

Referenced by ConfigurationHelper::getParameterEnumValues().

unsigned int getUnsignedInt ( ConfigurationParameters params,
QString  paramPath,
unsigned int  def = 0 
)
static

Return the value of parameter as unsigned integer, if the parameter has not been setted or the value is not an unsigned integer, it will return the defaul value specified.

Parameters
paramPathis the full path to the parameter; i.e. prefix + "paramName" in a typical use of configure method
defis the default value returned if the conversion fails

Definition at line 37 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

QVector< unsigned int > getUnsignedIntegerVector ( ConfigurationParameters params,
QString  paramPath,
QString  def = QString() 
)
static

Returns a vector of unsigned integers from the specified parameter.

This function helps parsing parameters like:

[GROUP]
param = 10 3 4 23 12

The value of the parameter should be a space-separated list of unsigned integers

Parameters
paramsthe configuration parameters object
paramPaththe name of the parameter to parse
defthe string to use if the parameter is not present
Returns
a vector of unsigned integers. If the parameter contains some non-numeric string, a 0 is returned in the corresponding position

Definition at line 117 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

QVector< double > getVector ( ConfigurationParameters params,
QString  paramPath,
QString  def = QString() 
)
static

Return a QVector of double from the parameters specified It helps on parsing parameters like:

[GROUP]
param = 10 3.2 4 23 12

and it returns a QVector containing the values

Parameters
paramPathis the full path to the parameter; i.e. prefix + "paramName" in a typical use of configure method
defthe string to use if the parameter is not present
Note
if the list of values in the parameter contains some non-numeric strings then in the corresponding position a zero will be placed into the vector:
[GROUP]
param = 10 3.2 garbage 4 23 12
getVector will return: { 10 3.2 0.0 4 23 12 }

Definition at line 83 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

bool hasGroup ( ConfigurationParameters params,
QString  group 
)
static

Return true if the group exists.

Parameters
groupis the full path of the group to search; i.e: /parentGroup1/parentGroup2/groupToCheck

Definition at line 154 of file configurationhelper.cpp.

References ConfigurationParameters::getGroupsList(), and ConfigurationParameters::isCaseSensitive().

bool hasParameter ( ConfigurationParameters params,
QString  group,
QString  paramName 
)
static

Return true if the parameter exist and is not empty into the group.

Parameters
groupis the full path of the group containing the parameter
paramNameis the name of the parameter to check
Returns
true if the parameter exists and its value is not empty, otherwise return false

Definition at line 167 of file configurationhelper.cpp.

References ConfigurationParameters::getValue().

bool isRuntimeParameter ( QString  type,
QString  paramName 
)
static

Returns true if the parameter can be modified at runtime using ParameterSettable::setRuntimeParameter.

Parameters
typethe type name of the object (or the full path where the type description is)
paramNameis the name of the parameter

Definition at line 198 of file configurationhelper.cpp.

References ParameterSettable::fullParameterDescriptionPath(), ConfigurationHelper::getBool(), and Factory::getTypeDescriptions().

bool parameterIsDouble ( QString  type,
QString  paramName 
)
static

return true if the real parameter is double, otherwise return false

Parameters
typethe type name of the object (or the full path where the type description is)
paramNameis the name of the parameter
Warning
in the description the precision is present only for runtime parameter with real type

Definition at line 205 of file configurationhelper.cpp.

References ParameterSettable::fullParameterDescriptionPath(), ConfigurationHelper::getString(), and Factory::getTypeDescriptions().

void throwUserConfigError ( QString  paramName,
QString  paramValue,
QString  description 
)
static

A utility function to ease throwing the exception UserDefinedCheckFailureException.

This function accepts QStrings instead of const char* to allow easier formatting of the error messages. This does never return as the exception is always thrown

Parameters
paramNamethe name of the parameter on which the check failed
paramValuethe value of the parameter that caused the check to fail
descriptiona description of the error

Definition at line 171 of file configurationhelper.cpp.

void throwUserMissingResourceError ( QString  resourceName,
QString  description 
)
static

A utility function to ease throwing the exception UserRequiredResourceMissingException.

This function accepts QStrings instead of const char* to allow easier formatting of the error messages. This does never return as the exception is always thrown

Parameters
resourceNamethe name of the missing resource
descriptiona description of the error

Definition at line 176 of file configurationhelper.cpp.


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