From c033dd56d7765cd72c7287dc719941a864cb2c69 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Thu, 24 Sep 2015 18:52:22 +0200 Subject: Add CRSMConfigValueBase::getValue and CRSMConfigValueBase::getStringValue and use them where appropriate --- src/CRSMConfig.hpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp index c6c072d..e38199b 100644 --- a/src/CRSMConfig.hpp +++ b/src/CRSMConfig.hpp @@ -26,6 +26,14 @@ public: virtual void setValue(const QString&) { } virtual QString value() { return ""; } virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::None; } + + + + template + static Type getValue(const QString& value); + + template + static QString getStringValue(Type val); }; template @@ -125,9 +133,7 @@ public: virtual void append(const QString &entry) { - Type val; - CRSMConfigValue configValue(val); - configValue.setValue(entry); + Type val = CRSMConfigValueBase::getValue(entry); if(!config.contains(val)) { config.append(val); @@ -140,8 +146,7 @@ public: foreach(Type val, config) { - CRSMConfigValue value(val); - ret.append(value.value()); + ret.append(CRSMConfigValueBase::getStringValue(val)); } return ret; @@ -162,13 +167,7 @@ public: virtual void setKeyValue(const QString& key, const QString& value) { - KeyType keyVal; - CRSMConfigValue keyConfigValue(keyVal); - keyConfigValue.setValue(key); - ValueType valueVal; - CRSMConfigValue valueConfigValue(valueVal); - valueConfigValue.setValue(value); - config[keyVal] = valueVal; + config[CRSMConfigValueBase::getValue(key)] = CRSMConfigValueBase::getValue(value); } virtual QMap getValues() @@ -177,9 +176,7 @@ public: foreach(KeyType key, config.keys()) { - CRSMConfigValue keyValue(key); - CRSMConfigValue valValue(config[key]); - ret[keyValue.value()] = valValue.value(); + ret[CRSMConfigValueBase::getStringValue(key)] = CRSMConfigValueBase::getStringValue(config[key]); } return ret; @@ -192,6 +189,22 @@ CRSMConfigValue* mkConfigValue(Type& Value) return new CRSMConfigValue(Value); } +template +Type CRSMConfigValueBase::getValue(const QString& value) +{ + Type ret; + CRSMConfigValue val(ret); + val.setValue(value); + return ret; +} + +template +QString CRSMConfigValueBase::getStringValue(Type value) +{ + CRSMConfigValue val(value); + return val.value(); +} + class CRSMConfig { public: -- cgit v1.2.3-54-g00ecf