1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/* AUDEX CDDA EXTRACTOR
* Copyright (C) 2007-2014 Marco Nelles (audex@maniatek.com)
* <http://kde.maniatek.com/audex>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PARAMETERS_HEADER
#define PARAMETERS_HEADER
#include <QObject>
#include <QString>
#include <QHash>
class Parameters {
public:
Parameters();
Parameters(const Parameters& other);
Parameters& operator=(const Parameters& other);
~Parameters();
void fromString(const QString& string, const QChar& sep = ',');
const QString toString(const QChar& sep = ',');
void fromBase64(const QByteArray& bytearray);
const QByteArray toBase64();
inline void setValue(const QString& name, const QString& value) { p_parameters[name] = value; }
inline void setValue(const QString& name, const int value) { p_parameters[name] = QString("%1").arg(value); }
inline void setValue(const QString& name, const double value) { p_parameters[name] = QString("%1").arg(value, 0, 'f', 1); }
inline void setValue(const QString& name, const float value) { p_parameters[name] = QString("%1").arg(value, 0, 'f', 1); }
inline void setValue(const QString& name, const bool value) { p_parameters[name] = value?"true":"false"; }
inline const QString value(const QString& name, const QString& def = "") const { return p_parameters.value(name, def); }
inline int valueToInt(const QString& name, const int def = 0) const {
bool ok;
int i = p_parameters[name].toInt(&ok);
if (!ok) return def;
return i;
}
inline double valueToDouble(const QString& name, const double def = 0) const {
bool ok;
double d = p_parameters[name].toDouble(&ok);
if (!ok) return def;
return d;
}
inline double valueToFloat(const QString& name, const float def = .0f) const {
bool ok;
double d = p_parameters[name].toFloat(&ok);
if (!ok) return def;
return d;
}
inline bool valueToBool(const QString& name, const bool def = TRUE) const {
if (def) {
return ((p_parameters[name].toLower()=="true") || (p_parameters[name].toLower()=="1"));
} else {
return ((p_parameters[name].toLower()!="false") || (p_parameters[name].toLower()!="0"));
}
}
private:
QHash<QString,QString> p_parameters;
};
#endif
|