diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2015-10-10 20:22:06 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2015-10-10 20:22:06 +0200 |
| commit | d62e19be818c7fab952bad861d7e8a98ce346d2f (patch) | |
| tree | 848c64c90b3d7219ac74c963db28cde149c5db48 /src/ConfigBase.hpp | |
| parent | b5e22002ef491cdbae8ab04e96200f101ca6312b (diff) | |
| download | manager-d62e19be818c7fab952bad861d7e8a98ce346d2f.tar.gz manager-d62e19be818c7fab952bad861d7e8a98ce346d2f.zip | |
Remove CRSM-prefix from Config(Base)-Classes
Diffstat (limited to 'src/ConfigBase.hpp')
| -rw-r--r-- | src/ConfigBase.hpp | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/src/ConfigBase.hpp b/src/ConfigBase.hpp index 5e2a50f..d25861c 100644 --- a/src/ConfigBase.hpp +++ b/src/ConfigBase.hpp @@ -10,9 +10,9 @@ #include <type_traits> #include <limits> -using CRSMConfigException = std::logic_error; +using ConfigException = std::logic_error; -namespace CRSMConfigValueType { +namespace ConfigValueType { enum Type { None, String, @@ -23,12 +23,12 @@ enum Type { }; } -class CRSMConfigValueBase { +class ConfigValueBase { public: virtual void setValue(const QString&) { } virtual QString value() { return ""; } - virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::None; } + virtual ConfigValueType::Type type() { return ConfigValueType::Type::None; } @@ -40,12 +40,12 @@ public: }; template<typename Type, typename = void> -class CRSMConfigValue : public CRSMConfigValueBase { +class ConfigValue : public ConfigValueBase { public: // CRSMConfigValue(Type&) { } - virtual void setValue(const QString&) { throw CRSMConfigException("Cannot assign"); } - virtual QString value() { throw CRSMConfigException("Cannot get the value"); } + virtual void setValue(const QString&) { throw ConfigException("Cannot assign"); } + virtual QString value() { throw ConfigException("Cannot get the value"); } }; using String = QString; @@ -56,16 +56,16 @@ using Boolean = bool; #define Map(KeyType, ValueType) QMap<KeyType, ValueType> -#define ConfigValue(Value) {#Value, mkConfigValue(Value)} -#define ConfigValueEx(Value, ...) {#Value, mkConfigValue(Value, __VA_ARGS__)} +#define ConfigVal(Value) {#Value, mkConfigValue(Value)} +#define ConfigValEx(Value, ...) {#Value, mkConfigValue(Value, __VA_ARGS__)} template<> -class CRSMConfigValue<String> : public CRSMConfigValueBase { +class ConfigValue<String> : public ConfigValueBase { String& config; bool trimmedQuotes = false; public: - CRSMConfigValue(String& config) : config(config) { } + ConfigValue(String& config) : config(config) { } virtual void setValue(const QString& value) { config = trimQuotes(QString(value), trimmedQuotes); } virtual QString value() @@ -79,7 +79,7 @@ public: return config; } } - virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::String; } + virtual ConfigValueType::Type type() { return ConfigValueType::Type::String; } private: QString& trimQuotes(QString&& string, bool& trimmed) @@ -97,30 +97,30 @@ private: }; template<typename Type> -class CRSMConfigValue<Type, typename std::enable_if<std::is_integral<Type>::value>::type> : public CRSMConfigValueBase { +class ConfigValue<Type, typename std::enable_if<std::is_integral<Type>::value>::type> : public ConfigValueBase { Type& config; public: - CRSMConfigValue(Type& config) : config(config) { } + ConfigValue(Type& config) : config(config) { } virtual void setValue(const QString& value) { bool ok = true; long long longLongVal = value.toLongLong(&ok, 0); - if(!ok) throw CRSMConfigException("\"" + value.toStdString() + "\" could not be parsed as an Integer"); - if(longLongVal < std::numeric_limits<Type>::min() || longLongVal > std::numeric_limits<Type>::max()) throw CRSMConfigException((QString::number(longLongVal) + " is out of range (" + QString::number(std::numeric_limits<Type>::min()) + " - " + QString::number(std::numeric_limits<Type>::max()) + ")").toStdString()); + if(!ok) throw ConfigException("\"" + value.toStdString() + "\" could not be parsed as an Integer"); + if(longLongVal < std::numeric_limits<Type>::min() || longLongVal > std::numeric_limits<Type>::max()) throw ConfigException((QString::number(longLongVal) + " is out of range (" + QString::number(std::numeric_limits<Type>::min()) + " - " + QString::number(std::numeric_limits<Type>::max()) + ")").toStdString()); config = static_cast<Type>(longLongVal); } virtual QString value() { return QString::number(config); } - virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::Integer; } + virtual ConfigValueType::Type type() { return ConfigValueType::Type::Integer; } }; template<> -class CRSMConfigValue<Boolean> : public CRSMConfigValueBase { +class ConfigValue<Boolean> : public ConfigValueBase { Boolean& config; public: - CRSMConfigValue(Boolean& config) : config(config) { } + ConfigValue(Boolean& config) : config(config) { } virtual void setValue(const QString& value) { @@ -134,21 +134,21 @@ public: } else { - throw CRSMConfigException("\"" + value.toStdString() + "\" could not be parsed as a Boolean"); + throw ConfigException("\"" + value.toStdString() + "\" could not be parsed as a Boolean"); } } virtual QString value() { return config ? "true" : "false"; } - virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::Boolean; } + virtual ConfigValueType::Type type() { return ConfigValueType::Type::Boolean; } }; -class CRSMConfigValueList : public CRSMConfigValueBase { +class ConfigValueList : public ConfigValueBase { public: virtual void append(const QString& entry) = 0; virtual void remove(const QString& entry) = 0; virtual QStringList getValues() = 0; }; -class CRSMConfigValueMap : public CRSMConfigValueBase { +class ConfigValueMap : public ConfigValueBase { public: virtual void setKeyValue(const QString& key, const QString& value) = 0; virtual void remove(const QString& key) = 0; @@ -156,28 +156,28 @@ public: }; template<typename Type> -class CRSMConfigValue<QList<Type>> : public CRSMConfigValueList { +class ConfigValue<QList<Type>> : public ConfigValueList { using ListType = QList<Type>; ListType& config; const bool deduplicate; public: - CRSMConfigValue(ListType& config, bool deduplicate = true) : config(config), deduplicate(deduplicate) {} + ConfigValue(ListType& config, bool deduplicate = true) : config(config), deduplicate(deduplicate) {} virtual ListType& list() { return config; } - virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::List; } + virtual ConfigValueType::Type type() { return ConfigValueType::Type::List; } virtual void append(const QString &entry) { - Type val = CRSMConfigValueBase::getValue<Type>(entry); + Type val = ConfigValueBase::getValue<Type>(entry); if(!deduplicate || !config.contains(val)) { config.append(val); } } - virtual void remove(const QString &entry) { config.removeAll(CRSMConfigValueBase::getValue<Type>(entry)); } + virtual void remove(const QString &entry) { config.removeAll(ConfigValueBase::getValue<Type>(entry)); } virtual QStringList getValues() { @@ -185,7 +185,7 @@ public: foreach(Type val, config) { - ret.append(CRSMConfigValueBase::getStringValue(val)); + ret.append(ConfigValueBase::getStringValue(val)); } return ret; @@ -193,20 +193,20 @@ public: }; template<typename KeyType, typename ValueType> -class CRSMConfigValue<QMap<KeyType, ValueType>> : public CRSMConfigValueMap { +class ConfigValue<QMap<KeyType, ValueType>> : public ConfigValueMap { using MapType = QMap<KeyType, ValueType>; MapType& config; public: - CRSMConfigValue(MapType& config) : config(config) {} + ConfigValue(MapType& config) : config(config) {} virtual MapType& map() { return config; } - virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::Map; } + virtual ConfigValueType::Type type() { return ConfigValueType::Type::Map; } virtual void setKeyValue(const QString& key, const QString& value) { - config[CRSMConfigValueBase::getValue<KeyType>(key)] = CRSMConfigValueBase::getValue<ValueType>(value); + config[ConfigValueBase::getValue<KeyType>(key)] = ConfigValueBase::getValue<ValueType>(value); } virtual QMap<QString, QString> getValues() @@ -215,7 +215,7 @@ public: foreach(KeyType key, config.keys()) { - ret[CRSMConfigValueBase::getStringValue(key)] = CRSMConfigValueBase::getStringValue(config[key]); + ret[ConfigValueBase::getStringValue(key)] = ConfigValueBase::getStringValue(config[key]); } return ret; @@ -223,43 +223,43 @@ public: virtual void remove(const QString &key) { - config.remove(CRSMConfigValueBase::getValue<KeyType>(key)); + config.remove(ConfigValueBase::getValue<KeyType>(key)); } }; template<typename Type> -class CRSMConfigValue<Type, typename std::enable_if<std::is_enum<Type>::value>::type> : public CRSMConfigValue<typename std::underlying_type<Type>::type> { +class ConfigValue<Type, typename std::enable_if<std::is_enum<Type>::value>::type> : public ConfigValue<typename std::underlying_type<Type>::type> { using UndType = typename std::underlying_type<Type>::type; public: - CRSMConfigValue(Type& config) : CRSMConfigValue<UndType>::CRSMConfigValue((UndType&)config) {} + ConfigValue(Type& config) : ConfigValue<UndType>::ConfigValue((UndType&)config) {} }; template<typename Type, typename... Types> -CRSMConfigValue<Type>* mkConfigValue(Type& Value, Types... values) +ConfigValue<Type>* mkConfigValue(Type& Value, Types... values) { - return new CRSMConfigValue<Type>(Value, values...); + return new ConfigValue<Type>(Value, values...); } template<typename Type> -Type CRSMConfigValueBase::getValue(const QString& value) +Type ConfigValueBase::getValue(const QString& value) { Type ret; - CRSMConfigValue<Type> val(ret); + ConfigValue<Type> val(ret); val.setValue(value); return ret; } template<typename Type> -QString CRSMConfigValueBase::getStringValue(Type value) +QString ConfigValueBase::getStringValue(Type value) { - CRSMConfigValue<Type> val(value); + ConfigValue<Type> val(value); return val.value(); } -class CRSMConfigBase +class ConfigBase { public: - explicit CRSMConfigBase(QMap<QString, CRSMConfigValueBase*> configValues) : configValues(configValues) {} + explicit ConfigBase(QMap<QString, ConfigValueBase*> configValues) : configValues(configValues) {} void setConfigValue(const QString& name, const QString& value); QString getConfigValueLine(const QString& name); @@ -273,10 +273,10 @@ public: void setConfigLine(const QString& line); protected: - void addConfigValue(QString name, CRSMConfigValueBase *value); - CRSMConfigValueBase& getConfigValue(const QString &name); + void addConfigValue(QString name, ConfigValueBase *value); + ConfigValueBase& getConfigValue(const QString &name); - QMap<QString, CRSMConfigValueBase*> configValues; + QMap<QString, ConfigValueBase*> configValues; }; #endif // CONFIGBASE |
