Removed ACE_HAS_BSTRING, not used
[ACE_TAO.git] / ACE / ace / Numeric_Limits.h
blob187123f6a1c94b1e3ec29e4cdfcb5650057f9a78
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Numeric_Limits.h
7 * Traits containing basic integer limits. Useful for template-based
8 * code on platforms that lack @c std::numeric_limits<>.
10 * @note These traits are not meant to be a replacement for
11 * @c std::numeric_limits<>. Rather they are a crutch until all
12 * ACE-supported platforms also support
13 * @c std::numeric_limits<>.
15 * @internal Only meant for internal use by ACE.
16 * @deprecated This header will be removed once all platforms
17 * supported by ACE support @c std::numeric_limits<>.
19 * @author Ossama Othman <ossama_othman at symantec dot com>
21 //=============================================================================
23 #ifndef ACE_NUMERIC_LIMITS_H
24 #define ACE_NUMERIC_LIMITS_H
26 #include /**/ "ace/pre.h"
28 #include /**/ "ace/ACE_export.h"
30 # if !defined (ACE_LACKS_PRAGMA_ONCE)
31 # pragma once
32 # endif /* ACE_LACKS_PRAGMA_ONCE */
34 #ifdef ACE_LACKS_NUMERIC_LIMITS
35 # include "ace/Basic_Types.h"
36 #else
38 # if defined __MINGW32__
39 // Windows defines min/max macros that interfere with the
40 // numeric_limits::min/max() traits. Undefine those macros before
41 // including <limits>.
43 // Ideally, we could prevent those macros from being defined by
44 // defining the Windows-specific NOMINMAX symbol before any Windows
45 // headers are included, preferably on the command line. However,
46 // that would probably break some applications.
48 // @@ Why isn't this a problem with MSVC++ and Borland builds?
49 # undef min
50 # undef max
51 # endif /* __MINGW32__ */
53 # include <limits>
54 #endif /* ACE_LACKS_NUMERIC_LIMITS */
56 // Address global namespace pollution potentially incurred by some
57 // platforms.
58 #undef min
59 #undef max
61 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
63 #ifdef ACE_LACKS_NUMERIC_LIMITS
65 template <typename T> struct ACE_Numeric_Limits;
68 // ------------------------------------------
69 // Special cases.
70 template<>
71 struct ACE_Export ACE_Numeric_Limits<char>
73 static char min (void) { return CHAR_MIN; }
74 static char max (void) { return CHAR_MAX; }
77 // ------------------------------------------
78 // Signed integers.
80 template<>
81 struct ACE_Export ACE_Numeric_Limits<signed char>
83 static signed char min (void) { return SCHAR_MIN; }
84 static signed char max (void) { return SCHAR_MAX; }
87 template<>
88 struct ACE_Export ACE_Numeric_Limits<signed short>
90 static signed short min (void) { return SHRT_MIN; }
91 static signed short max (void) { return SHRT_MAX; }
94 template<>
95 struct ACE_Export ACE_Numeric_Limits<signed int>
97 static signed int min (void) { return INT_MIN; }
98 static signed int max (void) { return INT_MAX; }
101 template<>
102 struct ACE_Export ACE_Numeric_Limits<signed long>
104 static signed long min (void) { return LONG_MIN; }
105 static signed long max (void) { return LONG_MAX; }
108 template<>
109 struct ACE_Export ACE_Numeric_Limits<signed long long>
111 #if defined (LLONG_MIN)
112 # define ACE_LLONG_MIN LLONG_MIN
113 #elif defined (LONG_LONG_MIN)
114 # define ACE_LLONG_MIN LONG_LONG_MIN
115 #elif defined (LONGLONG_MIN)
116 # define ACE_LLONG_MIN LONGLONG_MIN
117 #else
118 # error Unable to determine minimum signed long long value.
119 #endif /* LLONG_MIN */
121 #if defined (LLONG_MAX)
122 # define ACE_LLONG_MAX LLONG_MAX
123 #elif defined (LONG_LONG_MAX)
124 # define ACE_LLONG_MAX LONG_LONG_MAX
125 #elif defined (LONGLONG_MAX)
126 # define ACE_LLONG_MAX LONGLONG_MAX
127 #else
128 # error Unable to determine maximum signed long long value.
129 #endif /* LLONG_MAX */
131 static signed long long min (void) { return ACE_LLONG_MIN; }
132 static signed long long max (void) { return ACE_LLONG_MAX; }
135 // ------------------------------------------
136 // Unsigned integers
137 template<>
138 struct ACE_Export ACE_Numeric_Limits<unsigned char>
140 static unsigned char min (void) { return 0; }
141 static unsigned char max (void) { return UCHAR_MAX; }
144 template<>
145 struct ACE_Export ACE_Numeric_Limits<unsigned short>
147 static unsigned short min (void) { return 0; }
148 static unsigned short max (void) { return USHRT_MAX; }
151 template<>
152 struct ACE_Export ACE_Numeric_Limits<unsigned int>
154 static unsigned int min (void) { return 0; }
155 static unsigned int max (void) { return UINT_MAX; }
158 template<>
159 struct ACE_Export ACE_Numeric_Limits<unsigned long>
161 static unsigned long min (void) { return 0; }
162 static unsigned long max (void) { return ULONG_MAX; }
165 template<>
166 struct ACE_Export ACE_Numeric_Limits<unsigned long long>
168 static unsigned long long min (void) { return 0; }
169 static unsigned long long max (void)
171 # if defined (ULLONG_MAX)
172 return ULLONG_MAX;
173 # elif defined (ULONGLONG_MAX)
174 return ULONGLONG_MAX;
175 # else
176 # error Unable to determine maximum unsigned long long value.
177 # endif /* ULLONG_MAX */
181 // ------------------------------------------
182 // Floating point types
184 template<>
185 struct ACE_Export ACE_Numeric_Limits<float>
187 static float min (void) { return FLT_MIN; }
188 static float max (void) { return FLT_MAX; }
191 template<>
192 struct ACE_Export ACE_Numeric_Limits<double>
194 static double min (void) { return DBL_MIN; }
195 static double max (void) { return DBL_MAX; }
198 template<>
199 struct ACE_Export ACE_Numeric_Limits<long double>
201 static long double min (void) { return LDBL_MIN; }
202 static long double max (void) { return LDBL_MAX; }
205 #else
207 // std::numeric_limits<> has all of the necessary specializations.
208 // Just wrap it.
210 template <typename T>
211 struct ACE_Numeric_Limits
213 static T min (void) { return std::numeric_limits<T>::min (); }
214 static T max (void) { return std::numeric_limits<T>::max (); }
217 # if (defined (ACE_WIN64) && defined (_MSC_VER) && _MSC_VER <= 1310) \
218 || defined (ACE_LACKS_NUMERIC_LIMITS_64_BIT_TYPES)
219 // The Microsoft Platform SDK does not provide std::numeric_limits<>
220 // specializations for 64 bit integers so we need to explicitly provide
221 // ACE_Numeric_Limits<> specializations to compensate for this
222 // deficiency.
224 // Unfortunately there is no way to tell if the platform SDK is being
225 // used so we specialize for the ACE_WIN64 + MSVC++ 7.1 case, which is
226 // the configuration that exhibits this problem. It also happens to
227 // be a fairly isolated configuration since 64-bit support in MSVC++
228 // 7.1 was not very good to begin with.
229 template<>
230 struct ACE_Numeric_Limits<LONGLONG>
232 static LONGLONG min (void) { return _I64_MIN; }
233 static LONGLONG max (void) { return _I64_MAX; }
236 template<>
237 struct ACE_Numeric_Limits<ULONGLONG>
239 static ULONGLONG min (void) { return 0; }
240 static ULONGLONG max (void) { return _UI64_MAX; }
242 # endif /* ACE_WIN64 && _MSC_VER <= 1310 */
244 #endif /* ACE_LACKS_NUMERIC_LIMITS */
246 ACE_END_VERSIONED_NAMESPACE_DECL
248 #include /**/ "ace/post.h"
250 #endif /* ACE_NUMERIC_LIMITS_H */