Numeric_Limits.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file    Numeric_Limits.h
00006  *
00007  * $Id: Numeric_Limits.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  * Traits containing basic integer limits.  Useful for template-based
00010  * code on platforms that lack @c std::numeric_limits<>.
00011  *
00012  * @note These traits are not meant to be a replacement for
00013  *       @c std::numeric_limits<>.  Rather they are a crutch until all
00014  *       ACE-supported platforms also support
00015  *       @c std::numeric_limits<>.
00016  *
00017  * @internal   Only meant for internal use by ACE.
00018  * @deprecated This header will be removed once all platforms
00019  *             supported by ACE support @c std::numeric_limits<>.
00020  *
00021  * @author  Ossama Othman <ossama_othman at symantec dot com>
00022  */
00023 //=============================================================================
00024 
00025 #ifndef ACE_NUMERIC_LIMITS_H
00026 #define ACE_NUMERIC_LIMITS_H
00027 
00028 #include /**/ "ace/pre.h"
00029 
00030 #include /**/ "ace/ACE_export.h"
00031 
00032 # if !defined (ACE_LACKS_PRAGMA_ONCE)
00033 #   pragma once
00034 # endif /* ACE_LACKS_PRAGMA_ONCE */
00035 
00036 #ifdef ACE_LACKS_NUMERIC_LIMITS
00037 # include "ace/Basic_Types.h"
00038 #else
00039 
00040 # ifdef __MINGW32__
00041 // Windows defines min/max macros that interfere with the
00042 // numeric_limits::min/max() traits.  Undefine those macros before
00043 // including <limits>.
00044 //
00045 // Ideally, we could prevent those macros from being defined by
00046 // defining the Windows-specific NOMINMAX symbol before any Windows
00047 // headers are included, preferrably on the command line.  However,
00048 // that would probably break some applications.
00049 //
00050 // @@ Why isn't this a problem with MSVC++ and Borland builds?
00051 #  undef min
00052 #  undef max
00053 # endif  /* __MINGW32__ */
00054 
00055 # if defined (ACE_LACKS_LONGLONG_T) || defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00056 // For ACE_U_LongLong.
00057 #  include "ace/Basic_Types.h"
00058 # endif  /* ACE_LACKS_LONGLONG_T || ACE_LACKS_UNSIGNEDLONGLONG_T */
00059 
00060 # include <limits>
00061 #endif /* ACE_LACKS_NUMERIC_LIMITS */
00062 
00063 // Address global namespace pollution potentially incurred by some
00064 // platforms.
00065 #undef min
00066 #undef max
00067 
00068 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00069 
00070 #ifdef ACE_LACKS_NUMERIC_LIMITS
00071 
00072 template <typename T> struct ACE_Numeric_Limits;
00073 
00074 
00075 // ------------------------------------------
00076 // Special cases.
00077 template<>
00078 struct ACE_Export ACE_Numeric_Limits<char>
00079 {
00080   static char min (void) { return CHAR_MIN; }
00081   static char max (void) { return CHAR_MAX; }
00082 };
00083 
00084 // ------------------------------------------
00085 // Signed integers.
00086 
00087 template<>
00088 struct ACE_Export ACE_Numeric_Limits<signed char>
00089 {
00090   static signed char min (void) { return SCHAR_MIN; }
00091   static signed char max (void) { return SCHAR_MAX; }
00092 };
00093 
00094 template<>
00095 struct ACE_Export ACE_Numeric_Limits<signed short>
00096 {
00097   static signed short min (void) { return SHRT_MIN; }
00098   static signed short max (void) { return SHRT_MAX; }
00099 };
00100 
00101 template<>
00102 struct ACE_Export ACE_Numeric_Limits<signed int>
00103 {
00104   static signed int min (void) { return INT_MIN; }
00105   static signed int max (void) { return INT_MAX; }
00106 };
00107 
00108 template<>
00109 struct ACE_Export ACE_Numeric_Limits<signed long>
00110 {
00111   static signed long min (void) { return LONG_MIN; }
00112   static signed long max (void) { return LONG_MAX; }
00113 };
00114 
00115 // #ifndef ACE_LACKS_LONGLONG_T
00116 // template<>
00117 // struct ACE_Export ACE_Numeric_Limits<signed long long>
00118 // {
00119 // #if defined (LLONG_MIN)
00120 // #  define ACE_LLONG_MIN LLONG_MIN
00121 // #elif defined (LONG_LONG_MIN)
00122 // #  define ACE_LLONG_MIN LONG_LONG_MIN
00123 // #elif defined (LONGLONG_MIN)
00124 // #  define ACE_LLONG_MIN LONGLONG_MIN
00125 // #else
00126 // #  error Unable to determine minimum signed long long value.
00127 // #endif  /* LLONG_MIN */
00128 
00129 // #if defined (LLONG_MAX)
00130 // #  define ACE_LLONG_MAX LLONG_MAX
00131 // #elif defined (LONG_LONG_MAX)
00132 // #  define ACE_LLONG_MAX LONG_LONG_MAX
00133 // #elif defined (LONGLONG_MAX)
00134 // #  define ACE_LLONG_MAX LONGLONG_MAX
00135 // #else
00136 // #  error Unable to determine maximum signed long long value.
00137 // #endif  /* LLONG_MAX */
00138 
00139 //   static signed long long min (void) { return ACE_LLONG_MIN; }
00140 //   static signed long long max (void) { return ACE_LLONG_MAX; }
00141 // };
00142 // #endif  /* !ACE_LACKS_LONGLONG_T */
00143 
00144 // ------------------------------------------
00145 // Unsigned integers
00146 template<>
00147 struct ACE_Export ACE_Numeric_Limits<unsigned char>
00148 {
00149   static unsigned char min (void) { return 0; }
00150   static unsigned char max (void) { return UCHAR_MAX; }
00151 };
00152 
00153 template<>
00154 struct ACE_Export ACE_Numeric_Limits<unsigned short>
00155 {
00156   static unsigned short min (void) { return 0; }
00157   static unsigned short max (void) { return USHRT_MAX; }
00158 };
00159 
00160 template<>
00161 struct ACE_Export ACE_Numeric_Limits<unsigned int>
00162 {
00163   static unsigned int min (void) { return 0; }
00164   static unsigned int max (void) { return UINT_MAX; }
00165 };
00166 
00167 template<>
00168 struct ACE_Export ACE_Numeric_Limits<unsigned long>
00169 {
00170   static unsigned long min (void) { return 0; }
00171   static unsigned long max (void) { return ULONG_MAX; }
00172 };
00173 
00174 // #ifndef ACE_LACKS_LONGLONG_T
00175 // template<>
00176 // struct ACE_Export ACE_Numeric_Limits<unsigned long long>
00177 // {
00178 //   static unsigned long long min (void) { return 0; }
00179 //   static unsigned long long max (void)
00180 //   {
00181 // # if defined (ULLONG_MAX)
00182 //     return ULLONG_MAX;
00183 // # elif defined (ULONGLONG_MAX)
00184 //     return ULONGLONG_MAX;
00185 // # else
00186 // #  error Unable to determine maximum unsigned long long value.
00187 // # endif  /* ULLONG_MAX */
00188 //   }
00189 // };
00190 // #endif  /* !ACE_LACKS_LONGLONG_T */
00191 
00192 // ------------------------------------------
00193 // Floating point types
00194 
00195 template<>
00196 struct ACE_Export ACE_Numeric_Limits<float>
00197 {
00198   static float min (void) { return FLT_MIN; }
00199   static float max (void) { return FLT_MAX; }
00200 };
00201 
00202 template<>
00203 struct ACE_Export ACE_Numeric_Limits<double>
00204 {
00205   static double min (void) { return DBL_MIN; }
00206   static double max (void) { return DBL_MAX; }
00207 };
00208 
00209 template<>
00210 struct ACE_Export ACE_Numeric_Limits<long double>
00211 {
00212   static long double min (void) { return LDBL_MIN; }
00213   static long double max (void) { return LDBL_MAX; }
00214 };
00215 
00216 #else
00217 
00218 // std::numeric_limits<> has all of the necessary specializations.
00219 // Just wrap it.
00220 
00221 template <typename T>
00222 struct ACE_Numeric_Limits
00223 {
00224   static T min (void) { return std::numeric_limits<T>::min (); }
00225   static T max (void) { return std::numeric_limits<T>::max (); }
00226 };
00227 
00228 # if (defined (ACE_WIN64) && defined (_MSC_VER) && _MSC_VER <= 1310) \
00229     || defined (ACE_LACKS_NUMERIC_LIMITS_64_BIT_TYPES)
00230 // The Microsoft Platform SDK does not provide std::numeric_limits<>
00231 // specializations for 64 bit integers so we need to explicitly provide
00232 // ACE_Numeric_Limits<> specializations to compensate for this
00233 // deficiency.
00234 //
00235 // Unfortunately there is no way to tell if the platform SDK is being
00236 // used so we specialize for the ACE_WIN64 + MSVC++ 7.1 case, which is
00237 // the configuration that exhibits this problem.  It also happens to
00238 // be a fairly isolated configuration since 64-bit support in MSVC++
00239 // 7.1 was not very good to begin with.
00240 template<>
00241 struct ACE_Numeric_Limits<LONGLONG>
00242 {
00243   static LONGLONG min (void) { return _I64_MIN; }
00244   static LONGLONG max (void) { return _I64_MAX; }
00245 };
00246 
00247 template<>
00248 struct ACE_Numeric_Limits<ULONGLONG>
00249 {
00250   static ULONGLONG min (void) { return 0; }
00251   static ULONGLONG max (void) { return _UI64_MAX; }
00252 };
00253 # endif  /* ACE_WIN64 && _MSC_VER <= 1310 */
00254 
00255 #endif /* ACE_LACKS_NUMERIC_LIMITS */
00256 
00257 #if defined (ACE_LACKS_LONGLONG_T) || defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00258 template<>
00259 struct ACE_Numeric_Limits<ACE_U_LongLong>
00260 {
00261   static ACE_U_LongLong min (void) { return ACE_U_LongLong (); /* 0 */ }
00262   static ACE_U_LongLong max (void) { return ACE_UINT64_MAX; }
00263 };
00264 #endif  /* ACE_LACKS_LONGLONG_T || defined ACE_LACKS_UNSIGNEDLONGLONG_T */
00265 
00266 ACE_END_VERSIONED_NAMESPACE_DECL
00267 
00268 #include /**/ "ace/post.h"
00269 
00270 #endif  /* ACE_NUMERIC_LIMITS_H */

Generated on Tue Feb 2 17:18:41 2010 for ACE by  doxygen 1.4.7