summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CRSMConfig.hpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp
index b875d6f..b705c62 100644
--- a/src/CRSMConfig.hpp
+++ b/src/CRSMConfig.hpp
@@ -6,6 +6,8 @@
#include <QMap>
#include <exception>
+#include <type_traits>
+#include <limits>
using CRSMConfigException = std::logic_error;
@@ -36,7 +38,7 @@ public:
static QString getStringValue(Type val);
};
-template<typename Type>
+template<typename Type, typename = void>
class CRSMConfigValue : public CRSMConfigValueBase {
public:
// CRSMConfigValue(Type&) { }
@@ -66,19 +68,20 @@ public:
virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::String; }
};
-template<>
-class CRSMConfigValue<Integer> : public CRSMConfigValueBase {
- Integer& config;
+template<typename Type>
+class CRSMConfigValue<Type, typename std::enable_if<std::is_integral<Type>::value>::type> : public CRSMConfigValueBase {
+ Type& config;
public:
- CRSMConfigValue(Integer& config) : config(config) { }
+ CRSMConfigValue(Type& config) : config(config) { }
virtual void setValue(const QString& value)
{
bool ok = true;
- Integer val = value.toInt(&ok, 0);
+ long long longLongVal = value.toLongLong(&ok, 0);
if(!ok) throw CRSMConfigException("\"" + value.toStdString() + "\" could not be parsed as an Integer");
- config = val;
+ 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());
+ config = static_cast<Type>(longLongVal);
}
virtual QString value() { return QString::number(config); }
virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::Integer; }