Integers.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_Integers_hxx
00024 #define __ccxx_Integers_hxx
00025
00026 #include <commonc++/Common.h++>
00027
00028 #ifdef CCXX_OS_WINDOWS
00029 #include <windows.h>
00030 #ifndef CCXX_OS_WINDOWS_GNU
00031
00032 typedef INT8 int8_t;
00033 typedef UINT8 uint8_t;
00034 typedef INT16 int16_t;
00035 typedef UINT16 uint16_t;
00036 typedef INT32 int32_t;
00037 typedef UINT32 uint32_t;
00038 typedef INT64 int64_t;
00039 typedef UINT64 uint64_t;
00040 #else // CCXX_OS_WINDOWS_GNU
00041 #include <stdint.h>
00042 #endif // ! CCXX_OS_WINDOWS_GNU
00043 #else // ! CCXX_OS_WINDOWS
00044 #include <inttypes.h>
00045 #include <stdint.h>
00046 #endif // CCXX_OS_WINDOWS
00047
00048 #ifdef min
00049 #undef min
00050 #endif
00051
00052 #ifdef max
00053 #undef max
00054 #endif
00055
00056 namespace ccxx {
00057
00058 typedef unsigned char byte_t;
00059
00060 typedef unsigned int uint_t;
00061
00062 #ifdef CCXX_OS_WINDOWS
00063 typedef int64_t off64_t;
00064 #endif
00065
00070 typedef int32_t time_s_t;
00071
00075 typedef int timespan_s_t;
00076
00081 typedef int64_t time_ms_t;
00082
00086 typedef int timespan_ms_t;
00087
00088 };
00089
00097 #if defined (CCXX_OS_WINDOWS) && ! defined (CCXX_OS_WINDOWS_GNU)
00098
00099 #define INT64_CONST(I) (I ## i64)
00100 #define UINT64_CONST(I) (I ## Ui64)
00101
00102 #else
00103
00104 #define INT64_CONST(I) (I ## LL)
00105 #define UINT64_CONST(I) (I ## ULL)
00106
00107 #endif
00108
00136 #ifndef INT8_MIN
00137 #define INT8_MIN (-128)
00138 #endif
00139
00140 #ifndef INT16_MIN
00141 #define INT16_MIN (-32767-1)
00142 #endif
00143
00144 #ifndef INT32_MIN
00145 #define INT32_MIN (-2147483647-1)
00146 #endif
00147
00148 #ifndef INT64_MIN
00149 #define INT64_MIN (INT64_CONST(-9223372036854775807)-1)
00150 #endif
00151
00152 #ifndef INT8_MAX
00153 #define INT8_MAX (127)
00154 #endif
00155
00156 #ifndef INT16_MAX
00157 #define INT16_MAX (32767)
00158 #endif
00159
00160 #ifndef INT32_MAX
00161 #define INT32_MAX (2147483647)
00162 #endif
00163
00164 #ifndef INT64_MAX
00165 #define INT64_MAX (INT64_CONST(9223372036854775807))
00166 #endif
00167
00168 #ifndef UINT8_MAX
00169 #define UINT8_MAX (255U)
00170 #endif
00171
00172 #ifndef UINT16_MAX
00173 #define UINT16_MAX (65535U)
00174 #endif
00175
00176 #ifndef UINT32_MAX
00177 #define UINT32_MAX (4294967295U)
00178 #endif
00179
00180 #ifndef UINT64_MAX
00181 #define UINT64_MAX (UINT64_CONST(18446744073709551615))
00182 #endif
00183
00210 #if defined(CCXX_OS_WINDOWS) || defined (CCXX_OS_WINDOWS_GNU)
00211
00212 #define INT64_FMT "%I64d"
00213 #define UINT64_FMT "%I64u"
00214
00215
00216 #define INT64_P_FMT(W) "%" #W "I64d"
00217 #define UINT64_P_FMT(W) "%" #W "I64u"
00218
00219 #define INT64_WIDE_FMT L"%I64d"
00220 #define UINT64_WIDE_FMT L"%I64u"
00221
00222
00223
00224 #ifdef __GNUC__
00225
00226 #define INT64_WIDE_P_FMT(W) L"%" #W "I64d"
00227 #define UINT64_WIDE_P_FMT(W) L"%" #W "I64u"
00228
00229 #else
00230
00231 #define INT64_WIDE_P_FMT(W) L"%" L#W L"I64d"
00232 #define UINT64_WIDE_P_FMT(W) L"%" L#W L"I64u"
00233
00234 #endif // __GNUC__
00235
00236 #else
00237
00238 #define INT64_FMT "%lld"
00239 #define UINT64_FMT "%llu"
00240
00241
00242 #define INT64_P_FMT(W) "%" #W "lld"
00243 #define UINT64_P_FMT(W) "%" #W "llu"
00244
00245 #define INT64_WIDE_FMT L"%lld"
00246 #define UINT64_WIDE_FMT L"%llu"
00247
00248
00249
00250 #ifdef __GNUC__
00251
00252 #define INT64_WIDE_P_FMT(W) L"%" #W "lld"
00253 #define UINT64_WIDE_P_FMT(W) L"%" #W "llu"
00254
00255 #else
00256
00257 #define INT64_WIDE_P_FMT(W) L"%" L#W L"lld"
00258 #define UINT64_WIDE_P_FMT(W) L"%" L#W L"llu"
00259
00260 #endif // __GNUC__
00261
00262 #endif
00263
00270 #define CCXX_BIT_SET(N, BIT) \
00271 ((N) |= (1 << (BIT)))
00272
00279 #define CCXX_BIT_CLEAR(N, BIT) \
00280 (((N) &= ~(1 << (BIT))))
00281
00288 #define CCXX_BIT_READ(N, BIT) \
00289 ((((N) & (1 << (BIT))) == 0) ? 0 : 1)
00290
00298 #define CCXX_BIT_WRITE(N, BIT, VALUE) \
00299 ((VALUE) ? CCXX_BIT_SET((N), (BIT)) : CCXX_BIT_CLEAR((N), (BIT)))
00300
00308 #define CCXX_BIT_TEST(N, BIT) \
00309 (((N) & (1 << (BIT))) != 0)
00310
00311 #endif // __ccxx_Integers_hxx
00312
00313