diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-12 15:44:05 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-12 15:48:16 +0200 |
commit | f7ab2dc5a54c573cd7408a68cb1e93174827719e (patch) | |
tree | 683e3cda0a007f39ac97605850af94939d66bade /options/value-traits.hpp | |
parent | 4c4c783d023cf1bb6a8d7d883bf8d3384f7b7da1 (diff) |
options: split up value.hpp header
Also combine the traits classes and make them more useful.
Diffstat (limited to 'options/value-traits.hpp')
-rw-r--r-- | options/value-traits.hpp | 50 |
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 |