summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CRSMConfig.hpp43
1 files changed, 28 insertions, 15 deletions
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<typename Type>
+ static Type getValue(const QString& value);
+
+ template<typename Type>
+ static QString getStringValue(Type val);
};
template<typename Type>
@@ -125,9 +133,7 @@ public:
virtual void append(const QString &entry)
{
- Type val;
- CRSMConfigValue<Type> configValue(val);
- configValue.setValue(entry);
+ Type val = CRSMConfigValueBase::getValue<Type>(entry);
if(!config.contains(val))
{
config.append(val);
@@ -140,8 +146,7 @@ public:
foreach(Type val, config)
{
- CRSMConfigValue<Type> 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<KeyType> keyConfigValue(keyVal);
- keyConfigValue.setValue(key);
- ValueType valueVal;
- CRSMConfigValue<ValueType> valueConfigValue(valueVal);
- valueConfigValue.setValue(value);
- config[keyVal] = valueVal;
+ config[CRSMConfigValueBase::getValue<KeyType>(key)] = CRSMConfigValueBase::getValue<ValueType>(value);
}
virtual QMap<QString, QString> getValues()
@@ -177,9 +176,7 @@ public:
foreach(KeyType key, config.keys())
{
- CRSMConfigValue<KeyType> keyValue(key);
- CRSMConfigValue<ValueType> valValue(config[key]);
- ret[keyValue.value()] = valValue.value();
+ ret[CRSMConfigValueBase::getStringValue(key)] = CRSMConfigValueBase::getStringValue(config[key]);
}
return ret;
@@ -192,6 +189,22 @@ CRSMConfigValue<Type>* mkConfigValue(Type& Value)
return new CRSMConfigValue<Type>(Value);
}
+template<typename Type>
+Type CRSMConfigValueBase::getValue(const QString& value)
+{
+ Type ret;
+ CRSMConfigValue<Type> val(ret);
+ val.setValue(value);
+ return ret;
+}
+
+template<typename Type>
+QString CRSMConfigValueBase::getStringValue(Type value)
+{
+ CRSMConfigValue<Type> val(value);
+ return val.value();
+}
+
class CRSMConfig
{
public: