units
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#ifndef YAMLPARSER_H
|
||||
#define YAMLPARSER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
|
||||
class YamlNode {
|
||||
public:
|
||||
QString value;
|
||||
QStringList listValues;
|
||||
QMap<QString, YamlNode> children;
|
||||
|
||||
bool hasChild(const QString &key) const { return children.contains(key); }
|
||||
YamlNode operator[](const QString &key) const { return children.value(key); }
|
||||
YamlNode& operator[](const QString &key) { return children[key]; }
|
||||
|
||||
QString asString(const QString &def = "") const { return value.isEmpty() ? def : value; }
|
||||
int asInt(int def = 0) const { bool ok; int v = value.toInt(&ok); return ok ? v : def; }
|
||||
float asFloat(float def = 0.0f) const { bool ok; float v = value.toFloat(&ok); return ok ? v : def; }
|
||||
bool asBool(bool def = false) const {
|
||||
QString s = value.trimmed().toLower();
|
||||
if (s == "true" || s == "yes" || s == "1") return true;
|
||||
if (s == "false" || s == "no" || s == "0") return false;
|
||||
return def;
|
||||
}
|
||||
};
|
||||
|
||||
class YamlParser {
|
||||
public:
|
||||
static YamlNode parseFile(const QString &filePath);
|
||||
static YamlNode parseString(const QString &content);
|
||||
};
|
||||
|
||||
#endif // YAMLPARSER_H
|
||||
Reference in New Issue
Block a user