IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
PromotedType.h
Go to the documentation of this file.
1 // PromotedType.h:
3 // ---------------
4 //
14 
15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_PROMOTEDTYPE_H__
16 #define __IPSDKUTIL_INSTRUCTIONSET_PROMOTEDTYPE_H__
17 
19 
20 #include <boost/type_traits/is_signed.hpp>
21 
23 
24 namespace ipsdk {
25 
26 // choose the larger of two types
27 template<
28  typename T1
29  , typename T2
30  , bool choose1 = (sizeof(T1) > sizeof(T2)) // hands off!
31  >
32 struct choose_larger
33 {
34  typedef T1 Type;
35 };
36 
37 // specialization for the case where sizeof(T2) >= sizeof(T1)
38 template< typename T1, typename T2 >
39 struct choose_larger< T1, T2, false >
40 {
41  typedef T2 Type;
42 };
43 
46 
47 
48 // template PromotedType<T1, T2> declaration
49 template <typename T1, typename T2,
50  typename Enable=void>
51 struct PromotedType
52 {
53 };
54 
55 // specialization for case "T1 is integral, T2 is not"
56 template <typename T1, typename T2>
57 struct PromotedType<T1, T2,
58  typename boost::enable_if_c<
59  boost::is_integral<T1>::value
60  && !boost::is_integral<T2>::value
61  >::type
62  >
63 {
64  typedef T2 Type;
65 };
66 
67 // specialization for case "T2 is integral, T1 is not"
68 template <typename T1, typename T2>
69 struct PromotedType<T1, T2,
70  typename boost::enable_if_c<
71  !boost::is_integral<T1>::value
72  && boost::is_integral<T2>::value
73  >::type
74  >
75 {
76  typedef T1 Type;
77 };
78 
79 // specialization for case "T1 and T2 are both integral (or both not), and have
80 // different sizes"
81 template <typename T1, typename T2>
82 struct PromotedType<T1, T2,
83  typename boost::enable_if_c<
84  boost::is_integral<T1>::value == boost::is_integral<T2>::value
85  && sizeof(T1) != sizeof(T2)
86  >::type>
87 {
88  typedef typename choose_larger<T1, T2>::Type Type;
89 };
90 
91 // specialization for case "T1 and T2 have same type"
92 template <typename T1, typename T2>
93 struct PromotedType<T1, T2,
94  typename boost::enable_if_c<
95  boost::is_same<T1, T2>::value
96  >::type>
97 {
98  typedef T1 Type;
99 };
100 
101 // specialization for case "T1 and T2 are integers of same size; T1 is signed
102 // whereas T2 is unsigned"
103 template <typename T1, typename T2>
104 struct PromotedType<T1, T2,
105  typename boost::enable_if_c<
106  boost::is_integral<T1>::value
107  && boost::is_integral<T2>::value
108  && sizeof(T1) == sizeof(T2)
109  && boost::is_signed<T1>::value
110  && !boost::is_signed<T2>::value
111  >::type>
112 {
113  typedef T2 Type;
114 };
115 
116 // specialization for case "T1 and T2 are integers of same size; T1 is unsigned
117 // whereas T2 is signed"
118 template <typename T1, typename T2>
119 struct PromotedType<T1, T2,
120  typename boost::enable_if_c<
121  boost::is_integral<T1>::value
122  && boost::is_integral<T2>::value
123  && sizeof(T1) == sizeof(T2)
124  && !boost::is_signed<T1>::value
125  && boost::is_signed<T2>::value
126  >::type>
127 {
128  typedef T1 Type;
129 };
130 
131 // struct PromotedType3: gives the greatest type of 3
132 template <typename T1, typename T2, typename T3>
133 struct PromotedType3
134 {
135  typedef
136  typename PromotedType<typename PromotedType<T1, T2>::Type, T3>::Type
137  Type;
138 };
139 
142 
143 } // end of namespace ipsdk
144 
146 
147 #endif // __IPSDKUTIL_INSTRUCTIONSET_PROMOTEDTYPE_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: DataItemNodeHdrMacrosDetails.h:48
Definition of import/export macro for library.