VIGRA - vigra/sized_int.hxx Source File

[ 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.5.0, Dec 07 2006 )                                    */
    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         IntTypeList<signed long long,
    00101         Int_type_not_supported_on_this_platform > > > > > SignedIntTypes;
    00102 typedef IntTypeList<unsigned char,
    00103         IntTypeList<unsigned short,
    00104         IntTypeList<unsigned int,
    00105         IntTypeList<unsigned long,
    00106         IntTypeList<unsigned long long,
    00107         Int_type_not_supported_on_this_platform > > > > > UnsignedIntTypes;
    00108
    00109 } // namespace detail
    00110
    00111 /** \addtogroup FixedSizeInt Fixed Size Integer Types
    00112
    00113     Since the C++ standard does only specify minimal sizes for the built-in
    00114     integer types, one cannot rely on them to have a specific size. But
    00115     pixel types with a specific size are often required in image processing,
    00116     especially when reading or writing binary files. The VIGRA typedefs
    00117     are guaranteed to have exactly the correct size. If the system
    00118     does not provide a suitable type, the typedef will evaluate to
    00119     <tt>Int_type_not_supported_on_this_platform</tt>.
    00120 */
    00121 //@{
    00122
    00123     /// 8-bit signed int
    00124 typedef detail::SelectIntegerType<8,  detail::SignedIntTypes>::type Int8;
    00125     /// 16-bit signed int
    00126 typedef detail::SelectIntegerType<16, detail::SignedIntTypes>::type Int16;
    00127     /// 32-bit signed int
    00128 typedef detail::SelectIntegerType<32, detail::SignedIntTypes>::type Int32;
    00129     /// 64-bit signed int
    00130 typedef detail::SelectIntegerType<64, detail::SignedIntTypes>::type Int64;
    00131     /// 8-bit unsigned int
    00132 typedef detail::SelectIntegerType<8,  detail::UnsignedIntTypes>::type UInt8;
    00133     /// 16-bit unsigned int
    00134 typedef detail::SelectIntegerType<16, detail::UnsignedIntTypes>::type UInt16;
    00135     /// 32-bit unsigned int
    00136 typedef detail::SelectIntegerType<32, detail::UnsignedIntTypes>::type UInt32;
    00137     /// 64-bit unsigned int
    00138 typedef detail::SelectIntegerType<64, detail::UnsignedIntTypes>::type UInt64;
    00139
    00140     /// the biggest signed integer type of the system
    00141 typedef detail::SelectBiggestIntegerType<detail::SignedIntTypes>::type   IntBiggest;
    00142     /// the biggest unsigned integer type of the system
    00143 typedef detail::SelectBiggestIntegerType<detail::UnsignedIntTypes>::type UIntBiggest;
    00144
    00145 //@}
    00146
    00147 #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION
    00148
    00149 typedef signed char    Int8;
    00150 typedef signed short   Int16;
    00151 typedef signed int     Int32;
    00152 typedef Int_type_not_supported_on_this_platform Int64;
    00153 typedef unsigned char  UInt8;
    00154 typedef unsigned short UInt16;
    00155 typedef unsigned int   UInt32;
    00156 typedef Int_type_not_supported_on_this_platform UInt64;
    00157
    00158 typedef Int32  IntBiggest;
    00159 typedef UInt32 UIntBiggest;
    00160
    00161 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION
    00162
    00163 } // namespace vigra
    00164
    00165 #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.5.0 (7 Dec 2006)