diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2014-05-25 11:16:36 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2014-05-25 11:16:36 +0200 |
| commit | 84c15aecc7d296d25b7fd5ead6730f8d132d350f (patch) | |
| tree | e5e435007c97105ad819f0df84da3027d2e82d9d /boost_any_qvariant_convert.hpp | |
| parent | d4ea872acfee5d4bf563334181400a9fef7d5add (diff) | |
| download | generic-gui-84c15aecc7d296d25b7fd5ead6730f8d132d350f.tar.gz generic-gui-84c15aecc7d296d25b7fd5ead6730f8d132d350f.tar.bz2 generic-gui-84c15aecc7d296d25b7fd5ead6730f8d132d350f.zip | |
Adds a initial implementation of a Form, as a proof-of-concept.
Diffstat (limited to 'boost_any_qvariant_convert.hpp')
| -rw-r--r-- | boost_any_qvariant_convert.hpp | 120 |
1 files changed, 25 insertions, 95 deletions
diff --git a/boost_any_qvariant_convert.hpp b/boost_any_qvariant_convert.hpp index 1f6e2be..8770919 100644 --- a/boost_any_qvariant_convert.hpp +++ b/boost_any_qvariant_convert.hpp @@ -9,113 +9,43 @@ #include <string> -template<typename value_type> -QVariant to_qvariant(boost::any const& x) -{ - return QVariant::fromValue<value_type>(boost::any_cast<value_type>(x)); -} - -template <typename T, int n> -QVariant to_qvariant(boost::any const& x) -{ - typedef friendly_fusion::result_of::begin<T> begin; - typedef friendly_fusion::result_of::advance_c<typename begin::type, n> adv_it; - typedef friendly_fusion::result_of::deref<typename adv_it::type> deref; - typedef typename std::decay<typename deref::type>::type value_type; - return to_qvariant<value_type>(x); -} - -#if defined( __GNUC__ ) && !defined( __clang__ ) -template <typename T, int index> -std::function<QVariant(boost::any const&)> to_qvariant_lambda() -{ - return [](boost::any const& any) - { - return to_qvariant<T, index>(any); - }; -} - -#endif //defined( __GNUC__ ) && !defined( __clang__ ) - -template<typename T, int... Indices> -QVariant to_qvariant(boost::any const& any, int index, indices<Indices...>) -{ - typedef std::function<QVariant(boost::any const&)> element_type; - static element_type table[] = +template <typename T> +struct ToQvariantFunctor { + + typedef QVariant return_type; + + template <int I> + static return_type call(boost::any const& any) { -#if defined( __GNUC__ ) && !defined( __clang__ ) - //Workaround for gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226 - to_qvariant_lambda<T, Indices>() - ... -#else - [](boost::any const& any){return to_qvariant<T, Indices>(any);} - ... -#endif //defined( __GNUC__ ) && !defined( __clang__ ) - }; + typedef typename friendly_fusion::utils::DecayedTypeOfAtIndex<T, I>::type value_type; + + return QVariant::fromValue<value_type>(boost::any_cast<value_type>(any)); + } - return table[index](any); -} +}; template <typename T> QVariant to_qvariant(boost::any const& x, int index) { - typedef typename friendly_fusion::result_of::size<T>::type seq_size; - typedef typename build_indices<seq_size::value>::type indices_type; - - return to_qvariant<T>(x, index, indices_type{}); + return apply_functor_to_member<T, ToQvariantFunctor>(index, x); } -template<typename value_type> -boost::any to_boost_any(QVariant const& x) -{ - return boost::any(x.value<value_type>()); -} - -template <typename T, int n> -boost::any to_boost_any(QVariant const& x) -{ - typedef friendly_fusion::result_of::begin<T> begin; - typedef friendly_fusion::result_of::advance_c<typename begin::type, n> adv_it; - typedef friendly_fusion::result_of::deref<typename adv_it::type> deref; - typedef typename std::decay<typename deref::type>::type value_type; - return to_boost_any<value_type>(x); -} - -#if defined( __GNUC__ ) && !defined( __clang__ ) -template <typename T, int index> -std::function<boost::any(QVariant const&)> to_boost_any_lambda() -{ - return [](QVariant const& value) - { - return to_boost_any<T, index>(value); - }; -} -#endif //defined( __GNUC__ ) && !defined( __clang__ ) - -template<typename T, int... Indices> -boost::any to_boost_any(QVariant const& value, int index, indices<Indices...>) +template <typename T> +struct ToBoostAnyFunctor { - typedef std::function<boost::any(QVariant const&)> element_type; - static element_type table[] = + typedef boost::any return_type; + + template <int I> + static return_type call(QVariant const& variant) { -#if defined( __GNUC__ ) && !defined( __clang__ ) - //Workaround for gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226 - to_boost_any_lambda<T, Indices>() - ... -#else - [](QVariant const& value){return to_boost_any<T, Indices>(value);} - ... -#endif //defined( __GNUC__ ) && !defined( __clang__ ) - }; - - return table[index](value); -} + typedef typename friendly_fusion::utils::DecayedTypeOfAtIndex<T, I>::type value_type; + + return boost::any(variant.value<value_type>()); + } +}; template <typename T> boost::any to_boost_any(QVariant const& x, int index) { - typedef typename friendly_fusion::result_of::size<T>::type seq_size; - typedef typename build_indices<seq_size::value>::type indices_type; - - return to_boost_any<T>(x, index, indices_type{}); + return apply_functor_to_member<T, ToBoostAnyFunctor>(index, x); }
\ No newline at end of file |
