[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

sized_int.hxx VIGRA

1 /************************************************************************/
2 /* */
3 /* Copyright 1998-2002 by Ullrich Koethe */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35 
36 
37 #ifndef VIGRA_SIZED_INT_HXX
38 #define VIGRA_SIZED_INT_HXX
39 
40 #include "metaprogramming.hxx"
41 #include <limits>
42 
43 #if SHRT_MAX == 0x7FL
44 # define VIGRA_BITSOF_SHORT 8
45 #elif SHRT_MAX == 0x7FFFL
46 # define VIGRA_BITSOF_SHORT 16
47 #elif SHRT_MAX == 0x7FFFFFFFL
48 # define VIGRA_BITSOF_SHORT 32
49 #elif SHRT_MAX > 0xFFFFFFFFL
50 # define VIGRA_BITSOF_SHORT 64
51 #else
52 # define VIGRA_BITSOF_SHORT -1
53 #endif
54 
55 #if INT_MAX == 0x7FL
56 # define VIGRA_BITSOF_INT 8
57 #elif INT_MAX == 0x7FFFL
58 # define VIGRA_BITSOF_INT 16
59 #elif INT_MAX == 0x7FFFFFFFL
60 # define VIGRA_BITSOF_INT 32
61 #elif INT_MAX > 0xFFFFFFFFL
62 # define VIGRA_BITSOF_INT 64
63 #else
64 # define VIGRA_BITSOF_INT -1
65 #endif
66 
67 #if LONG_MAX == 0x7FL
68 # define VIGRA_BITSOF_LONG 8
69 #elif LONG_MAX == 0x7FFFL
70 # define VIGRA_BITSOF_LONG 16
71 #elif LONG_MAX == 0x7FFFFFFFL
72 # define VIGRA_BITSOF_LONG 32
73 #elif LONG_MAX > 0xFFFFFFFFL
74 # define VIGRA_BITSOF_LONG 64
75 #else
76 # define VIGRA_BITSOF_LONG -1
77 #endif
78 
79 #if LLONG_MAX == 0x7FL
80 # define VIGRA_BITSOF_LONG_LONG 8
81 #elif LLONG_MAX == 0x7FFFL
82 # define VIGRA_BITSOF_LONG_LONG 16
83 #elif LLONG_MAX == 0x7FFFFFFFL
84 # define VIGRA_BITSOF_LONG_LONG 32
85 #elif LLONG_MAX > 0xFFFFFFFFL
86 # define VIGRA_BITSOF_LONG_LONG 64
87 #else
88 # define VIGRA_BITSOF_LONG_LONG -1
89 #endif
90 
91 namespace vigra {
92 
93 class Int_type_not_supported_on_this_platform {};
94 
95 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION
96 
97 namespace detail {
98 
99 template<class T, class NEXT>
100 struct IntTypeList
101 {
102  enum { size = sizeof(T)*8 };
103  typedef T type;
104  typedef NEXT next;
105 };
106 
107 template<int SIZE, class LIST>
108 struct SelectIntegerType
109 {
110  typedef typename
111  IfBool<(SIZE == LIST::size),
112  typename LIST::type,
113  typename SelectIntegerType<SIZE, typename LIST::next>::type >::type
114  type;
115 };
116 
117 template<int SIZE>
118 struct SelectIntegerType<SIZE, Int_type_not_supported_on_this_platform>
119 {
120  typedef Int_type_not_supported_on_this_platform type;
121 };
122 
123 template<class LIST>
124 struct SelectBiggestIntegerType
125 {
126  enum { cursize = static_cast<int>(LIST::size),
127  nextsize = static_cast<int>(SelectBiggestIntegerType<typename LIST::next>::size),
128  size = (cursize < nextsize) ? nextsize : cursize };
129  typedef typename
130  IfBool<(cursize < nextsize),
131  typename SelectBiggestIntegerType<typename LIST::next>::type,
132  typename LIST::type>::type
133  type;
134 };
135 
136 template<>
137 struct SelectBiggestIntegerType<Int_type_not_supported_on_this_platform>
138 {
139  enum { size = 0 };
140  typedef Int_type_not_supported_on_this_platform type;
141 };
142 
143 typedef IntTypeList<signed char,
144  IntTypeList<signed short,
145  IntTypeList<signed int,
146  IntTypeList<signed long,
147  IntTypeList<signed long long,
148  Int_type_not_supported_on_this_platform > > > > > SignedIntTypes;
149 typedef IntTypeList<unsigned char,
150  IntTypeList<unsigned short,
151  IntTypeList<unsigned int,
152  IntTypeList<unsigned long,
153  IntTypeList<unsigned long long,
154  Int_type_not_supported_on_this_platform > > > > > UnsignedIntTypes;
155 
156 } // namespace detail
157 
158 /** \addtogroup FixedSizeInt Fixed Size Integer Types
159 
160  Since the C++ standard does only specify minimal sizes for the built-in
161  integer types, one cannot rely on them to have a specific size. But
162  pixel types with a specific size are often required in image processing,
163  especially when reading or writing binary files. The VIGRA typedefs
164  are guaranteed to have exactly the correct size. If the system
165  does not provide a suitable type, the typedef will evaluate to
166  <tt>Int_type_not_supported_on_this_platform</tt>.
167 */
168 //@{
169 
170  /// 8-bit signed int
171 typedef detail::SelectIntegerType<8, detail::SignedIntTypes>::type Int8;
172  /// 16-bit signed int
173 typedef detail::SelectIntegerType<16, detail::SignedIntTypes>::type Int16;
174  /// 32-bit signed int
175 typedef detail::SelectIntegerType<32, detail::SignedIntTypes>::type Int32;
176  /// 64-bit signed int
177 typedef detail::SelectIntegerType<64, detail::SignedIntTypes>::type Int64;
178  /// 8-bit unsigned int
179 typedef detail::SelectIntegerType<8, detail::UnsignedIntTypes>::type UInt8;
180  /// 16-bit unsigned int
181 typedef detail::SelectIntegerType<16, detail::UnsignedIntTypes>::type UInt16;
182  /// 32-bit unsigned int
183 typedef detail::SelectIntegerType<32, detail::UnsignedIntTypes>::type UInt32;
184  /// 64-bit unsigned int
185 typedef detail::SelectIntegerType<64, detail::UnsignedIntTypes>::type UInt64;
186 
187  /// the biggest signed integer type of the system
188 typedef detail::SelectBiggestIntegerType<detail::SignedIntTypes>::type IntBiggest;
189  /// the biggest unsigned integer type of the system
190 typedef detail::SelectBiggestIntegerType<detail::UnsignedIntTypes>::type UIntBiggest;
191 
192 //@}
193 
194 #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION
195 
196 typedef signed char Int8;
197 typedef signed short Int16;
198 typedef signed int Int32;
199 typedef Int_type_not_supported_on_this_platform Int64;
200 typedef unsigned char UInt8;
201 typedef unsigned short UInt16;
202 typedef unsigned int UInt32;
203 typedef Int_type_not_supported_on_this_platform UInt64;
204 
205 typedef Int32 IntBiggest;
206 typedef UInt32 UIntBiggest;
207 
208 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION
209 
210 } // namespace vigra
211 
212 #endif /* VIGRA_SIZED_INT_HXX */
detail::SelectIntegerType< 8, detail::UnsignedIntTypes >::type UInt8
8-bit unsigned int
Definition: sized_int.hxx:179
detail::SelectIntegerType< 16, detail::UnsignedIntTypes >::type UInt16
16-bit unsigned int
Definition: sized_int.hxx:181
detail::SelectIntegerType< 64, detail::SignedIntTypes >::type Int64
64-bit signed int
Definition: sized_int.hxx:177
detail::SelectBiggestIntegerType< detail::UnsignedIntTypes >::type UIntBiggest
the biggest unsigned integer type of the system
Definition: sized_int.hxx:190
detail::SelectIntegerType< 16, detail::SignedIntTypes >::type Int16
16-bit signed int
Definition: sized_int.hxx:173
detail::SelectIntegerType< 32, detail::SignedIntTypes >::type Int32
32-bit signed int
Definition: sized_int.hxx:175
detail::SelectBiggestIntegerType< detail::SignedIntTypes >::type IntBiggest
the biggest signed integer type of the system
Definition: sized_int.hxx:188
detail::SelectIntegerType< 32, detail::UnsignedIntTypes >::type UInt32
32-bit unsigned int
Definition: sized_int.hxx:183
detail::SelectIntegerType< 64, detail::UnsignedIntTypes >::type UInt64
64-bit unsigned int
Definition: sized_int.hxx:185
detail::SelectIntegerType< 8, detail::SignedIntTypes >::type Int8
8-bit signed int
Definition: sized_int.hxx:171

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.11.1 (Fri May 19 2017)