00001 #ifndef CLASSLIB_INT_TRAITS_H
00002 # define CLASSLIB_INT_TRAITS_H
00003
00004
00005
00006 # include "classlib/utils/LongLong.h"
00007 # ifdef _MSC_VER
00008 # define CLASSLIB_BROKEN_TEMPLATE_CONSTANTS 1
00009 # endif
00010
00011 namespace lat {
00012
00013
00014
00015
00016
00017
00018
00021 template <class T> struct IntTraits;
00022
00023 #if !CLASSLIB_BROKEN_TEMPLATE_CONSTANTS
00024 template <>
00025 struct IntTraits<unsigned char>
00026 {
00027 static const unsigned char Min = 0;
00028 static const unsigned char Max = UCHAR_MAX;
00029 };
00030
00031 template <>
00032 struct IntTraits<signed char>
00033 {
00034 static const signed char Min = SCHAR_MIN;
00035 static const signed char Max = SCHAR_MAX;
00036 };
00037
00038 template <>
00039 struct IntTraits<char>
00040 {
00041 static const char Min = CHAR_MIN;
00042 static const char Max = CHAR_MAX;
00043 };
00044
00045 template <>
00046 struct IntTraits<unsigned short>
00047 {
00048 static const unsigned short Min = 0;
00049 static const unsigned short Max = USHRT_MAX;
00050 };
00051
00052 template <>
00053 struct IntTraits<signed short>
00054 {
00055 static const signed short Min = SHRT_MIN;
00056 static const signed short Max = SHRT_MAX;
00057 };
00058
00059 template <>
00060 struct IntTraits<unsigned int>
00061 {
00062 static const unsigned int Min = 0;
00063 static const unsigned int Max = UINT_MAX;
00064 };
00065
00066 template <>
00067 struct IntTraits<signed int>
00068 {
00069 static const signed int Min = INT_MIN;
00070 static const signed int Max = INT_MAX;
00071 };
00072
00073 template <>
00074 struct IntTraits<unsigned long>
00075 {
00076 static const unsigned long Min = 0;
00077 static const unsigned long Max = ULONG_MAX;
00078 };
00079
00080 template <>
00081 struct IntTraits<signed long>
00082 {
00083 static const signed long Min = LONG_MIN;
00084 static const signed long Max = LONG_MAX;
00085 };
00086
00087 # if HAVE_LONG_LONG
00088 template <>
00089 struct IntTraits<unsigned long long>
00090 {
00091 static const unsigned long long Min = 0;
00092 static const unsigned long long Max = ULONG_LONG_MAX;
00093 };
00094
00095 template <>
00096 struct IntTraits<signed long long>
00097 {
00098 static const signed long long Min = LONG_LONG_MIN;
00099 static const signed long long Max = LONG_LONG_MAX;
00100 };
00101 # elif HAVE_INT64
00102 template <>
00103 struct IntTraits<unsigned __int64>
00104 {
00105 static const unsigned __int64 Min = 0;
00106 static const unsigned __int64 Max = ULONG_LONG_MAX;
00107 };
00108
00109 template <>
00110 struct IntTraits<signed __int64>
00111 {
00112 static const signed __int64 Min = LONG_LONG_MIN;
00113 static const signed __int64 Max = LONG_LONG_MAX;
00114 };
00115 # endif
00116
00117 #else // CLASSLIB_BROKEN_TEMPLATE_CONSTANTS
00118 template <>
00119 struct IntTraits<unsigned char>
00120 {
00121 enum { Min = 0 };
00122 enum { Max = UCHAR_MAX };
00123 };
00124
00125 template <>
00126 struct IntTraits<signed char>
00127 {
00128 enum { Min = SCHAR_MIN };
00129 enum { Max = SCHAR_MAX };
00130 };
00131
00132 template <>
00133 struct IntTraits<char>
00134 {
00135 enum { Min = CHAR_MIN };
00136 enum { Max = CHAR_MAX };
00137 };
00138
00139 template <>
00140 struct IntTraits<unsigned short>
00141 {
00142 enum { Min = 0 };
00143 enum { Max = USHRT_MAX };
00144 };
00145
00146 template <>
00147 struct IntTraits<signed short>
00148 {
00149 enum { Min = SHRT_MIN };
00150 enum { Max = SHRT_MAX };
00151 };
00152
00153 template <>
00154 struct IntTraits<unsigned int>
00155 {
00156 enum { Min = 0 };
00157 enum { Max = UINT_MAX };
00158 };
00159
00160 template <>
00161 struct IntTraits<signed int>
00162 {
00163 enum { Min = INT_MIN };
00164 enum { Max = INT_MAX };
00165 };
00166
00167 template <>
00168 struct IntTraits<unsigned long>
00169 {
00170 enum { Min = 0 };
00171 enum { Max = ULONG_MAX };
00172 };
00173
00174 template <>
00175 struct IntTraits<signed long>
00176 {
00177 enum { Min = LONG_MIN };
00178 enum { Max = LONG_MAX };
00179 };
00180
00181 # if 0 && HAVE_LONG_LONG // Disabled: MSVC++ can't do 64-bit enum constants
00182 template <>
00183 struct IntTraits<unsigned long long>
00184 {
00185 enum { Min = 0 };
00186 enum { Max = ULONG_LONG_MAX };
00187 };
00188
00189 template <>
00190 struct IntTraits<signed long long>
00191 {
00192 enum { Min = LONG_LONG_MIN };
00193 enum { Max = LONG_LONG_MAX };
00194 };
00195 # elif 0 && HAVE_INT64 // Disabled: MSVC++ can't do 64-bit enum constants
00196 template <>
00197 struct IntTraits<unsigned __int64>
00198 {
00199 enum { Min = 0 };
00200 enum { Max = ULONG_LONG_MAX };
00201 };
00202
00203 template <>
00204 struct IntTraits<signed __int64>
00205 {
00206 enum { Min = LONG_LONG_MIN };
00207 enum { Max = LONG_LONG_MAX };
00208 };
00209 # endif
00210 # endif // CLASSLIB_BROKEN_TEMPLATE_CONSTANTS
00211
00212
00213
00214
00215 }
00216 #endif // CLASSLIB_INT_TRAITS_H