22 #include <Information.hpp> 29 #include <QStringList> 30 #include <QTextStream> 38 namespace mgx {
namespace util {
120 explicit Parms(
int verboseLevel = 1);
135 VerboseLevel = (vl < 0) ? 0 : vl;
149 return Parameters.empty();
169 template <
typename T>
bool operator()(
const QString& section,
const QString& key, T& value);
178 bool operator()(
const QString& section,
const QString& key,
bool& value);
184 bool operator()(
const QString& section,
const QString& key,
int& value);
190 bool operator()(
const QString& section,
const QString& key,
float& value);
196 bool operator()(
const QString& section,
const QString& key,
double& value);
205 bool operator()(
const QString& section,
const QString& key, std::string& value);
222 template <
typename T>
bool operator()(
const QString& section,
const QString& key, T& value,
const T& def);
238 template <
typename Container>
bool all(
const QString& section,
const QString& key, Container& value);
245 bool all(
const QString& section,
const QString& key, std::vector<bool>& value);
251 bool all(
const QString& section,
const QString& key, std::vector<int>& value);
257 bool all(
const QString& section,
const QString& key, std::vector<float>& value);
263 bool all(
const QString& section,
const QString& key, std::vector<double>& value);
269 bool all(
const QString& section,
const QString& key, std::vector<std::string>& value);
275 bool all(
const QString& section,
const QString& key, std::vector<QString>& value);
297 template <
typename T,
typename Container>
bool all(
const QString& section, std::map<QString, Container>& values);
304 bool all(
const QString& section, std::map<
QString, std::vector<bool> >& value);
310 bool all(
const QString& section, std::map<
QString, std::vector<int> >& value);
316 bool all(
const QString& section, std::map<
QString, std::vector<float> >& value);
322 bool all(
const QString& section, std::map<
QString, std::vector<double> >& value);
328 bool all(
const QString& section, std::map<
QString, std::vector<std::string> >& value);
334 bool all(
const QString& section, std::map<
QString, std::vector<QString> >& value);
340 bool all(
const QString& section, std::map<QString, QStringList>& value);
363 bool readValue(
const QString& value,
bool& variable);
371 bool readValue(
const QString& value, std::string& variable);
388 template <
typename T>
bool readValue(
const QString& value, std::vector<T>& variable);
397 template <
typename T>
bool readValue(
const QString& value, std::list<T>& variable);
406 template <
typename T>
bool readValue(
const QString& value, std::set<T>& variable);
415 template <
typename T>
bool readValue(
const QString& value, T& variable);
417 template <
typename T,
typename InsertIterator>
bool readContainer(
const QString& value, InsertIterator container);
435 std::map<QString, QStringList> Parameters;
459 template <
typename T,
typename InsertIterator>
bool Parms::readContainer(
const QString& value, InsertIterator it)
463 while(!iss.
atEnd() and iss.
status() == QTextStream::Ok) {
471 template <
typename T>
bool Parms::readValue(
const QString& value, std::vector<T>& variable)
473 return readContainer<T>(value, std::back_insert_iterator<std::vector<T> >(variable));
476 template <
typename T>
bool Parms::readValue(
const QString& value, std::list<T>& variable)
478 return readContainer<T>(value, std::back_insert_iterator<std::list<T> >(variable));
481 template <
typename T>
bool Parms::readValue(
const QString& value, std::set<T>& variable)
483 return readContainer<T>(value, std::insert_iterator<std::set<T> >(variable, variable.end()));
486 template <
typename T>
bool Parms::readValue(
const QString& value, T& variable)
491 return iss.
status() == QTextStream::Ok;
497 if(!extractValues(section, key, values))
500 if((values.size() > 1) && (VerboseLevel > 1)) {
501 Information::err <<
"Parms::operator():Warning multiple value for key [" << section <<
"]" << key
502 <<
", last one used.\n" << flush;
505 if(!readValue(values.back(), value)) {
506 if(VerboseLevel > 0) {
507 Information::err <<
"Parms::operator():Error getting value for key [" << section <<
"]" << key <<
" value " 508 << values.back() <<
"\n" << flush;
519 if(!(*
this)(section, key, value)) {
521 if(VerboseLevel > 2) {
522 Information::err <<
"Parms::operator()::Info key [" << section <<
"]" << key
523 <<
" not found, using default value" << endl;
534 typedef typename Container::value_type T;
537 if(!extractValues(section, key, values))
540 std::insert_iterator<Container> it(value, value.end());
541 forall(
const QString& val, values) {
543 if(readValue(val, single_value)) {
544 *it++ = (
const T&)single_value;
546 if(VerboseLevel > 2) {
547 Information::err <<
"Parms::all:Error reading key [" << section <<
"]" << key <<
" with value " << val
557 template <
typename T,
typename Container>
bool Parms::all(
const QString& section, std::map<QString, Container>& result)
561 typedef std::map<QString, QStringList>::value_type value_type;
563 int pos = section.
size() + 1;
564 forall(
const value_type& pair, Parameters) {
565 QString sec(pair.first.mid(0, pos - 1));
568 QString key(pair.first.mid(pos));
569 Container& value = result[key];
571 forall(
const QString& val, pair.second) {
573 if(readValue(val, single_value)) {
574 value.push_back(single_value);
576 if(VerboseLevel > 2) {
577 Information::err <<
"Parms::all:Error reading key [" << section <<
"]" << key
578 <<
" with value " << val << endl;
This file contains the defines the forall loops.
bool isLoaded() const
Returns true if the parameter object has been correctly loaded.
Definition: Parms.hpp:141
bool empty() const
Returns true if the parameter file was empty (e.g.
Definition: Parms.hpp:148
bool operator()(const QString §ion, const QString &key, T &value)
This operator retrieve a single parameter.
Definition: Parms.hpp:494
void verboseLevel(int vl)
Change the verbosity level.
Definition: Parms.hpp:134
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:115
bool all(const QString §ion, const QString &key, Container &value)
This operator retrieves all parameters with same [section]key.
Definition: Parms.hpp:531