00001 #ifndef __types_h__
00002 #define __types_h__
00003
00004 #ifdef HAVE_STDLIB_H
00005 #include <stdlib.h>
00006 #endif
00007
00008
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_bool(const T& a_arg)
00260 { return(false); }
00261
00262
00263 template<>
00264 static bool is_bool(const bool& a_arg)
00265 { return(true); }
00266
00267
00268
00269
00270 template<typename T>
00271 static bool is_signed(const T& a_arg)
00272 {
00273 return(
00274 is_signed_char(a_arg)
00275 || is_signed_short(a_arg)
00276 || is_signed_int(a_arg)
00277 || is_signed_long(a_arg)
00278 || is_signed_long_long(a_arg)
00279 || is_float(a_arg)
00280 || is_double(a_arg)
00281 );
00282 }
00283
00284
00285 template<typename T>
00286 static bool is_unsigned(const T& a_arg)
00287 {
00288 return(
00289 is_unsigned_char(a_arg)
00290 || is_unsigned_short(a_arg)
00291 || is_unsigned_int(a_arg)
00292 || is_unsigned_long(a_arg)
00293 || is_unsigned_long_long(a_arg)
00294 );
00295 }
00296
00297
00298
00299 template<typename T>
00300 static char * type_name(const T & a_arg)
00301 { return("unknown"); }
00302
00303 template<>
00304 static char * type_name(const unsigned char & a_arg)
00305 { return("unsigned char"); }
00306
00307 template<>
00308 static char * type_name(const char & a_arg)
00309 { return("char"); }
00310
00311 template<>
00312 static char * type_name(const unsigned short & a_arg)
00313 { return("unsigned short"); }
00314
00315 template<>
00316 static char * type_name(const short & a_arg)
00317 { return("short"); }
00318
00319 template<>
00320 static char * type_name(const unsigned int & a_arg)
00321 { return("unsigned int"); }
00322
00323 template<>
00324 static char * type_name(const int & a_arg)
00325 { return("int"); }
00326
00327 template<>
00328 static char * type_name(const unsigned long & a_arg)
00329 { return("unsigned long"); }
00330
00331 template<>
00332 static char * type_name(const long & a_arg)
00333 { return("long"); }
00334
00335 template<>
00336 static char * type_name(const unsigned long long & a_arg)
00337 { return("unsigned long long"); }
00338
00339 template<>
00340 static char * type_name(const long long & a_arg)
00341 { return("long long"); }
00342
00343 template<>
00344 static char * type_name(const float & a_arg)
00345 { return("float"); }
00346
00347 template<>
00348 static char * type_name(const double & a_arg)
00349 { return("double"); }
00350
00351 template<>
00352 static char * type_name(const bool & a_arg)
00353 { return("bool"); }
00354
00355
00356
00357 #endif