|
MorphoGraphX
2.0-1-227
|
A utility class to parse L-Studio like parameter files. More...
#include <Parms.hpp>
Public Member Functions | |
| Parms (int verboseLevel=1) | |
| Default constructor, with no file. More... | |
| Parms (const QString &parmFile, int verboseLevel=1) | |
| Constructor of the parameter file. More... | |
| ~Parms () | |
| void | verboseLevel (int vl) |
| Change the verbosity level. More... | |
| bool | isLoaded () const |
| Returns true if the parameter object has been correctly loaded. More... | |
| bool | empty () const |
| Returns true if the parameter file was empty (e.g. More... | |
| template<typename T > | |
| bool | operator() (const QString §ion, const QString &key, T &value) const |
| This operator retrieve a single parameter. More... | |
| bool | operator() (const QString §ion, const QString &key, bool &value) const |
| Retrieve a single parameter. More... | |
| bool | operator() (const QString §ion, const QString &key, int &value) const |
| Retrieve a single parameter. More... | |
| bool | operator() (const QString §ion, const QString &key, float &value) const |
| Retrieve a single parameter. More... | |
| bool | operator() (const QString §ion, const QString &key, double &value) const |
| Retrieve a single parameter. More... | |
| bool | operator() (const QString §ion, const QString &key, std::string &value) const |
| Retrieve a single parameter. More... | |
| bool | operator() (const QString §ion, const QString &key, QString &value) const |
| Retrieve a single parameter. More... | |
| template<typename T > | |
| bool | operator() (const QString §ion, const QString &key, T &value, const T &def) |
Variation on the previous, but if the [section]key is not found, an information message is issued (instead of an error) and value is set up to def. More... | |
| template<typename Container > | |
| bool | all (const QString §ion, const QString &key, Container &value) |
| This operator retrieves all parameters with same [section]key. More... | |
| bool | all (const QString §ion, const QString &key, std::vector< bool > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, const QString &key, std::vector< int > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, const QString &key, std::vector< float > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, const QString &key, std::vector< double > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, const QString &key, std::vector< std::string > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, const QString &key, std::vector< QString > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, const QString &key, QStringList &value) |
| Retrieve a all parameters with same [section]key. More... | |
| template<typename T , typename Container > | |
| bool | all (const QString §ion, std::map< QString, Container > &values) |
| This operator retrieves all parameters with same [section]. More... | |
| bool | all (const QString §ion, std::map< QString, std::vector< bool > > &value) |
| Retrieve a all parameters with same [section]. More... | |
| bool | all (const QString §ion, std::map< QString, std::vector< int > > &value) |
| Retrieve a all parameters with same [section]. More... | |
| bool | all (const QString §ion, std::map< QString, std::vector< float > > &value) |
| Retrieve a all parameters with same [section]. More... | |
| bool | all (const QString §ion, std::map< QString, std::vector< double > > &value) |
| Retrieve a all parameters with same [section]. More... | |
| bool | all (const QString §ion, std::map< QString, std::vector< std::string > > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, std::map< QString, std::vector< QString > > &value) |
| Retrieve a all parameters with same [section]key. More... | |
| bool | all (const QString §ion, std::map< QString, QStringList > &value) |
| Retrieve a all parameters with same [section]key. More... | |
A utility class to parse L-Studio like parameter files.
The basic information in the parameter file is a key associated to a value, possibly with a C++-like comment:
Keys can be organized in sections:
Empty line or comment-only line are ignored, any other line will raise an error. The default section is named with an empty string "".
Here is an example:
To read user-defined typed as parameter, it is enough to overload the function
T being the type of the parameter to read.
If the same key is used may times in the same section, either all the values can be retrieved using the Parms::all() method, or only the last can be retrieved using the normal Parms::operator()().
The class accepts 5 verbosity levels:
Debug information output the raw string before evaluation to set up a parameter.
|
explicit |
Default constructor, with no file.
| mgx::Parms::Parms | ( | const QString & | parmFile, |
| int | verboseLevel = 1 |
||
| ) |
Constructor of the parameter file.
| mgx::Parms::~Parms | ( | ) |
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| Container & | value | ||
| ) |
This operator retrieves all parameters with same [section]key.
| section | Section in which the parameter is looked for |
| key | Key to look for |
| value | Variable to set up |
value is filled with the different values found having same [section]key. If none, value is simply empty. The only error that can arise is a reading error, if one parameter has invalid value. This parameter will simply be ignored, all other parameters being read.
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| QStringList & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| std::vector< bool > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| std::vector< double > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| std::vector< float > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| std::vector< int > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| std::vector< QString > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| const QString & | key, | ||
| std::vector< std::string > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, Container > & | values | ||
| ) |
This operator retrieves all parameters with same [section].
| section | Section in which the parameter is looked for |
| value | Variable to set up |
value is filled with the different keys found in [section] and, for each key, the vector of all the values associated to it. If none, value is simply empty. The only error that can arise is a reading error, if one parameter has invalid value. This parameter will simply be ignored, all other parameters being read.
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, QStringList > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, std::vector< bool > > & | value | ||
| ) |
Retrieve a all parameters with same [section].
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, std::vector< double > > & | value | ||
| ) |
Retrieve a all parameters with same [section].
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, std::vector< float > > & | value | ||
| ) |
Retrieve a all parameters with same [section].
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, std::vector< int > > & | value | ||
| ) |
Retrieve a all parameters with same [section].
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, std::vector< QString > > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
| bool mgx::Parms::all | ( | const QString & | section, |
| std::map< QString, std::vector< std::string > > & | value | ||
| ) |
Retrieve a all parameters with same [section]key.
|
inline |
|
inline |
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| bool & | value | ||
| ) | const |
Retrieve a single parameter.
Boolean value must read "true" or "false", case being meaningless.
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| double & | value | ||
| ) | const |
Retrieve a single parameter.
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| float & | value | ||
| ) | const |
Retrieve a single parameter.
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| int & | value | ||
| ) | const |
Retrieve a single parameter.
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| QString & | value | ||
| ) | const |
Retrieve a single parameter.
For string, the value is the whole line with whitespaces and comment stripped before and after the parameter.
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| std::string & | value | ||
| ) | const |
Retrieve a single parameter.
For string, the value is the whole line with whitespaces and comment stripped before and after the parameter.
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| T & | value | ||
| ) | const |
This operator retrieve a single parameter.
| section | Section in which the parameter is looked for |
| key | Key to look for |
| value | Variable to set up if possible |
If the [section]key exists, value is set up to the parameter value. Any key placed before the first section is considered in the first secion. If the [section]key is multiply defined, only the last one is taken and a warning is issued (see Verbosity). If the [section]key does not exist, or its content cannot be interpreted as the requested type, then ar error is issued.
| bool mgx::Parms::operator() | ( | const QString & | section, |
| const QString & | key, | ||
| T & | value, | ||
| const T & | def | ||
| ) |
|
inline |
1.8.17