00001
00002
00003 #ifndef __types_h__
00004 #define __types_h__
00005
00006 #ifdef HAVE_STDLIB_H
00007 #include <stdlib.h>
00008 #endif
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #if SIZEOF_UNSIGNED_CHAR == 1
00020 typedef unsigned char uint8;
00021 #elif SIZEOF_UNSIGNED_SHORT == 1
00022 typedef unsigned short uint8;
00023 #elif SIZEOF_UNSIGNED_INT == 1
00024 typedef unsigned int uint8;
00025 #elif SIZEOF_UNSIGNED_LONG == 1
00026 typedef unsigned long uint8;
00027 #elif SIZEOF_UNSIGNED_LONG_LONG == 1
00028 typedef unsigned long long uint8;
00029 #else
00030 # error *** ERROR: No 8-bit type found to use as uint8
00031 #endif
00032
00033
00034
00035
00036
00037
00038
00039
00040 #if SIZEOF_UNSIGNED_CHAR == 2
00041 typedef unsigned char uint16;
00042 #elif SIZEOF_UNSIGNED_SHORT == 2
00043 typedef unsigned short uint16;
00044 #elif SIZEOF_UNSIGNED_INT == 2
00045 typedef unsigned int uint16;
00046 #elif SIZEOF_UNSIGNED_LONG == 2
00047 typedef unsigned long uint16;
00048 #elif SIZEOF_UNSIGNED_LONG_LONG == 2
00049 typedef unsigned long long uint16;
00050 #else
00051 # error *** ERROR: No 16-bit type found to use as uint16
00052 #endif
00053
00054
00055
00056
00057
00058
00059
00060
00061 #if SIZEOF_UNSIGNED_CHAR == 4
00062 typedef unsigned char uint32;
00063 #elif SIZEOF_UNSIGNED_SHORT == 4
00064 typedef unsigned short uint32;
00065 #elif SIZEOF_UNSIGNED_INT == 4
00066 typedef unsigned int uint32;
00067 #elif SIZEOF_UNSIGNED_LONG == 4
00068 typedef unsigned long uint32;
00069 #elif SIZEOF_UNSIGNED_LONG_LONG == 4
00070 typedef unsigned long long uint32;
00071 #else
00072 # error *** ERROR: No 32-bit type found to use as uint32
00073 #endif
00074
00075
00076
00077
00078
00079
00080
00081
00082 #if SIZEOF_UNSIGNED_CHAR == 8
00083 typedef unsigned char uint64;
00084 #elif SIZEOF_UNSIGNED_SHORT == 8
00085 typedef unsigned short uint64;
00086 #elif SIZEOF_UNSIGNED_INT == 8
00087 typedef unsigned int uint64;
00088 #elif SIZEOF_UNSIGNED_LONG == 8
00089 typedef unsigned long uint64;
00090 #elif SIZEOF_UNSIGNED_LONG_LONG == 8
00091 typedef unsigned long long uint64;
00092 #else
00093 # error *** ERROR: No 64-bit type found to use as uint64
00094 #endif
00095
00096
00097
00098
00099 template<typename T>
00100 static bool is_signed_char(const T& a_arg)
00101 { return(false); }
00102
00103
00104 template<>
00105 static bool is_signed_char(const char& a_arg)
00106 { return(true); }
00107
00108
00109 template<typename T>
00110 static bool is_unsigned_char(const T& a_arg)
00111 { return(false); }
00112
00113
00114 template<>
00115 static bool is_unsigned_char(const unsigned char& a_arg)
00116 { return(true); }
00117
00118
00119 template<typename T>
00120 static bool is_char(const T& a_arg)
00121 { return(is_signed_char(a_arg) || is_unsigned_char(a_arg)); }
00122
00123
00124
00125
00126 template<typename T>
00127 static bool is_signed_short(const T& a_arg)
00128 { return(false); }
00129
00130
00131 template<>
00132 static bool is_signed_short(const short& a_arg)
00133 { return(true); }
00134
00135
00136 template<typename T>
00137 static bool is_unsigned_short(const T& a_arg)
00138 { return(false); }
00139
00140
00141 template<>
00142 static bool is_unsigned_short(const unsigned short& a_arg)
00143 { return(true); }
00144
00145
00146 template<typename T>
00147 static bool is_short(const T& a_arg)
00148 { return(is_signed_short(a_arg) || is_unsigned_short(a_arg)); }
00149
00150
00151
00152
00153 template<typename T>
00154 static bool is_signed_int(const T& a_arg)
00155 { return(false); }
00156
00157
00158 template<>
00159 static bool is_signed_int(const int& a_arg)
00160 { return(true); }
00161
00162
00163 template<typename T>
00164 static bool is_unsigned_int(const T& a_arg)
00165 { return(false); }
00166
00167
00168 template<>
00169 static bool is_unsigned_int(const unsigned int& a_arg)
00170 { return(true); }
00171
00172
00173 template<typename T>
00174 static bool is_int(const T& a_arg)
00175 { return(is_signed_int(a_arg) || is_unsigned_int(a_arg)); }
00176
00177
00178
00179
00180 template<typename T>
00181 static bool is_signed_long(const T& a_arg)
00182 { return(false); }
00183
00184
00185 template<>
00186 static bool is_signed_long(const long& a_arg)
00187 { return(true); }
00188
00189
00190 template<typename T>
00191 static bool is_unsigned_long(const T& a_arg)
00192 { return(false); }
00193
00194
00195 template<>
00196 static bool is_unsigned_long(const unsigned long& a_arg)
00197 { return(true); }
00198
00199
00200 template<typename T>
00201 static bool is_long(const T& a_arg)
00202 { return(is_signed_long(a_arg) || is_unsigned_long(a_arg)); }
00203
00204
00205
00206
00207 template<typename T>
00208 static bool is_signed_long_long(const T& a_arg)
00209 { return(false); }
00210
00211
00212 template<>
00213 static bool is_signed_long_long(const long long& a_arg)
00214 { return(true); }
00215
00216
00217 template<typename T>
00218 static bool is_unsigned_long_long(const T& a_arg)
00219 { return(false); }
00220
00221
00222 template<>
00223 static bool is_unsigned_long_long(const unsigned long long& a_arg)
00224 { return(true); }
00225
00226
00227 template<typename T>
00228 static bool is_long_long(const T& a_arg)
00229 { return(is_signed_long_long(a_arg) || is_unsigned_long_long(a_arg)); }
00230
00231
00232
00233
00234 template<typename T>
00235 static bool is_float(const T& a_arg)
00236 { return(false); }
00237
00238
00239 template<>
00240 static bool is_float(const float& a_arg)
00241 { return(true); }
00242
00243
00244
00245
00246 template<typename T>
00247 static bool is_double(const T& a_arg)
00248 { return(false); }
00249
00250
00251 template<>
00252 static bool is_double(const double& a_arg)
00253 { return(true); }
00254
00255
00256
00257
00258 template<typename T>
00259 static bool is_signed(const T& a_arg)
00260 {
00261 return(
00262 is_signed_char(a_arg)
00263 || is_signed_short(a_arg)
00264 || is_signed_int(a_arg)
00265 || is_signed_long(a_arg)
00266 || is_signed_long_long(a_arg)
00267 || is_float(a_arg)
00268 || is_double(a_arg)
00269 );
00270 }
00271
00272
00273 template<typename T>
00274 static bool is_unsigned(const T& a_arg)
00275 {
00276 return(
00277 is_unsigned_char(a_arg)
00278 || is_unsigned_short(a_arg)
00279 || is_unsigned_int(a_arg)
00280 || is_unsigned_long(a_arg)
00281 || is_unsigned_long_long(a_arg)
00282 );
00283 }
00284
00285
00286 #endif