libcommonc++  0.7
Integers.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Integers_hxx
24 #define __ccxx_Integers_hxx
25 
26 #include <commonc++/Common.h++>
27 
28 #ifdef CCXX_OS_WINDOWS
29 #include <windows.h>
30 #ifndef CCXX_OS_WINDOWS_GNU
31 
32 typedef INT8 int8_t;
33 typedef UINT8 uint8_t;
34 typedef INT16 int16_t;
35 typedef UINT16 uint16_t;
36 typedef INT32 int32_t;
37 typedef UINT32 uint32_t;
38 typedef INT64 int64_t;
39 typedef UINT64 uint64_t;
40 #else // CCXX_OS_WINDOWS_GNU
41 #ifndef __STDC_FORMAT_MACROS
42 #define __STDC_FORMAT_MACROS
43 #endif
44 #include <stdint.h>
45 #endif // ! CCXX_OS_WINDOWS_GNU
46 #else // ! CCXX_OS_WINDOWS
47 #ifndef __STDC_FORMAT_MACROS
48 #define __STDC_FORMAT_MACROS
49 #endif
50 #include <inttypes.h>
51 #include <stdint.h>
52 #endif // CCXX_OS_WINDOWS
53 
54 #ifdef min
55 #undef min
56 #endif
57 
58 #ifdef max
59 #undef max
60 #endif
61 
62 namespace ccxx {
63 
68 typedef unsigned char byte_t;
69 
74 typedef unsigned int uint_t;
75 
76 #ifdef CCXX_OS_WINDOWS
77 typedef int64_t off64_t;
78 #endif
79 
85 typedef int32_t time_s_t;
86 
91 typedef int timespan_s_t;
92 
98 typedef int64_t time_ms_t;
99 
104 typedef int timespan_ms_t;
105 
106 } // namespace ccxx
107 
115 #if defined (CCXX_OS_WINDOWS) && ! defined (CCXX_OS_WINDOWS_GNU)
116 
117 #define INT64_CONST(I) (I ## i64)
118 #define UINT64_CONST(I) (I ## Ui64)
119 
120 #else
121 
122 #define INT64_CONST(I) int64_t(I ## LL)
123 #define UINT64_CONST(I) uint64_t(I ## ULL)
124 
125 #endif
126 
154 #ifndef INT8_MIN
155 #define INT8_MIN (-128)
156 #endif
157 
158 #ifndef INT16_MIN
159 #define INT16_MIN (-32767-1)
160 #endif
161 
162 #ifndef INT32_MIN
163 #define INT32_MIN (-2147483647-1)
164 #endif
165 
166 #ifndef INT64_MIN
167 #define INT64_MIN (INT64_CONST(-9223372036854775807)-1)
168 #endif
169 
170 #ifndef INT8_MAX
171 #define INT8_MAX (127)
172 #endif
173 
174 #ifndef INT16_MAX
175 #define INT16_MAX (32767)
176 #endif
177 
178 #ifndef INT32_MAX
179 #define INT32_MAX (2147483647)
180 #endif
181 
182 #ifndef INT64_MAX
183 #define INT64_MAX (INT64_CONST(9223372036854775807))
184 #endif
185 
186 #ifndef UINT8_MAX
187 #define UINT8_MAX (255U)
188 #endif
189 
190 #ifndef UINT16_MAX
191 #define UINT16_MAX (65535U)
192 #endif
193 
194 #ifndef UINT32_MAX
195 #define UINT32_MAX (4294967295U)
196 #endif
197 
198 #ifndef UINT64_MAX
199 #define UINT64_MAX (UINT64_CONST(18446744073709551615))
200 #endif
201 
228 #if defined(CCXX_OS_WINDOWS) || defined (CCXX_OS_WINDOWS_GNU)
229 
230 #define INT64_FMT "%I64d"
231 #define UINT64_FMT "%I64u"
232 
233 // parameterized width versions
234 #define INT64_P_FMT(W) "%" #W "I64d"
235 #define UINT64_P_FMT(W) "%" #W "I64u"
236 
237 // parameterized width versions
238 
239 #ifdef __GNUC__
240 
241 #define INT64_WIDE_P_FMT(W) L"%" #W "I64d"
242 #define UINT64_WIDE_P_FMT(W) L"%" #W "I64u"
243 
244 #else
245 
246 #define INT64_WIDE_P_FMT(W) L"%" L#W L"I64d"
247 #define UINT64_WIDE_P_FMT(W) L"%" L#W L"I64u"
248 
249 #endif // __GNUC__
250 
251 #else
252 
253 #define INT64_FMT "%" PRId64
254 #define UINT64_FMT "%" PRIu64
255 
256 // parameterized width versions
257 #define INT64_P_FMT(W) "%" #W PRId64
258 #define UINT64_P_FMT(W) "%" #W PRIu64
259 
260 #endif
261 
267 #define CCXX_BIT_SET(N, BIT) \
268  ((N) |= (1 << (BIT)))
269 
275 #define CCXX_BIT_CLEAR(N, BIT) \
276  (((N) &= ~(1 << (BIT))))
277 
283 #define CCXX_BIT_READ(N, BIT) \
284  ((((N) & (1 << (BIT))) == 0) ? 0 : 1)
285 
292 #define CCXX_BIT_WRITE(N, BIT, VALUE) \
293  ((VALUE) ? CCXX_BIT_SET((N), (BIT)) : CCXX_BIT_CLEAR((N), (BIT)))
294 
301 #define CCXX_BIT_TEST(N, BIT) \
302  (((N) & (1 << (BIT))) != 0)
303 
304 #endif // __ccxx_Integers_hxx
int64_t time_ms_t
A time expressed in milliseconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:98
int32_t time_s_t
A time expressed in seconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:85
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
int timespan_s_t
A timespan expressed in seconds.
Definition: Integers.h++:91
int timespan_ms_t
A timespan expressed in milliseconds.
Definition: Integers.h++:104
Definition: AllocationMap.c++:25
unsigned char byte_t
An unsigned 8-bit value.
Definition: Integers.h++:68