Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
type_list/type_at.h
1 /// @file meta/type_list/type_at.h
2 ///
3 /// Provides utility functions for use with type_containers.
4 ///
5 /// This file provides these utility access functions for use with the
6 /// - **TypeList**
7 /// This provides a form of reflection upon the data type. Reflection is not
8 /// a feature provided by C++. **TypeAt** works upon a **TypeList**
9 /// definition to query the type of parameter at the specified index.
10 ///
11 /// - **front**
12 /// Returns the type for the element at the beginning of the **TypeList**.
13 ///
14 /// - **pop_front**
15 /// Removes the type for the element at the beginning of the
16 /// **TypeList**. The TypeList defined in the resulting
17 /// meta-structure is the original TypeList with the first element removed.
18 ///
19 /// - **push_front**
20 /// Pushes a new type at the beginning of the **TypeList**.
21 /// The TypeList defined in the resulting meta-structure is the original
22 /// TypeList with the new element added to the front of the list.
23 ///
24 /// - **back**
25 /// Returns the type for the element at the end of the **TypeList**.
26 ///
27 /// The MIT License(MIT)
28 /// @copyright 2014 Paul M Watt
29 // ****************************************************************************
30 #ifndef TYPE_LIST_TYPE_AT_H_INCLUDED
31 #define TYPE_LIST_TYPE_AT_H_INCLUDED
32 // Includes ******************************************************************
33 #include <Pb/type_list.h>
34 
35 namespace Hg
36 {
37 // ****************************************************************************
38 /// Defines each type index lookup.
39 ///
40 /// This macro will generate a set of code for type definitions that looks like
41 /// this, where 3 has been used for the input I.
42 ///
43 /// Generated Output:
44 /// ~~~{.cpp}
45 /// tmp_ALCHEMY_TYPELIST_AT(3);
46 ///
47 /// template <typename
48 /// TypeList < typename T0, typename T1, typename T2, typename T3,
49 /// typename T4, typename T5, typename T6, typename T7,
50 /// typename T8, typename T9, typename T10, typename T11,
51 /// typename T12, typename T13, typename T14, typename T15,
52 /// typename T16, typename T17, typename T18, typename T19,
53 /// typename T20, typename T21, typename T22, typename T23,
54 /// typename T24, typename T25, typename T26, typename T27,
55 /// typename T28, typename T29, typename T30, typename T31>,
56 /// typename ErrorT = error::Undefined_Type>
57 /// struct TypeAt<(3), TypeList < T0, T1, T2, T3, T4, T5, T6, T7,
58 /// T8, T9, T10, T11, T12, T13, T14, T15,
59 /// T16, T17, T18, T19, T20, T21, T22, T23,
60 /// T24, T25, T26, T27, T28, T29, T30, T31>
61 /// >
62 /// {
63 /// typedef T3 type;
64 /// };
65 /// ~~~
66 ///
67 /// @note
68 /// This is a locally defined MACRO. After the list of entries have been defined
69 /// to generate the required function calls, the MACRO will be undefined.
70 ///
71 #define tmp_ALCHEMY_TYPELIST_AT(I) \
72 template <TMP_ARRAY_32(typename T), \
73  typename ErrorT> \
74 struct TypeAt<(I), \
75  TypeList<TMP_ARRAY_32(T)>, \
76  ErrorT \
77  > \
78 { \
79  typedef TypeList <TMP_ARRAY_32(T)> container; \
80  typedef T##I type; \
81 }
82 
83 // ****************************************************************************
84 // MACRO Declarations for each ENTRY that is supported for the TypeList size
85 tmp_ALCHEMY_TYPELIST_AT(0);
86 tmp_ALCHEMY_TYPELIST_AT(1);
87 tmp_ALCHEMY_TYPELIST_AT(2);
88 tmp_ALCHEMY_TYPELIST_AT(3);
89 tmp_ALCHEMY_TYPELIST_AT(4);
90 tmp_ALCHEMY_TYPELIST_AT(5);
91 tmp_ALCHEMY_TYPELIST_AT(6);
92 tmp_ALCHEMY_TYPELIST_AT(7);
93 tmp_ALCHEMY_TYPELIST_AT(8);
94 tmp_ALCHEMY_TYPELIST_AT(9);
95 tmp_ALCHEMY_TYPELIST_AT(10);
96 tmp_ALCHEMY_TYPELIST_AT(11);
97 tmp_ALCHEMY_TYPELIST_AT(12);
98 tmp_ALCHEMY_TYPELIST_AT(13);
99 tmp_ALCHEMY_TYPELIST_AT(14);
100 tmp_ALCHEMY_TYPELIST_AT(15);
101 tmp_ALCHEMY_TYPELIST_AT(16);
102 tmp_ALCHEMY_TYPELIST_AT(17);
103 tmp_ALCHEMY_TYPELIST_AT(18);
104 tmp_ALCHEMY_TYPELIST_AT(19);
105 tmp_ALCHEMY_TYPELIST_AT(20);
106 tmp_ALCHEMY_TYPELIST_AT(21);
107 tmp_ALCHEMY_TYPELIST_AT(22);
108 tmp_ALCHEMY_TYPELIST_AT(23);
109 tmp_ALCHEMY_TYPELIST_AT(24);
110 tmp_ALCHEMY_TYPELIST_AT(25);
111 tmp_ALCHEMY_TYPELIST_AT(26);
112 tmp_ALCHEMY_TYPELIST_AT(27);
113 tmp_ALCHEMY_TYPELIST_AT(28);
114 tmp_ALCHEMY_TYPELIST_AT(29);
115 tmp_ALCHEMY_TYPELIST_AT(30);
116 tmp_ALCHEMY_TYPELIST_AT(31);
117 
118 // Undefining the declaration MACRO to prevent its further use. ***************
119 #undef tmp_ALCHEMY_TYPELIST_AT
120 
121 // ****************************************************************************
122 /// This allows the first type of the list to be returned.
123 ///
124 template<TMP_ARRAY_32(typename T)>
125 struct front<TypeList<TMP_ARRAY_32(T)> >
126 {
127  typedef T0 type; ///< Type of the first element in the list
128 };
129 
130 
131 // ****************************************************************************
132 /// This allows the first type of the list to be removed, and
133 /// the remainder of the list will become the type typedef.
134 ///
135 template<typename TPop, TMP_ARRAY_31(typename T)>
136 struct pop_front<TypeList<TPop, TMP_ARRAY_31(T)> >
137 {
138  typedef TypeList<TMP_ARRAY_31(T)> type;
139 };
140 
141 template<TMP_ARRAY_31(typename T)>
142 struct pop_front<TypeList<MT, TMP_ARRAY_31(T)> >
143 {
144  typedef MT type;
145 };
146 
147 // ****************************************************************************
148 /// This allows the a new type to be pushed at the front of the list.
149 /// The new list will become the typedef of the pushed type and
150 /// the existing type list.
151 ///
152 template<TMP_ARRAY_32(typename T), typename T>
153 struct push_front<TypeList<TMP_ARRAY_32(T)>, T>
154 {
156 };
157 
158 // ****************************************************************************
159 /// This allows the a new type to be pushed at the back of the list.
160 /// The new list will become the typedef of the pushed type and
161 /// the existing type list.
162 ///
163 template<TMP_ARRAY_32(typename T), typename T>
164 struct push_back<TypeList<TMP_ARRAY_32(T)>, T>
165 {
167 };
168 
169 // ****************************************************************************
170 /// This allows the last type of the list to be returned.
171 ///
172 template<TMP_ARRAY_32(typename T)>
173 struct back<TypeList<TMP_ARRAY_32(T)> >
174 {
177 };
178 
179 
180 
181 } // namespace Hg
182 
183 #endif