12 #include <Information.hpp>
19 #include <QStringList>
20 #include <QTextStream>
28 namespace mgx {
namespace util {
110 explicit Parms(
int verboseLevel = 1);
125 VerboseLevel = (vl < 0) ? 0 : vl;
139 return Parameters.empty();
159 template <
typename T>
bool operator()(
const QString& section,
const QString& key, T& value);
168 bool operator()(
const QString& section,
const QString& key,
bool& value);
174 bool operator()(
const QString& section,
const QString& key,
int& value);
180 bool operator()(
const QString& section,
const QString& key,
float& value);
186 bool operator()(
const QString& section,
const QString& key,
double& value);
195 bool operator()(
const QString& section,
const QString& key, std::string& value);
212 template <
typename T>
bool operator()(
const QString& section,
const QString& key, T& value,
const T& def);
228 template <
typename Container>
bool all(
const QString& section,
const QString& key, Container& value);
235 bool all(
const QString& section,
const QString& key, std::vector<bool>& value);
241 bool all(
const QString& section,
const QString& key, std::vector<int>& value);
247 bool all(
const QString& section,
const QString& key, std::vector<float>& value);
253 bool all(
const QString& section,
const QString& key, std::vector<double>& value);
259 bool all(
const QString& section,
const QString& key, std::vector<std::string>& value);
265 bool all(
const QString& section,
const QString& key, std::vector<QString>& value);
287 template <
typename T,
typename Container>
bool all(
const QString& section, std::map<QString, Container>& values);
294 bool all(
const QString& section, std::map<
QString, std::vector<bool> >& value);
300 bool all(
const QString& section, std::map<
QString, std::vector<int> >& value);
306 bool all(
const QString& section, std::map<
QString, std::vector<float> >& value);
312 bool all(
const QString& section, std::map<
QString, std::vector<double> >& value);
318 bool all(
const QString& section, std::map<
QString, std::vector<std::string> >& value);
324 bool all(
const QString& section, std::map<
QString, std::vector<QString> >& value);
330 bool all(
const QString& section, std::map<QString, QStringList>& value);
353 bool readValue(
const QString& value,
bool& variable);
361 bool readValue(
const QString& value, std::string& variable);
378 template <
typename T>
bool readValue(
const QString& value, std::vector<T>& variable);
387 template <
typename T>
bool readValue(
const QString& value, std::list<T>& variable);
396 template <
typename T>
bool readValue(
const QString& value, std::set<T>& variable);
405 template <
typename T>
bool readValue(
const QString& value, T& variable);
407 template <
typename T,
typename InsertIterator>
bool readContainer(
const QString& value, InsertIterator container);
425 std::map<QString, QStringList> Parameters;
449 template <
typename T,
typename InsertIterator>
bool Parms::readContainer(
const QString& value, InsertIterator it)
453 while(!iss.atEnd() and iss.status() == QTextStream::Ok) {
461 template <
typename T>
bool Parms::readValue(
const QString& value, std::vector<T>& variable)
463 return readContainer<T>(value, std::back_insert_iterator<std::vector<T> >(variable));
466 template <
typename T>
bool Parms::readValue(
const QString& value, std::list<T>& variable)
468 return readContainer<T>(value, std::back_insert_iterator<std::list<T> >(variable));
471 template <
typename T>
bool Parms::readValue(
const QString& value, std::set<T>& variable)
473 return readContainer<T>(value, std::insert_iterator<std::set<T> >(variable, variable.end()));
476 template <
typename T>
bool Parms::readValue(
const QString& value, T& variable)
481 return iss.status() == QTextStream::Ok;
487 if(!extractValues(section, key, values))
490 if((values.size() > 1) && (VerboseLevel > 1)) {
491 Information::err <<
"Parms::operator():Warning multiple value for key [" << section <<
"]" << key
492 <<
", last one used.\n" << flush;
495 if(!readValue(values.back(), value)) {
496 if(VerboseLevel > 0) {
497 Information::err <<
"Parms::operator():Error getting value for key [" << section <<
"]" << key <<
" value "
498 << values.back() <<
"\n" << flush;
509 if(!(*
this)(section, key, value)) {
511 if(VerboseLevel > 2) {
512 Information::err <<
"Parms::operator()::Info key [" << section <<
"]" << key
513 <<
" not found, using default value" << endl;
524 typedef typename Container::value_type T;
527 if(!extractValues(section, key, values))
530 std::insert_iterator<Container> it(value, value.end());
531 forall(
const QString& val, values) {
533 if(readValue(val, single_value)) {
534 *it++ = (
const T&)single_value;
536 if(VerboseLevel > 2) {
537 Information::err <<
"Parms::all:Error reading key [" << section <<
"]" << key <<
" with value " << val
547 template <
typename T,
typename Container>
bool Parms::all(
const QString& section, std::map<QString, Container>& result)
551 typedef std::map<QString, QStringList>::value_type value_type;
553 int pos = section.
size() + 1;
554 forall(
const value_type& pair, Parameters) {
555 QString sec(pair.first.mid(0, pos - 1));
558 QString key(pair.first.mid(pos));
559 Container& value = result[key];
561 forall(
const QString& val, pair.second) {
563 if(readValue(val, single_value)) {
564 value.push_back(single_value);
566 if(VerboseLevel > 2) {
567 Information::err <<
"Parms::all:Error reading key [" << section <<
"]" << key
568 <<
" 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:131
bool empty() const
Returns true if the parameter file was empty (e.g.
Definition: Parms.hpp:138
bool operator()(const QString §ion, const QString &key, T &value)
This operator retrieve a single parameter.
Definition: Parms.hpp:484
void verboseLevel(int vl)
Change the verbosity level.
Definition: Parms.hpp:124
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:105
bool all(const QString §ion, const QString &key, Container &value)
This operator retrieves all parameters with same [section]key.
Definition: Parms.hpp:521