[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
vigra/sized_int.hxx | ![]() |
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 1998-2002 by Ullrich Koethe */ 00004 /* */ 00005 /* This file is part of the VIGRA computer vision library. */ 00006 /* The VIGRA Website is */ 00007 /* http://hci.iwr.uni-heidelberg.de/vigra/ */ 00008 /* Please direct questions, bug reports, and contributions to */ 00009 /* ullrich.koethe@iwr.uni-heidelberg.de or */ 00010 /* vigra@informatik.uni-hamburg.de */ 00011 /* */ 00012 /* Permission is hereby granted, free of charge, to any person */ 00013 /* obtaining a copy of this software and associated documentation */ 00014 /* files (the "Software"), to deal in the Software without */ 00015 /* restriction, including without limitation the rights to use, */ 00016 /* copy, modify, merge, publish, distribute, sublicense, and/or */ 00017 /* sell copies of the Software, and to permit persons to whom the */ 00018 /* Software is furnished to do so, subject to the following */ 00019 /* conditions: */ 00020 /* */ 00021 /* The above copyright notice and this permission notice shall be */ 00022 /* included in all copies or substantial portions of the */ 00023 /* Software. */ 00024 /* */ 00025 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */ 00026 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */ 00027 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */ 00028 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */ 00029 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */ 00030 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */ 00031 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */ 00032 /* OTHER DEALINGS IN THE SOFTWARE. */ 00033 /* */ 00034 /************************************************************************/ 00035 00036 00037 #ifndef VIGRA_SIZED_INT_HXX 00038 #define VIGRA_SIZED_INT_HXX 00039 00040 #include "metaprogramming.hxx" 00041 #include <limits> 00042 00043 #if SHRT_MAX == 0x7FL 00044 # define VIGRA_BITSOF_SHORT 8 00045 #elif SHRT_MAX == 0x7FFFL 00046 # define VIGRA_BITSOF_SHORT 16 00047 #elif SHRT_MAX == 0x7FFFFFFFL 00048 # define VIGRA_BITSOF_SHORT 32 00049 #elif SHRT_MAX > 0xFFFFFFFFL 00050 # define VIGRA_BITSOF_SHORT 64 00051 #else 00052 # define VIGRA_BITSOF_SHORT -1 00053 #endif 00054 00055 #if INT_MAX == 0x7FL 00056 # define VIGRA_BITSOF_INT 8 00057 #elif INT_MAX == 0x7FFFL 00058 # define VIGRA_BITSOF_INT 16 00059 #elif INT_MAX == 0x7FFFFFFFL 00060 # define VIGRA_BITSOF_INT 32 00061 #elif INT_MAX > 0xFFFFFFFFL 00062 # define VIGRA_BITSOF_INT 64 00063 #else 00064 # define VIGRA_BITSOF_INT -1 00065 #endif 00066 00067 #if LONG_MAX == 0x7FL 00068 # define VIGRA_BITSOF_LONG 8 00069 #elif LONG_MAX == 0x7FFFL 00070 # define VIGRA_BITSOF_LONG 16 00071 #elif LONG_MAX == 0x7FFFFFFFL 00072 # define VIGRA_BITSOF_LONG 32 00073 #elif LONG_MAX > 0xFFFFFFFFL 00074 # define VIGRA_BITSOF_LONG 64 00075 #else 00076 # define VIGRA_BITSOF_LONG -1 00077 #endif 00078 00079 #if LLONG_MAX == 0x7FL 00080 # define VIGRA_BITSOF_LONG_LONG 8 00081 #elif LLONG_MAX == 0x7FFFL 00082 # define VIGRA_BITSOF_LONG_LONG 16 00083 #elif LLONG_MAX == 0x7FFFFFFFL 00084 # define VIGRA_BITSOF_LONG_LONG 32 00085 #elif LLONG_MAX > 0xFFFFFFFFL 00086 # define VIGRA_BITSOF_LONG_LONG 64 00087 #else 00088 # define VIGRA_BITSOF_LONG_LONG -1 00089 #endif 00090 00091 namespace vigra { 00092 00093 class Int_type_not_supported_on_this_platform {}; 00094 00095 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION 00096 00097 namespace detail { 00098 00099 template<class T, class NEXT> 00100 struct IntTypeList 00101 { 00102 enum { size = sizeof(T)*8 }; 00103 typedef T type; 00104 typedef NEXT next; 00105 }; 00106 00107 template<int SIZE, class LIST> 00108 struct SelectIntegerType 00109 { 00110 typedef typename 00111 IfBool<(SIZE == LIST::size), 00112 typename LIST::type, 00113 typename SelectIntegerType<SIZE, typename LIST::next>::type >::type 00114 type; 00115 }; 00116 00117 template<int SIZE> 00118 struct SelectIntegerType<SIZE, Int_type_not_supported_on_this_platform> 00119 { 00120 typedef Int_type_not_supported_on_this_platform type; 00121 }; 00122 00123 template<class LIST> 00124 struct SelectBiggestIntegerType 00125 { 00126 enum { cursize = static_cast<int>(LIST::size), 00127 nextsize = static_cast<int>(SelectBiggestIntegerType<typename LIST::next>::size), 00128 size = (cursize < nextsize) ? nextsize : cursize }; 00129 typedef typename 00130 IfBool<(cursize < nextsize), 00131 typename SelectBiggestIntegerType<typename LIST::next>::type, 00132 typename LIST::type>::type 00133 type; 00134 }; 00135 00136 template<> 00137 struct SelectBiggestIntegerType<Int_type_not_supported_on_this_platform> 00138 { 00139 enum { size = 0 }; 00140 typedef Int_type_not_supported_on_this_platform type; 00141 }; 00142 00143 typedef IntTypeList<signed char, 00144 IntTypeList<signed short, 00145 IntTypeList<signed int, 00146 IntTypeList<signed long, 00147 IntTypeList<signed long long, 00148 Int_type_not_supported_on_this_platform > > > > > SignedIntTypes; 00149 typedef IntTypeList<unsigned char, 00150 IntTypeList<unsigned short, 00151 IntTypeList<unsigned int, 00152 IntTypeList<unsigned long, 00153 IntTypeList<unsigned long long, 00154 Int_type_not_supported_on_this_platform > > > > > UnsignedIntTypes; 00155 00156 } // namespace detail 00157 00158 /** \addtogroup FixedSizeInt Fixed Size Integer Types 00159 00160 Since the C++ standard does only specify minimal sizes for the built-in 00161 integer types, one cannot rely on them to have a specific size. But 00162 pixel types with a specific size are often required in image processing, 00163 especially when reading or writing binary files. The VIGRA typedefs 00164 are guaranteed to have exactly the correct size. If the system 00165 does not provide a suitable type, the typedef will evaluate to 00166 <tt>Int_type_not_supported_on_this_platform</tt>. 00167 */ 00168 //@{ 00169 00170 /// 8-bit signed int 00171 typedef detail::SelectIntegerType<8, detail::SignedIntTypes>::type Int8; 00172 /// 16-bit signed int 00173 typedef detail::SelectIntegerType<16, detail::SignedIntTypes>::type Int16; 00174 /// 32-bit signed int 00175 typedef detail::SelectIntegerType<32, detail::SignedIntTypes>::type Int32; 00176 /// 64-bit signed int 00177 typedef detail::SelectIntegerType<64, detail::SignedIntTypes>::type Int64; 00178 /// 8-bit unsigned int 00179 typedef detail::SelectIntegerType<8, detail::UnsignedIntTypes>::type UInt8; 00180 /// 16-bit unsigned int 00181 typedef detail::SelectIntegerType<16, detail::UnsignedIntTypes>::type UInt16; 00182 /// 32-bit unsigned int 00183 typedef detail::SelectIntegerType<32, detail::UnsignedIntTypes>::type UInt32; 00184 /// 64-bit unsigned int 00185 typedef detail::SelectIntegerType<64, detail::UnsignedIntTypes>::type UInt64; 00186 00187 /// the biggest signed integer type of the system 00188 typedef detail::SelectBiggestIntegerType<detail::SignedIntTypes>::type IntBiggest; 00189 /// the biggest unsigned integer type of the system 00190 typedef detail::SelectBiggestIntegerType<detail::UnsignedIntTypes>::type UIntBiggest; 00191 00192 //@} 00193 00194 #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION 00195 00196 typedef signed char Int8; 00197 typedef signed short Int16; 00198 typedef signed int Int32; 00199 typedef Int_type_not_supported_on_this_platform Int64; 00200 typedef unsigned char UInt8; 00201 typedef unsigned short UInt16; 00202 typedef unsigned int UInt32; 00203 typedef Int_type_not_supported_on_this_platform UInt64; 00204 00205 typedef Int32 IntBiggest; 00206 typedef UInt32 UIntBiggest; 00207 00208 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION 00209 00210 } // namespace vigra 00211 00212 #endif /* VIGRA_SIZED_INT_HXX */
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|