Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JTypeList.hh
Go to the documentation of this file.
1#ifndef __JLANG__JTYPELIST__
2#define __JLANG__JTYPELIST__
3
4#include "JLang/JNullType.hh"
5#include "JLang/JType.hh"
6
7
8/**
9 * \author mdejong
10 */
11
12namespace JLANG {}
13namespace JPP { using namespace JLANG; }
14
15namespace JLANG {
16
17
18 /**
19 * Type list.
20 */
21 template<class JHead_t = JNullType, class JTail_t = JNullType>
22 struct JTypeList
23 {
24 typedef JHead_t head_type;
25 typedef JTail_t tail_type;
26 };
27
28
29 /**
30 * List of identical types.
31 */
32 template<unsigned int N, class T>
34 {
35 typedef JTypeList<T, typename JMultipleType<N-1, T>::typelist> typelist;
36 };
37
38
39 /**
40 * Terminator class of list of identical types.
41 */
42 template<class T>
43 struct JMultipleType<1, T>
44 {
46 };
47
48
49 /**
50 * Append to type list.
51 *
52 * Source code is taken from reference:
53 * A. Alexandrescu, Modern C++ Design, Addison Wesley.
54 */
55
56
57 /**
58 * Template specialisation of append to type list.
59 */
60 template<class JHead_t, class JTail_t>
65
66
67 /**
68 * Template specialisation of append to type list.
69 */
70 template<>
72 {
74 };
75
76
77 /**
78 * Template specialisation of append to type list.
79 */
80 template<class T>
81 struct JAppend<JNullType, T>
82 {
84 };
85
86
87 /**
88 * Template specialisation of append to type list.
89 */
90 template<class JHead_t, class JTail_t>
91 struct JAppend<JNullType, JTypeList<JHead_t, JTail_t> >
92 {
94 };
95
96
97 /**
98 * Template specialisation of append to type list.
99 */
100 template<class JHead_t, class JTail_t, class T>
105
106
107 /**
108 * Removal of data type from type list.
109 *
110 * Source code is taken from reference:
111 * A. Alexandrescu, Modern C++ Design, Addison Wesley.
112 */
113 template<class JTypelist_t, class T>
114 struct JRemove;
115
116
117 /**
118 * Template specialisation of removal of data type from type list.
119 */
120 template<class T>
122 {
124 };
125
126
127 /**
128 * Template specialisation of removal of data type from type list.
129 */
130 template<class T, class JTail_t>
131 struct JRemove<JTypeList<T, JTail_t>, T>
132 {
133 typedef JTail_t typelist;
134 };
135
136
137 /**
138 * Template specialisation of removal of data type from type list.
139 */
140 template<class JHead_t, class JTail_t, class T>
145
146
147 /**
148 * Template specialisation of removal of type list from type list.
149 */
150 template<class JHead_t1, class JTail_t1, class JHead_t2, class JTail_t2>
151 struct JRemove<JTypeList<JHead_t1, JTail_t1>,
152 JTypeList<JHead_t2, JTail_t2> >
153 {
154 typedef typename JRemove<typename JRemove<JTypeList<JHead_t1, JTail_t1>, JHead_t2>::typelist,
155 JTail_t2>::typelist typelist;
156 };
157
158
159 /**
160 * Template specialisation of removal of type list from type list.
161 */
162 template<class JHead_t1, class JTail_t1, class JHead_t2>
163 struct JRemove<JTypeList<JHead_t1, JTail_t1>,
164 JTypeList<JHead_t2, JNullType> >
165 {
166 typedef typename JRemove<JTypeList<JHead_t1, JTail_t1>, JHead_t2>::typelist typelist;
167 };
168
169
170 /**
171 * Length of type list.
172 *
173 * Source code is taken from reference:
174 * A. Alexandrescu, Modern C++ Design, Addison Wesley.
175 */
176 template<class JTypeList_t> struct JLength {};
177
178
179 /**
180 * Recursive length of type list.
181 */
182 template<class JHead_t, class JTail_t>
183 struct JLength< JTypeList<JHead_t, JTail_t> >
184 {
185 enum { value = 1 + JLength<JTail_t>::value };
186 };
187
188
189 /**
190 * Terminator class of length of type list.
191 */
192 template<>
194 {
195 enum { value = 0 };
196 };
197
198
199 /**
200 * Test presence of data type in type list.
201 */
202 template<class JTypeList_t, class T>
203 struct JHasType;
204
205
206 /**
207 * Recursive test of presence data type in type list.
208 */
209 template<class JHead_t, class JTail_t, class T>
210 struct JHasType<JTypeList<JHead_t, JTail_t>, T>
211 {
213 };
214
215
216 /**
217 * Identify presence data type in type list.
218 */
219 template<class JTail_t, class T>
220 struct JHasType<JTypeList<T, JTail_t>, T>
221 {
222 enum { value = true };
223 };
224
225
226 /**
227 * Termination of recursive test of presence data type in type list.
228 */
229 template<class T>
231 {
232 enum { value = false };
233 };
234
235
236 /**
237 * Specialisation of JHasType for single class type.
238 */
239 template<class T>
240 struct JHasType<T, T>
241 {
242 enum { value = true };
243 };
244
245
246 /**
247 * Resolve template class to JTypeList.
248 */
249 template<class T>
251 {
253 };
254
255
256 /**
257 * Resolve JTypeList to JTypeList.
258 */
259 template<class JHead_t, class JTail_t>
260 struct JResolveTypeList< JTypeList<JHead_t, JTail_t> >
261 {
263 };
264
265
266 /**
267 * Extraction of data type from type list.
268 *
269 * Source code is taken from reference:
270 * A. Alexandrescu, Modern C++ Design, Addison Wesley.
271 */
272 template<class JTypelist_t, unsigned int index, bool range_check = true>
273 struct JTypeAt;
274
275
276 /**
277 * Recursive extraction of data type from type list.
278 */
279 template<class JHead_t, class JTail_t, unsigned int index, bool range_check>
280 struct JTypeAt<JTypeList<JHead_t, JTail_t>, index, range_check>
281 {
282 typedef typename JTypeAt<JTail_t, index - 1, range_check>::value_type value_type;
283 };
284
285
286 /**
287 * Termination of recursive extraction of data type from type list.
288 */
289 template<class JHead_t, class JTail_t, bool range_check>
290 struct JTypeAt<JTypeList<JHead_t, JTail_t>, 0, range_check>
291 {
292 typedef JHead_t value_type;
293 };
294
295
296 /**
297 * Termination of recursive extraction of data type from type list.
298 */
299 template<unsigned int index>
300 struct JTypeAt<JNullType, index, false>
301 {
303 };
304
305
306 /**
307 * Indexing of data type in type list.
308 */
309 template<class JTypeList_t, class T>
310 struct JIndexOf;
311
312
313 /**
314 * Recursive indexing of data type in type list.
315 */
316 template<class JHead_t, class JTail_t, class T>
317 struct JIndexOf<JTypeList<JHead_t, JTail_t>, T>
318 {
319 private:
321
322 public:
323 enum { value = (tmp == -1 ? -1 : tmp + 1) };
324 };
325
326
327 /**
328 * Identify indexi of data type in type list.
329 */
330 template<class JTail_t, class T>
331 struct JIndexOf<JTypeList<T, JTail_t>, T>
332 {
333 enum { value = 0 };
334 };
335
336
337 /**
338 * Termination of recursive indexing of data type in type list.
339 */
340 template<class T>
342 {
343 enum { value = -1 };
344 };
345
346
347 /**
348 * Auxiliary class for recursive type list generation.
349 */
350 template<class T, class ...Args>
351 struct JTYPELIST {
352 typedef JTypeList<T, typename JTYPELIST<Args...>::typelist> typelist;
353 };
354
355
356 /**
357 * Template specialisation for expanding type list.
358 */
359 template<class JHead_t, class JTail_t, class T, class ...Args>
360 struct JTYPELIST<JTypeList<JHead_t, JTail_t>, T, Args...> {
361 typedef JTypeList<JHead_t, typename JTYPELIST<JTail_t, T, Args...>::typelist> typelist;
362 };
363
364
365 /**
366 * Template specialisation for expanding type list.
367 */
368 template<class JHead_t, class T, class ...Args>
369 struct JTYPELIST<JTypeList<JHead_t, JNullType>, T, Args...> {
370 typedef JTypeList<JHead_t, typename JTYPELIST<T, Args...>::typelist> typelist;
371 };
372
373
374 /**
375 * Template specialisation for expanding type list.
376 */
377 template<class JHead_t, class JTail_t>
378 struct JTYPELIST< JTypeList<JHead_t, JTail_t> > {
380 };
381
382
383 /**
384 * Termination class for type list generation.
385 */
386 template<class T>
387 struct JTYPELIST<T> {
389 };
390
391
392 /**
393 * Termination class for type list generation.
394 */
395 template<>
398 };
399
400
401 /**
402 * For each data type method.
403 *
404 * The given object should provide for the function object operator
405 * <pre>
406 * template<class T>
407 * void operator()(JType<T> type);
408 * </pre>
409 *
410 * \param object object
411 * \param typelist type list
412 */
413 template<class JObject_t, class JHead_t, class JTail_t>
414 void for_each(JObject_t& object, JType< JTypeList<JHead_t, JTail_t> > typelist)
415 {
416 for_each(object, JType<JHead_t>());
417 for_each(object, JType<JTail_t>());
418 }
419
420
421 /**
422 * For each data type method.
423 *
424 * The given object should provide for the function object operator
425 * <pre>
426 * template<class T>
427 * void operator()(JType<T> type);
428 * </pre>
429 *
430 * \param object object
431 * \param type type
432 */
433 template<class JObject_t, class T>
434 void for_each(JObject_t& object, JType<T> type)
435 {
436 object(type);
437 }
438
439
440 /**
441 * Termination method of for each data type method.
442 *
443 * \param object object
444 * \param type null type
445 */
446 template<class JObject_t>
447 void for_each(JObject_t& object, JType<JNullType> type)
448 {}
449
450
451 /**
452 * For each data type method.
453 *
454 * The given object should provide for the function object operator
455 * <pre>
456 * template<class T>
457 * void operator()(JType<T> type);
458 * </pre>
459 *
460 * \param object object
461 */
462 template<class JTypelist_t, class JObject_t>
463 void for_each(JObject_t& object)
464 {
465 for_each(object, JType<JTypelist_t>());
466 }
467}
468
469#endif
Auxiliary classes and methods for language specific functionality.
void for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition JTypeList.hh:414
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JTypeList< JHead_t, typename JAppend< JTail_t, T >::typelist > typelist
Definition JTypeList.hh:103
Append to type list.
Definition JTypeList.hh:62
JTypeList< JHead_t, JTail_t > typelist
Definition JTypeList.hh:63
Test presence of data type in type list.
Definition JTypeList.hh:203
Indexing of data type in type list.
Definition JTypeList.hh:310
Length of type list.
Definition JTypeList.hh:176
JTypeList< T, JNullType > typelist
Definition JTypeList.hh:45
List of identical types.
Definition JTypeList.hh:34
JTypeList< T, typename JMultipleType< N-1, T >::typelist > typelist
Definition JTypeList.hh:35
Auxiliary class for no type definition.
Definition JNullType.hh:19
JRemove< JTypeList< JHead_t1, JTail_t1 >, JHead_t2 >::typelist typelist
Definition JTypeList.hh:166
JRemove< typenameJRemove< JTypeList< JHead_t1, JTail_t1 >, JHead_t2 >::typelist, JTail_t2 >::typelist typelist
Definition JTypeList.hh:155
JTypeList< JHead_t, typename JRemove< JTail_t, T >::typelist > typelist
Definition JTypeList.hh:143
Removal of data type from type list.
Definition JTypeList.hh:114
Resolve template class to JTypeList.
Definition JTypeList.hh:251
JTypeList< T > typelist
Definition JTypeList.hh:252
JTypeList< JHead_t, typename JTYPELIST< T, Args... >::typelist > typelist
Definition JTypeList.hh:370
JTypeList< JHead_t, typename JTYPELIST< JTail_t, T, Args... >::typelist > typelist
Definition JTypeList.hh:361
JTypeList< T > typelist
Definition JTypeList.hh:388
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
JTypeList< T, typename JTYPELIST< Args... >::typelist > typelist
Definition JTypeList.hh:352
JTypeAt< JTail_t, index-1, range_check >::value_type value_type
Definition JTypeList.hh:282
Extraction of data type from type list.
Definition JTypeList.hh:273
Type list.
Definition JTypeList.hh:23
JHead_t head_type
Definition JTypeList.hh:24
JTail_t tail_type
Definition JTypeList.hh:25
Auxiliary class for a type holder.
Definition JType.hh:19