Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
12 namespace JLANG {}
13 namespace JPP { using namespace JLANG; }
14 
15 namespace 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>
33  struct JMultipleType
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>
61  struct JAppend
62  {
64  };
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>
101  struct JAppend<JTypeList<JHead_t, JTail_t>, T>
102  {
104  };
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>
121  struct JRemove<JNullType, 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>
141  struct JRemove<JTypeList<JHead_t, JTail_t>, T>
142  {
144  };
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  {
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  {
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  {
212  enum { value = JHasType<JTail_t, T>::value };
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 object()(JType<T> type);
408  * </pre>
409  *
410  * \param object object
411  * \param typelist type list
412  * \return object
413  */
414  template<class JObject_t, class JHead_t, class JTail_t>
415  JObject_t& for_each(JObject_t& object, JType< JTypeList<JHead_t, JTail_t> > typelist)
416  {
417  for_each(object, JType<JHead_t>());
418  for_each(object, JType<JTail_t>());
419 
420  return object;
421  }
422 
423 
424  /**
425  * For each data type method.
426  *
427  * The given object should provide for the function object operator
428  * <pre>
429  * template<class T>
430  * void object()(JType<T> type);
431  * </pre>
432  *
433  * \param object object
434  * \param type type
435  * \return object
436  */
437  template<class JObject_t, class T>
438  JObject_t& for_each(JObject_t& object, JType<T> type)
439  {
440  object(type);
441 
442  return object;
443  }
444 
445 
446  /**
447  * Termination method of for each data type method.
448  *
449  * \param object object
450  * \param type null type
451  * \return object
452  */
453  template<class JObject_t>
454  JObject_t& for_each(JObject_t& object, JType<JNullType> type)
455  {
456  return object;
457  }
458 }
459 
460 #endif
JRemove< typename JRemove< JTypeList< JHead_t1, JTail_t1 >, JHead_t2 >::typelist, JTail_t2 >::typelist typelist
Definition: JTypeList.hh:155
JTypeAt< JTail_t, index-1, range_check >::value_type value_type
Definition: JTypeList.hh:282
Append to type list.
Definition: JTypeList.hh:61
Test presence of data type in type list.
Definition: JTypeList.hh:203
JTypeList< T > typelist
Definition: JTypeList.hh:388
Removal of data type from type list.
Definition: JTypeList.hh:114
JHead_t head_type
Definition: JTypeList.hh:24
Auxiliary class for a type holder.
Definition: JType.hh:19
JTypeList< T, JNullType > typelist
Definition: JTypeList.hh:45
Length of type list.
Definition: JTypeList.hh:176
Type list.
Definition: JTypeList.hh:22
JTail_t tail_type
Definition: JTypeList.hh:25
do montage tile geometry tmp
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
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
JTypeList< T > typelist
Definition: JTypeList.hh:252
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Resolve template class to JTypeList.
Definition: JTypeList.hh:250
Auxiliary class for no type definition.
Definition: JNullType.hh:19
JRemove< JTypeList< JHead_t1, JTail_t1 >, JHead_t2 >::typelist typelist
Definition: JTypeList.hh:166
List of identical types.
Definition: JTypeList.hh:33
JTypeList< JHead_t, typename JRemove< JTail_t, T >::typelist > typelist
Definition: JTypeList.hh:143
JTypeList< JHead_t, typename JAppend< JTail_t, T >::typelist > typelist
Definition: JTypeList.hh:103
JObject_t & for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition: JTypeList.hh:415
JTypeList< JHead_t, JTail_t > typelist
Definition: JTypeList.hh:63
JTypeList< T, typename JTYPELIST< Args...>::typelist > typelist
Definition: JTypeList.hh:352
Indexing of data type in type list.
Definition: JTypeList.hh:310
JTypeList< T, typename JMultipleType< N-1, T >::typelist > typelist
Definition: JTypeList.hh:35
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37
JTypeList< JHead_t, JTail_t > typelist
Definition: JTypeList.hh:379
Extraction of data type from type list.
Definition: JTypeList.hh:273