limits.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: limits.h,v 1.19 2005/12/23 17:01:39 amoll Exp $
00005 //
00006 
00007 #ifndef BALL_COMMON_LIMITS_H
00008 #define BALL_COMMON_LIMITS_H
00009 
00010 #ifndef BALL_CONFIG_CONFIG_H
00011 # include <BALL/CONFIG/config.h>
00012 #endif
00013 
00014 #ifndef BALL_COMMON_GLOBAL_H
00015 # include <BALL/COMMON/global.h>
00016 #endif
00017 
00018 #ifdef BALL_HAS_NUMERIC_LIMITS
00019 # include <limits>
00020 #else
00021 # ifdef BALL_HAS_LIMITS_H
00022 #   include <limits.h>
00023 # endif
00024 # ifdef BALL_HAS_VALUES_H
00025 #   include <limits.h>
00026 # endif
00027 #endif
00028 
00029 # ifdef BALL_HAS_FLOAT_H
00030 #   include <float.h>
00031 # endif
00032 
00033 namespace BALL 
00034 {
00035   
00036 
00048   template <typename T>
00049   class BALL_EXPORT Limits
00050   {
00051     public:
00052 
00053 #ifdef BALL_HAS_NUMERIC_LIMITS
00054 
00055 
00059     static T min()  
00060     { 
00061       return std::numeric_limits<T>::min(); 
00062     }
00063 
00067     static T max()  
00068     { 
00069       return std::numeric_limits<T>::max(); 
00070     }
00071 #else
00072     static T min()  
00073     { 
00074       return (T)0; 
00075     }
00076     static T max()  
00077     { 
00078       return (T)0; 
00079     }
00080 #endif
00081   };
00082 
00083 #ifndef BALL_HAS_NUMERIC_LIMITS
00084   
00085   template <> 
00086   class BALL_EXPORT Limits<float>
00087   {
00088     public:
00089       
00090     static float min() 
00091     {
00092       return FLT_MIN;
00093     }
00094 
00095     static float max() 
00096     {
00097       return FLT_MAX;
00098     }
00099   };
00100 
00101   template <> 
00102   class BALL_EXPORT Limits<double>
00103   {
00104     public:
00105       
00106     static double min() 
00107     {
00108       return DBL_MIN;
00109     }
00110 
00111     static double max() 
00112     {
00113       return DBL_MAX;
00114     }
00115   };
00116 
00117   template <> 
00118   class BALL_EXPORT Limits<bool>
00119   {
00120     public:
00121       
00122     static bool min() 
00123     {
00124       return false;
00125     }
00126 
00127     static bool max() 
00128     {
00129       return true;
00130     }
00131   };
00132 
00133   template <> 
00134   class BALL_EXPORT Limits<char>
00135   {
00136     public:
00137       
00138     static char min() 
00139     {
00140       return CHAR_MIN;
00141     }
00142 
00143     static char max() 
00144     {
00145       return CHAR_MAX;
00146     }
00147   };
00148 
00149   template <> 
00150   class BALL_EXPORT Limits<signed char>
00151   {
00152     public:
00153       
00154     static signed char min() 
00155     {
00156       return SCHAR_MIN;
00157     }
00158 
00159     static signed char max() 
00160     {
00161       return SCHAR_MAX;
00162     }
00163   };
00164 
00165   template <> 
00166   class BALL_EXPORT Limits<unsigned char>
00167   {
00168     public:
00169       
00170     static unsigned char min() 
00171     {
00172       return 0;
00173     }
00174 
00175     static unsigned char max() 
00176     {
00177       return UCHAR_MAX;
00178     }
00179   };
00180 
00181   template <> 
00182   class BALL_EXPORT Limits<short>
00183   {
00184     public:
00185       
00186     static short min() 
00187     {
00188       return SHRT_MIN;
00189     }
00190 
00191     static short max() 
00192     {
00193       return SHRT_MAX;
00194     }
00195   };
00196 
00197   template <> 
00198   class BALL_EXPORT Limits<unsigned short>
00199   {
00200     public:
00201       
00202     static unsigned short min() 
00203     {
00204       return 0;
00205     }
00206 
00207     static unsigned short max() 
00208     {
00209       return USHRT_MAX;
00210     }
00211   };
00212 
00213   template <> 
00214   class BALL_EXPORT Limits<int>
00215   {
00216     public:
00217       
00218     static int min() 
00219     {
00220       return INT_MIN;
00221     }
00222 
00223     static int max() 
00224     {
00225       return INT_MAX;
00226     }
00227   };
00228 
00229   template <> 
00230   class BALL_EXPORT Limits<unsigned int>
00231   {
00232     public:
00233       
00234     static unsigned int min() 
00235     {
00236       return 0;
00237     }
00238 
00239     static unsigned int max() 
00240     {
00241       return UINT_MAX;
00242     }
00243   };
00244 
00245   template <> 
00246   class BALL_EXPORT Limits<long>
00247   {
00248     public:
00249       
00250     static long min() 
00251     {
00252       return LONG_MIN;
00253     }
00254 
00255     static long max() 
00256     {
00257       return LONG_MAX;
00258     }
00259   };
00260 
00261   template <> 
00262   class BALL_EXPORT Limits<unsigned long>
00263   {
00264     public:
00265       
00266     static unsigned long min() 
00267     {
00268       return 0;
00269     }
00270 
00271     static unsigned long max() 
00272     {
00273       return ULONG_MAX;
00274     }
00275   };
00276 
00277 #endif // BALL_HAS_NUMERIC_LIMITS
00278 
00279 } // namespace BALL
00280 
00281 #endif // BALL_COMMON_LIMITS_H