00001
00002
00003
00004
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 # ifdef BALL_HAS_FLOAT_H
00028 # include <float.h>
00029 # endif
00030 #endif
00031
00032 namespace BALL
00033 {
00034
00035
00047 template <typename T>
00048 class BALL_EXPORT Limits
00049 {
00050 public:
00051
00052 #ifdef BALL_HAVE_NUMERIC_LIMITS
00053
00054
00058 static T min()
00059 {
00060 return std::numeric_limits<T>::min();
00061 }
00062
00066 static T max()
00067 {
00068 return std::numeric_limits<T>::max();
00069 }
00070 #else
00071 static T min()
00072 {
00073 return (T)0;
00074 }
00075 static T max()
00076 {
00077 return (T)0;
00078 }
00079 #endif
00080 };
00081
00082 #ifndef BALL_HAVE_NUMERIC_LIMITS
00083
00084 template <>
00085 class BALL_EXPORT Limits<float>
00086 {
00087 public:
00088
00089 static float min()
00090 {
00091 return FLT_MIN;
00092 }
00093
00094 static float max()
00095 {
00096 return FLT_MAX;
00097 }
00098 };
00099
00100 template <>
00101 class BALL_EXPORT Limits<double>
00102 {
00103 public:
00104
00105 static double min()
00106 {
00107 return DBL_MIN;
00108 }
00109
00110 static double max()
00111 {
00112 return DBL_MAX;
00113 }
00114 };
00115
00116 template <>
00117 class BALL_EXPORT Limits<bool>
00118 {
00119 public:
00120
00121 static bool min()
00122 {
00123 return false;
00124 }
00125
00126 static bool max()
00127 {
00128 return true;
00129 }
00130 };
00131
00132 template <>
00133 class BALL_EXPORT Limits<char>
00134 {
00135 public:
00136
00137 static char min()
00138 {
00139 return CHAR_MIN;
00140 }
00141
00142 static char max()
00143 {
00144 return CHAR_MAX;
00145 }
00146 };
00147
00148 template <>
00149 class BALL_EXPORT Limits<signed char>
00150 {
00151 public:
00152
00153 static signed char min()
00154 {
00155 return SCHAR_MIN;
00156 }
00157
00158 static signed char max()
00159 {
00160 return SCHAR_MAX;
00161 }
00162 };
00163
00164 template <>
00165 class BALL_EXPORT Limits<unsigned char>
00166 {
00167 public:
00168
00169 static unsigned char min()
00170 {
00171 return 0;
00172 }
00173
00174 static unsigned char max()
00175 {
00176 return UCHAR_MAX;
00177 }
00178 };
00179
00180 template <>
00181 class BALL_EXPORT Limits<short>
00182 {
00183 public:
00184
00185 static short min()
00186 {
00187 return SHRT_MIN;
00188 }
00189
00190 static short max()
00191 {
00192 return SHRT_MAX;
00193 }
00194 };
00195
00196 template <>
00197 class BALL_EXPORT Limits<unsigned short>
00198 {
00199 public:
00200
00201 static unsigned short min()
00202 {
00203 return 0;
00204 }
00205
00206 static unsigned short max()
00207 {
00208 return USHRT_MAX;
00209 }
00210 };
00211
00212 template <>
00213 class BALL_EXPORT Limits<int>
00214 {
00215 public:
00216
00217 static int min()
00218 {
00219 return INT_MIN;
00220 }
00221
00222 static int max()
00223 {
00224 return INT_MAX;
00225 }
00226 };
00227
00228 template <>
00229 class BALL_EXPORT Limits<unsigned int>
00230 {
00231 public:
00232
00233 static unsigned int min()
00234 {
00235 return 0;
00236 }
00237
00238 static unsigned int max()
00239 {
00240 return UINT_MAX;
00241 }
00242 };
00243
00244 template <>
00245 class BALL_EXPORT Limits<long>
00246 {
00247 public:
00248
00249 static long min()
00250 {
00251 return LONG_MIN;
00252 }
00253
00254 static long max()
00255 {
00256 return LONG_MAX;
00257 }
00258 };
00259
00260 template <>
00261 class BALL_EXPORT Limits<unsigned long>
00262 {
00263 public:
00264
00265 static unsigned long min()
00266 {
00267 return 0;
00268 }
00269
00270 static unsigned long max()
00271 {
00272 return ULONG_MAX;
00273 }
00274 };
00275
00276 #endif // BALL_HAVE_NUMERIC_LIMITS
00277
00278 }
00279
00280 #endif // BALL_COMMON_LIMITS_H