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/offset_of.h
1 /// @file meta/type_list/offset_of.h
2 ///
3 /// Calculates the offset in bytes of the type at the specified index in the
4 /// Type Container.
5 ///
6 /// The MIT License(MIT)
7 /// @copyright 2014 Paul M Watt
8 // ****************************************************************************
9 #ifndef OFFSET_OF_H_INCLUDED
10 # error "Do not include this file directly. Use <Pb/offset_of.h> instead"
11 #endif
12 
13 
14 namespace Hg
15 {
16 
17 // ****************************************************************************
18 /// Defines each type offset lookup
19 ///
20 /// This macro will generate a set of code for type definitions that looks like
21 /// this, where 3 has been used for the input I.
22 ///
23 /// ~~~{.cpp}
24 /// tmp_ALCHEMY_TYPELIST_OFFSETOF(3);
25 ///
26 /// template <TypeList < typename T0, typename T1, typename T2, typename T3,
27 /// typename T4, typename T5, typename T6, typename T7,
28 /// typename T8, typename T9, typename T10, typename T11,
29 /// typename T12, typename T13, typename T14, typename T15,
30 /// typename T16, typename T17, typename T18, typename T19,
31 /// typename T20, typename T21, typename T22, typename T23,
32 /// typename T24, typename T25, typename T26, typename T27,
33 /// typename T28, typename T29, typename T30, typename T31>,
34 /// ErrorT
35 /// >
36 /// ptrdiff_t OffsetOf< (3),
37 /// TypeList < T0, T1, T2, T3, T4, T5, T6, T7,
38 /// T8, T9, T10, T11, T12, T13, T14, T15,
39 /// T16, T17, T18, T19, T20, T21, T22, T23,
40 /// T24, T25, T26, T27, T28, T29, T30, T31
41 /// >;
42 /// >
43 /// {
44 /// typedef TypeList < T0, T1, T2, T3, T4, T5, T6, T7,
45 /// T8, T9, T10, T11, T12, T13, T14, T15,
46 /// T16, T17, T18, T19, T20, T21, T22, T23,
47 /// T24, T25, T26, T27, T28, T29, T30, T31
48 /// > ContainerT;
49 /// static const size_t value = SizeOf <3-1, ContainerT>()
50 /// + OffsetOf<3-1, ContainerT>();
51 /// };
52 /// ~~~
53 ///
54 /// @note: This is a locally defined MACRO. After the list of entries
55 /// have been defined to generate the required function calls,
56 /// the MACRO will be undefined.
57 // ****************************************************************************
58 #define tmp_ALCHEMY_TYPELIST_OFFSETOF(I) \
59 template <TMP_ARRAY_32(typename T)> \
60 struct OffsetOf< (I), TypeList<TMP_ARRAY_32(T)> > \
61 { \
62  typedef TypeList<TMP_ARRAY_32(T)> container; \
63  \
64  enum { value = OffsetOf<(I)-1, container>::value \
65  + SizeAt <(I)-1, container>::value }; \
66 }
67 
68 
69 
70 // Declarations for each ENTRY that is supported for the TypeList size *******
71 // Offset for zero is handled as a special case above *************************
72 tmp_ALCHEMY_TYPELIST_OFFSETOF(1);
73 tmp_ALCHEMY_TYPELIST_OFFSETOF(2);
74 tmp_ALCHEMY_TYPELIST_OFFSETOF(3);
75 tmp_ALCHEMY_TYPELIST_OFFSETOF(4);
76 tmp_ALCHEMY_TYPELIST_OFFSETOF(5);
77 tmp_ALCHEMY_TYPELIST_OFFSETOF(6);
78 tmp_ALCHEMY_TYPELIST_OFFSETOF(7);
79 tmp_ALCHEMY_TYPELIST_OFFSETOF(8);
80 tmp_ALCHEMY_TYPELIST_OFFSETOF(9);
81 tmp_ALCHEMY_TYPELIST_OFFSETOF(10);
82 tmp_ALCHEMY_TYPELIST_OFFSETOF(11);
83 tmp_ALCHEMY_TYPELIST_OFFSETOF(12);
84 tmp_ALCHEMY_TYPELIST_OFFSETOF(13);
85 tmp_ALCHEMY_TYPELIST_OFFSETOF(14);
86 tmp_ALCHEMY_TYPELIST_OFFSETOF(15);
87 tmp_ALCHEMY_TYPELIST_OFFSETOF(16);
88 tmp_ALCHEMY_TYPELIST_OFFSETOF(17);
89 tmp_ALCHEMY_TYPELIST_OFFSETOF(18);
90 tmp_ALCHEMY_TYPELIST_OFFSETOF(19);
91 tmp_ALCHEMY_TYPELIST_OFFSETOF(20);
92 tmp_ALCHEMY_TYPELIST_OFFSETOF(21);
93 tmp_ALCHEMY_TYPELIST_OFFSETOF(22);
94 tmp_ALCHEMY_TYPELIST_OFFSETOF(23);
95 tmp_ALCHEMY_TYPELIST_OFFSETOF(24);
96 tmp_ALCHEMY_TYPELIST_OFFSETOF(25);
97 tmp_ALCHEMY_TYPELIST_OFFSETOF(26);
98 tmp_ALCHEMY_TYPELIST_OFFSETOF(27);
99 tmp_ALCHEMY_TYPELIST_OFFSETOF(28);
100 tmp_ALCHEMY_TYPELIST_OFFSETOF(29);
101 tmp_ALCHEMY_TYPELIST_OFFSETOF(30);
102 tmp_ALCHEMY_TYPELIST_OFFSETOF(31);
103 
104 // Undefining the declaration MACRO to prevent its further use. ***************
105 #undef tmp_ALCHEMY_TYPELIST_OFFSETOF
106 
107 } // namespace Hg
108