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_type_trait.h
1 /// @file detail/deduce_type_trait.h
2 ///
3 /// The declaration and definition of DeduceTypeTrait.
4 ///
5 /// A template meta-function that selects the appropriate trait tag for
6 /// automatic type deduction of other processing constructs. One particularly
7 /// important system that depends on this is the DataProxy abstraction.
8 ///
9 /// The MIT License(MIT)
10 /// @copyright 2014 Paul M Watt
11 // ****************************************************************************
12 #ifndef DEDUCE_TYPE_TRAIT_H_INCLUDED
13 #define DEDUCE_TYPE_TRAIT_H_INCLUDED
14 // Includes ******************************************************************
15 #include <Pb/meta_util.h>
16 
17 namespace Hg
18 {
19 
20 namespace detail
21 {
22 
23 // ****************************************************************************
24 /// A convenience meta-function to define the type trait tag that is best
25 /// suited for specified type.
26 /// The constructed type can be accessed through the public typedef *type*.
27 ///
28 /// @paramt ValueT [typename] The value to identify the traits.
29 ///
30 template< typename ValueT >
32 {
33 private:
34  // **************************************************************************
35  typedef ValueT value_type;
36 
37  // **************************************************************************
38  /// There are four distinct types of proxy objects required:
39  /// Search from most general to most restrictive.
40  /// Propagate the type info forward until the last test.
41  /// The remaining trait at the end will be the most specific type role
42  /// the index_type satisfies.
43  ///
44  /// 1: datum proxy: Fundamental and nested heterogenous types.
45  /// - This is the catch all type for fields that
46  /// do not require any special processing.
47  /// 2: bit field proxy Bit-field types
48  /// 3: dynamic array proxy Dynamically sized nested homogenous types
49  /// 4: fixed array proxy Fixed sized nested homogenous types
50  ///
51  typedef typename
52  std::conditional< packed_value<value_type>::value,
55  >::type basic_type;
56 
57  // **************************************************************************
58  // Defines the nested-type trait to use for compound structures.
59  //
60  typedef typename
61  std::conditional< nested_value<value_type>::value,
63  basic_type
64  >::type nested_type;
65 
66  // **************************************************************************
67  // Specifies a sequence type trait to use if a sequence_value is selected.
68  //
69  typedef typename
70  std::conditional< vector_value<value_type>::value,
72  nested_type
73  >::type dynamic_type;
74 
75  // **************************************************************************
76  // Differentiates between an array and a vector type sequence.
77  //
78  typedef typename
79  std::conditional< array_value<value_type>::value,
81  dynamic_type
82  >::type deduced_type_trait;
83 
84 public:
85 
86  // **************************************************************************
87  /// The type trait tag deduced for the specified parameter type.
88  ///
89  typedef deduced_type_trait type;
90 };
91 
92 // ****************************************************************************
93 /// A specialization that will deduce the traits from an index in a TypeList.
94 ///
95 /// @paramt IdxT
96 /// @paramt FormatT
97 ///
98 template< size_t IdxT,
99  typename FormatT
100  >
102 {
103 private:
104  typedef typename
105  TypeAt< IdxT, FormatT >::type value_type;
106 
107  typedef typename
108  DeduceTypeTrait<value_type>::type deduced_type_trait;
109 
110 public:
111  // **************************************************************************
112  /// The type trait tag deduced for the specified parameter type.
113  ///
114  typedef deduced_type_trait type;
115 };
116 
117 
118 } // namespace detail
119 
120 } // namespace Hg
121 
122 #endif