summaryrefslogtreecommitdiff
path: root/fusion_static_dispatch.hpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2014-05-03 16:14:48 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2014-05-03 22:38:33 +0200
commit13cfd05f9b2bb3c8d7d1bf47fcef037a745bacf8 (patch)
tree98a325d0e547d5da0b0fd4b0b9ce2054306e87d0 /fusion_static_dispatch.hpp
parent5bf919190e90b017ff00ab074bce68e90958fa3c (diff)
downloadgeneric-gui-13cfd05f9b2bb3c8d7d1bf47fcef037a745bacf8.tar.gz
generic-gui-13cfd05f9b2bb3c8d7d1bf47fcef037a745bacf8.tar.bz2
generic-gui-13cfd05f9b2bb3c8d7d1bf47fcef037a745bacf8.zip
Adds editing functionality to the models.
no longer able to store QStrings in the model though, But when creating generic guis you should not use any Gui related types anyway.
Diffstat (limited to 'fusion_static_dispatch.hpp')
-rw-r--r--fusion_static_dispatch.hpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/fusion_static_dispatch.hpp b/fusion_static_dispatch.hpp
index 8b68ba0..b0037a6 100644
--- a/fusion_static_dispatch.hpp
+++ b/fusion_static_dispatch.hpp
@@ -7,14 +7,6 @@
#include <functional>
-template <typename T, int index>
-struct TypeAt {
- typedef friendly_fusion::result_of::begin<T> begin;
- typedef friendly_fusion::result_of::advance_c<typename begin::type, index> adv_it;
- typedef friendly_fusion::result_of::deref<typename adv_it::type> deref;
- typedef typename std::decay<typename deref::type>::type value_type;
-};
-
#if defined( __GNUC__ ) && !defined( __clang__ )
template<int index, typename T>
std::function<boost::any(T)> make_at_c_lambda(T seq)
@@ -62,6 +54,45 @@ boost::any get_nth(T x, int index)
return get_nth_functor<T>()(x, index);
}
+template <typename T, int... Indices>
+void set_nth_impl(T& seq, int index, boost::any const& value, indices<Indices...>)
+{
+ typedef std::function<void(T&, boost::any const&)> element_type;
+ static element_type table[] =
+ {
+ [](T& seq, boost::any const& value)
+ {
+ typedef friendly_fusion::result_of::begin<T> begin;
+ typedef friendly_fusion::result_of::advance_c<typename begin::type, Indices> adv_it;
+ typedef friendly_fusion::result_of::deref<typename adv_it::type> deref;
+ typedef typename std::decay<typename deref::type>::type value_type;
+
+ friendly_fusion::deref(friendly_fusion::advance_c<Indices>(friendly_fusion::begin(seq))) = boost::any_cast<value_type>(value);
+ }
+ ...
+ };
+
+ table[index](seq, value);
+}
+
+template<typename T>
+struct set_nth_functor
+{
+ void operator()(T& seq, int index, boost::any const& value)
+ {
+ typedef typename friendly_fusion::result_of::size<T>::type seq_size;
+ typedef typename build_indices<seq_size::value>::type indices_type;
+
+ set_nth_impl(seq, index, value, indices_type{});
+ }
+};
+
+template <typename T>
+void set_nth(T& x, int index, boost::any const& value)
+{
+ set_nth_functor<T>()(x, index, value);
+}
+
#if defined( __GNUC__ ) && !defined( __clang__ )
template<int index, typename T>
std::function<std::string()> make_struct_member_name_lambda()