Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
deduce_msg_type_list.h
1 /// @file detail/deduce_msg_type_list.h
2 ///
3 /// The declaration and definition of DeduceMsgTypeList.
4 ///
5 /// A template meta-function that composes a typelist definition from
6 /// a specified object that contains a collection of meta-functions that
7 /// indicate the type of a parameter at a specified index.
8 ///
9 /// The MIT License(MIT)
10 /// @copyright 2014 Paul M Watt
11 // ****************************************************************************
12 #ifndef DEDUCE_MSG_TYPE_LIST_H_INCLUDED
13 #define DEDUCE_MSG_TYPE_LIST_H_INCLUDED
14 // Includes ******************************************************************
15 #include <Pb/meta_util.h>
16 
17 namespace Hg
18 {
19 
20 namespace detail
21 {
22 
23 
24 // ****************************************************************************
25 // Invariant: PosT must be < LimitT
26 //
27 // This function builds the typelist starting from the rear.
28 //
29 template< typename T,
30  size_t PosT,
31  size_t LimitT
32  >
33 struct DeduceMsgTypeList_Worker
34 {
35  typedef typename
36  push_front
37  < typename DeduceMsgTypeList_Worker<T,PosT+1, LimitT>::type,
38  typename Hg::TypeAt<PosT, typename T::format_type>::type
39  >::type type;
40 };
41 
42 // ****************************************************************************
43 template< typename T,
44  size_t PosT
45  >
46 struct DeduceMsgTypeList_Worker<T, PosT, PosT>
47 {
48  typedef
49  TypeList<typename Hg::TypeAt<PosT, typename T::format_type>::type> type;
50 };
51 
52 // ****************************************************************************
53 /// A convenience meta-function to define the typelist of a message object
54 /// that is derived from the specified field-types.
55 ///
56 /// The constructed type can be accessed through the public typedef *type*.
57 ///
58 /// @paramt T [typename] The msg type that contains the sub-fields.
59 /// @param SizeT [size_t] The number of sub-fields to index.
60 ///
61 template< typename T,
62  size_t SizeT
63  >
65 {
66  typedef typename
67  DeduceMsgTypeList_Worker<T,0, SizeT>::type type;
68 };
69 
70 } // namespace detail
71 
72 } // namespace Hg
73 
74 #endif