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

| vigra/sized_int.hxx |
--- | --- | ---

    00001 /************************************************************************/
    00002 /*                                                                      */
    00003 /*               Copyright 1998-2002 by Ullrich Koethe                  */
    00004 /*       Cognitive Systems Group, University of Hamburg, Germany        */
    00005 /*                                                                      */
    00006 /*    This file is part of the VIGRA computer vision library.           */
    00007 /*    ( Version 1.4.0, Dec 21 2005 )                                    */
    00008 /*    The VIGRA Website is                                              */
    00009 /*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
    00010 /*    Please direct questions, bug reports, and contributions to        */
    00011 /*        koethe@informatik.uni-hamburg.de          or                  */
    00012 /*        vigra@kogs1.informatik.uni-hamburg.de                         */
    00013 /*                                                                      */
    00014 /*    Permission is hereby granted, free of charge, to any person       */
    00015 /*    obtaining a copy of this software and associated documentation    */
    00016 /*    files (the "Software"), to deal in the Software without           */
    00017 /*    restriction, including without limitation the rights to use,      */
    00018 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00019 /*    sell copies of the Software, and to permit persons to whom the    */
    00020 /*    Software is furnished to do so, subject to the following          */
    00021 /*    conditions:                                                       */
    00022 /*                                                                      */
    00023 /*    The above copyright notice and this permission notice shall be    */
    00024 /*    included in all copies or substantial portions of the             */
    00025 /*    Software.                                                         */
    00026 /*                                                                      */
    00027 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00028 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00029 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00030 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00031 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00032 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00033 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00034 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00035 /*                                                                      */
    00036 /************************************************************************/
    00037
    00038
    00039 #ifndef VIGRA_SIZED_INT_HXX
    00040 #define VIGRA_SIZED_INT_HXX
    00041
    00042 #include "metaprogramming.hxx"
    00043
    00044 namespace vigra {
    00045
    00046 class Int_type_not_supported_on_this_platform {};
    00047
    00048 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION
    00049
    00050 namespace detail {
    00051
    00052 template<class T, class NEXT>
    00053 struct IntTypeList
    00054 {
    00055     enum { size = sizeof(T)*8 };
    00056     typedef T type;
    00057     typedef NEXT next;
    00058 };
    00059
    00060 template<int SIZE, class LIST>
    00061 struct SelectIntegerType
    00062 {
    00063     typedef typename
    00064        IfBool<(SIZE == LIST::size),
    00065            typename LIST::type,
    00066            typename SelectIntegerType<SIZE, typename LIST::next>::type >::type
    00067        type;
    00068 };
    00069
    00070 template<int SIZE>
    00071 struct SelectIntegerType<SIZE, Int_type_not_supported_on_this_platform>
    00072 {
    00073     typedef Int_type_not_supported_on_this_platform type;
    00074 };
    00075
    00076 template<class LIST>
    00077 struct SelectBiggestIntegerType
    00078 {
    00079     enum { cursize = LIST::size,
    00080            nextsize = SelectBiggestIntegerType<typename LIST::next>::size,
    00081            size = (cursize < nextsize) ? nextsize : cursize };
    00082     typedef typename
    00083        IfBool<(cursize < nextsize),
    00084            typename SelectBiggestIntegerType<typename LIST::next>::type,
    00085            typename LIST::type>::type
    00086        type;
    00087 };
    00088
    00089 template<>
    00090 struct SelectBiggestIntegerType<Int_type_not_supported_on_this_platform>
    00091 {
    00092     enum { size = 0 };
    00093     typedef Int_type_not_supported_on_this_platform type;
    00094 };
    00095
    00096 typedef IntTypeList<signed char,
    00097         IntTypeList<signed short,
    00098         IntTypeList<signed int,
    00099         IntTypeList<signed long,
    00100         Int_type_not_supported_on_this_platform > > > > SignedIntTypes;
    00101 typedef IntTypeList<unsigned char,
    00102         IntTypeList<unsigned short,
    00103         IntTypeList<unsigned int,
    00104         IntTypeList<unsigned long,
    00105         Int_type_not_supported_on_this_platform > > > > UnsignedIntTypes;
    00106
    00107 } // namespace detail
    00108
    00109 /** \addtogroup FixedSizeInt Fixed Size Integer Types
    00110
    00111     Since the C++ standard does only specifiy minimal sizes for the built-in
    00112     integer types, one cannot rely on them have a specific size. But
    00113     pixel types with a specific size are often required in image processing,
    00114     especially when reading or writing binary files. The VIGRA typedefs
    00115     are guaranteed to have exactly the correct size. If the system
    00116     does not provide a suitable type, the typedef will evaluate to
    00117     <tt>Int_type_not_supported_on_this_platform</tt>.
    00118 */
    00119 //@{
    00120
    00121     /// 8-bit signed int
    00122 typedef detail::SelectIntegerType<8,  detail::SignedIntTypes>::type Int8;
    00123     /// 16-bit signed int
    00124 typedef detail::SelectIntegerType<16, detail::SignedIntTypes>::type Int16;
    00125     /// 32-bit signed int
    00126 typedef detail::SelectIntegerType<32, detail::SignedIntTypes>::type Int32;
    00127     /// 64-bit signed int
    00128 typedef detail::SelectIntegerType<64, detail::SignedIntTypes>::type Int64;
    00129     /// 8-bit unsigned int
    00130 typedef detail::SelectIntegerType<8,  detail::UnsignedIntTypes>::type UInt8;
    00131     /// 16-bit unsigned int
    00132 typedef detail::SelectIntegerType<16, detail::UnsignedIntTypes>::type UInt16;
    00133     /// 32-bit unsigned int
    00134 typedef detail::SelectIntegerType<32, detail::UnsignedIntTypes>::type UInt32;
    00135     /// 64-bit unsigned int
    00136 typedef detail::SelectIntegerType<64, detail::UnsignedIntTypes>::type UInt64;
    00137
    00138     /// the biggest signed integer type of the system
    00139 typedef detail::SelectBiggestIntegerType<detail::SignedIntTypes>::type   IntBiggest;
    00140     /// the biggest unsigned integer type of the system
    00141 typedef detail::SelectBiggestIntegerType<detail::UnsignedIntTypes>::type UIntBiggest;
    00142
    00143 //@}
    00144
    00145 #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION
    00146
    00147 typedef signed char    Int8;
    00148 typedef signed short   Int16;
    00149 typedef signed int     Int32;
    00150 typedef Int_type_not_supported_on_this_platform Int64;
    00151 typedef unsigned char  UInt8;
    00152 typedef unsigned short UInt16;
    00153 typedef unsigned int   UInt32;
    00154 typedef Int_type_not_supported_on_this_platform UInt64;
    00155
    00156 typedef Int32  IntBiggest;
    00157 typedef UInt32 UIntBiggest;
    00158
    00159 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION
    00160
    00161 } // namespace vigra
    00162
    00163 #endif /* VIGRA_SIZED_INT_HXX */

© Ullrich Köthe (koethe@informatik.uni-hamburg.de) Cognitive Systems Group, University of Hamburg, Germany | html generated using doxygen and Python VIGRA 1.4.0 (21 Dec 2005)