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