summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/attribute_reorder.hpp
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-06 02:54:36 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-06 02:54:36 -0300
commit2a3d7860dbc11458425e162cd69ee399e9025251 (patch)
tree84c5b21b644c4cf8806a8eee07b4ed81922c92b4 /src/lib/eolian_cxx/grammar/attribute_reorder.hpp
parent4d1b3191d94fcc70472552b1bb554984a9cb0288 (diff)
eolian-cxx: Rewrite to accomodate new features of the C++ binding
Diffstat (limited to 'src/lib/eolian_cxx/grammar/attribute_reorder.hpp')
-rw-r--r--src/lib/eolian_cxx/grammar/attribute_reorder.hpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/lib/eolian_cxx/grammar/attribute_reorder.hpp b/src/lib/eolian_cxx/grammar/attribute_reorder.hpp
new file mode 100644
index 0000000000..b3f8b3196b
--- /dev/null
+++ b/src/lib/eolian_cxx/grammar/attribute_reorder.hpp
@@ -0,0 +1,87 @@
1#ifndef EOLIAN_CXX_ATTRIBUTE_REORDER_HH
2#define EOLIAN_CXX_ATTRIBUTE_REORDER_HH
3
4#include "grammar/generator.hpp"
5#include "grammar/attributes.hpp"
6
7namespace efl { namespace eolian { namespace grammar {
8
9template <typename Tuple, int...S>
10struct reorder_tuple
11{
12 Tuple* tuple;
13};
14
15namespace impl {
16
17template <int N, typename T>
18struct index_calc;
19
20template <int N, typename Tuple, int...S>
21struct index_calc<0, reorder_tuple<Tuple, N, S...>> : std::integral_constant<int, N> {};
22
23template <int I, int N, typename Tuple, int...S>
24struct index_calc<I, reorder_tuple<Tuple, N, S...>> : index_calc<I-1, reorder_tuple<Tuple, S...>> {};
25
26}
27namespace attributes {
28template <int N, typename Tuple, int...S>
29struct tuple_element<N, reorder_tuple<Tuple, S...>>
30{
31 template <typename T>
32 struct identity { typedef T type; };
33 typedef impl::index_calc<N, reorder_tuple<Tuple, S...>> index;
34 typedef typename std::conditional
35 <index::value == -1
36 , identity<Tuple>
37 , tuple_element<index::value, typename std::remove_const<Tuple>::type>>::type::type type;
38 static type const& get_impl(reorder_tuple<Tuple, S...> const& t
39 , std::integral_constant<int, -1>)
40 { return *t.tuple; }
41 template <int I>
42 static type const& get_impl(reorder_tuple<Tuple, S...> const& t
43 , std::integral_constant<int, I>)
44 { using std::get; return get<index::value>(*t.tuple); }
45 static type const& get(reorder_tuple<Tuple, S...> const& t)
46 { return get_impl(t, index{}); }
47};
48}
49template <int N, typename Tuple, int...S>
50typename attributes::tuple_element<N, reorder_tuple<Tuple, S...>>::type const& get(reorder_tuple<Tuple, S...>const& t)
51{
52 return attributes::tuple_element<N, reorder_tuple<Tuple, S...>>::get(t);
53}
54
55template <typename G, int...S>
56struct attribute_reorder_generator
57{
58 template <typename OutputIterator, typename Attribute, typename Context>
59 bool generate(OutputIterator sink, Attribute const& attribute, Context const& ctx) const
60 {
61 return attributes::generate(as_generator(g), sink, reorder_tuple<Attribute const, S...>{&attribute}, ctx);
62 }
63
64 G g;
65};
66
67template <typename G, int...S>
68struct is_eager_generator<attribute_reorder_generator<G, S...>> : std::true_type {};
69
70template <int...S, typename G>
71attribute_reorder_generator<G, S...> attribute_reorder(G g)
72{
73 return {g};
74}
75
76namespace type_traits {
77template <typename G, int...S>
78struct attributes_needed<attribute_reorder_generator<G, S...>> : attributes_needed<G> {};
79template <int...S, typename Tuple>
80struct is_explicit_tuple<reorder_tuple<Tuple, S...>> : std::true_type {};
81template <int...S, typename Tuple>
82struct is_tuple<reorder_tuple<Tuple, S...>> : std::true_type {};
83}
84
85} } }
86
87#endif