• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

limits.hh

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_VALUE_INTERNAL_LIMITS_HH
00027 # define MLN_VALUE_INTERNAL_LIMITS_HH
00028 
00032 
00033 # if defined(__GNUC__) && __GNUC__ < 3
00034 #  include <cfloat>
00035 #  include <climits>
00036 # else
00037 #  include <limits>
00038 # endif
00039 
00040 namespace mln
00041 {
00042 
00043   namespace value
00044   {
00045 
00046     namespace internal
00047     {
00048 
00049       template<typename T>
00050       struct limits
00051 # if !defined(__GNUC__) || __GNUC__ >= 3
00052         : std::numeric_limits<T>
00053       { };
00054 # else
00055       {
00056         static const bool is_specialized = false;
00057       };
00058 
00059       template<>
00060       struct limits<bool>
00061       {
00062         static bool min() throw() { return false; }
00063         static bool max() throw() { return false; }
00064         static bool epsilon() throw()
00065         { return false; }
00066       };
00067 
00068       template<>
00069       struct limits<char>
00070       {
00071         static char min() throw() { return CHAR_MIN; }
00072         static char max() throw() { return CHAR_MAX; }
00073         static char epsilon() throw()
00074         { return 0; }
00075       };
00076 
00077       template<>
00078       struct limits<signed char>
00079       {
00080         static signed char min() throw() { return SCHAR_MIN; }
00081         static signed char max() throw() { return SCHAR_MAX; }
00082         static signed char epsilon() throw()
00083         { return 0; }
00084       };
00085 
00086       template<>
00087       struct limits<unsigned char>
00088       {
00089         static unsigned char min() throw() { return 0; }
00090         static unsigned char max() throw() { return UCHAR_MAX; }
00091         static unsigned char epsilon() throw()
00092         { return 0; }
00093       };
00094 
00095       template<>
00096       struct limits<short>
00097       {
00098         static short min() throw() { return SHRT_MIN; }
00099         static short max() throw() { return SHRT_MAX; }
00100         static short epsilon() throw()
00101         { return 0; }
00102       };
00103 
00104       template<>
00105       struct limits<unsigned short>
00106       {
00107         static unsigned short min() throw() { return 0; }
00108         static unsigned short max() throw() { return USHRT_MAX; }
00109         static unsigned short epsilon() throw()
00110         { return 0; }
00111       };
00112 
00113       template<>
00114       struct limits<int>
00115       {
00116         static int min() throw() { return INT_MIN; }
00117         static int max() throw() { return INT_MAX; }
00118         static int epsilon() throw()
00119         { return 0; }
00120       };
00121 
00122       template<>
00123       struct limits<unsigned int>
00124       {
00125         static unsigned int min() throw() { return 0; }
00126         static unsigned int max() throw() { return UINT_MAX; }
00127         static unsigned int epsilon() throw()
00128         { return 0; }
00129       };
00130 
00131       template<>
00132       struct limits<long>
00133       {
00134         static long min() throw() { return LONG_MIN; }
00135         static long max() throw() { return LONG_MAX; }
00136         static long epsilon() throw()
00137         { return 0; }
00138       };
00139 
00140       template<>
00141       struct limits<unsigned long>
00142       {
00143         static unsigned long min() throw() { return 0; }
00144         static unsigned long max() throw() { return ULONG_MAX; }
00145         static unsigned long epsilon() throw()
00146         { return 0; }
00147       };
00148 
00149 
00150 /*
00151 **   Some pre-ANSI-C99 systems like Linux/GCC 2.95 define
00152 **     ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
00153 */
00154 
00155 #  if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
00156 #   define LONGLONG_MIN((long long) 0x8000000000000000LL)
00157 #   define LONGLONG_MAX((long long) 0x7FFFFFFFFFFFFFFFLL)
00158 #  endif
00159 
00160 
00161 #  if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
00162       /* First check for ANSI C99 definition: */
00163 #   ifdef ULLONG_MAX
00164 #    define ULONGLONG_MAX  ULLONG_MAX
00165 #   else
00166 #    define ULONGLONG_MAX ((unsigned long long)(~0ULL))
00167 #   endif
00168 
00169 #  endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
00170 
00171 
00172 #  if defined(HAVE_LONG_LONG)
00173       template<>
00174       struct limits<long long>
00175       {
00176         static long long min() throw() { return LONGLONG_MIN; }
00177         static long long max() throw() { return LONGLONG_MAX; }
00178         static long long epsilon() throw()
00179         { return 0; }
00180       };
00181 
00182       template<>
00183       struct limits<unsigned long long>
00184       {
00185         static unsigned long long min() throw() { return 0; }
00186         static unsigned long long max() throw() { return ULONGLONG_MAX; }
00187         static unsigned long long epsilon() throw()
00188         { return 0; }
00189       };
00190 #  endif
00191 
00192       template<>
00193       struct limits<float>
00194       {
00195         static float min() throw()   { return FLT_MIN; }
00196         static float max() throw() { return FLT_MAX; }
00197         static float epsilon() throw()
00198         { return FLT_EPSILON; }
00199       };
00200 
00201       template<>
00202       struct limits<double>
00203       {
00204         static float min() throw()   { return DBL_MIN; }
00205         static float max() throw() { return DBL_MAX; }
00206         static float epsilon() throw()
00207         { return DBL_EPSILON; }
00208       };
00209 
00210 # endif
00211     } // end of namespace mln::value::internal
00212 
00213   } // end of namespace mln::value
00214 
00215 } // end of namespace mln
00216 
00217 #endif // ! MLN_VALUE_INTERNAL_LIMITS_HH

Generated on Tue Oct 4 2011 15:24:01 for Milena (Olena) by  doxygen 1.7.1