summaryrefslogtreecommitdiffhomepage
path: root/options/value-traits.hpp
diff options
context:
space:
mode:
authorStanisław Halik <sthalik@misaki.pl>2017-05-14 16:22:09 +0200
committerGitHub <noreply@github.com>2017-05-14 16:22:09 +0200
commit5c23666b58bb1dd4aea15c0d62a2f716d5be7f52 (patch)
treee6497e9b55c073be209ec673ef05e62bf57a2c8f /options/value-traits.hpp
parent4701dd3b0c8323a11cf7d5ad09c579a9864a41bd (diff)
parentc392181211b245e74292424500265323c960c1aa (diff)
Merge branch 'unstable' into unstable
Diffstat (limited to 'options/value-traits.hpp')
-rw-r--r--options/value-traits.hpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/options/value-traits.hpp b/options/value-traits.hpp
new file mode 100644
index 00000000..cf12649c
--- /dev/null
+++ b/options/value-traits.hpp
@@ -0,0 +1,50 @@
+#include "export.hpp"
+
+#include "compat/functional.hpp"
+#include "slider.hpp"
+
+#include <QString>
+
+#include <type_traits>
+
+namespace options {
+namespace detail {
+
+template<typename t, typename u = t, typename Enable = void>
+struct default_value_traits
+{
+ using element_type = remove_qualifiers<t>;
+ using value_type = u;
+
+ static inline value_type from_value(const value_type& val, const value_type&) { return val; }
+ static inline value_type from_storage(const element_type& x) { return static_cast<value_type>(x); }
+ static inline element_type to_storage(const value_type& val) { return static_cast<element_type>(val); }
+};
+
+template<typename t, typename u = t, typename Enable = void>
+struct value_traits : default_value_traits<t, u, Enable>
+{
+};
+
+template<>
+struct value_traits<slider_value> : default_value_traits<slider_value>
+{
+ static inline slider_value from_value(const slider_value& val, const slider_value& def)
+ {
+ return slider_value(val.cur(), def.min(), def.max());
+ }
+};
+
+// Qt uses int a lot in slots so use it for all enums
+template<typename t>
+struct value_traits<t, t, std::enable_if_t<std::is_enum<t>::value>> : public default_value_traits<int, t>
+{
+};
+
+template<>
+struct value_traits<float> : public default_value_traits<float, double, void>
+{
+};
+
+} // ns detail
+} // ns options