• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ******************************************************************************
3 *
4 *   Copyright (C) 1999-2010, International Business Machines
5 *   Corporation and others.  All Rights Reserved.
6 *
7 ******************************************************************************
8 *   file name:  umachine.h
9 *   encoding:   US-ASCII
10 *   tab size:   8 (not used)
11 *   indentation:4
12 *
13 *   created on: 1999sep13
14 *   created by: Markus W. Scherer
15 *
16 *   This file defines basic types and constants for utf.h to be
17 *   platform-independent. umachine.h and utf.h are included into
18 *   utypes.h to provide all the general definitions for ICU.
19 *   All of these definitions used to be in utypes.h before
20 *   the UTF-handling macros made this unmaintainable.
21 */
22 
23 #ifndef __UMACHINE_H__
24 #define __UMACHINE_H__
25 
26 
27 /**
28  * \file
29  * \brief Basic types and constants for UTF
30  *
31  * <h2> Basic types and constants for UTF </h2>
32  *   This file defines basic types and constants for utf.h to be
33  *   platform-independent. umachine.h and utf.h are included into
34  *   utypes.h to provide all the general definitions for ICU.
35  *   All of these definitions used to be in utypes.h before
36  *   the UTF-handling macros made this unmaintainable.
37  *
38  */
39 /*==========================================================================*/
40 /* Include platform-dependent definitions                                   */
41 /* which are contained in the platform-specific file platform.h             */
42 /*==========================================================================*/
43 
44 #if defined(U_PALMOS)
45 #   include "unicode/ppalmos.h"
46 #elif !defined(__MINGW32__) && (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64))
47 #ifdef CYGWINMSVC
48 #   include "unicode/platform.h"
49 #endif
50 #   include "unicode/pwin32.h"
51 #else
52 #   include "unicode/ptypes.h" /* platform.h is included in ptypes.h */
53 #endif
54 
55 /*
56  * ANSI C headers:
57  * stddef.h defines wchar_t
58  */
59 #include <stddef.h>
60 
61 /*==========================================================================*/
62 /* XP_CPLUSPLUS is a cross-platform symbol which should be defined when     */
63 /* using C++.  It should not be defined when compiling under C.             */
64 /*==========================================================================*/
65 
66 #ifdef __cplusplus
67 #   ifndef XP_CPLUSPLUS
68 #       define XP_CPLUSPLUS
69 #   endif
70 #else
71 #   undef XP_CPLUSPLUS
72 #endif
73 
74 /*==========================================================================*/
75 /* For C wrappers, we use the symbol U_STABLE.                                */
76 /* This works properly if the includer is C or C++.                         */
77 /* Functions are declared   U_STABLE return-type U_EXPORT2 function-name()... */
78 /*==========================================================================*/
79 
80 /**
81  * \def U_CFUNC
82  * This is used in a declaration of a library private ICU C function.
83  * @stable ICU 2.4
84  */
85 
86 /**
87  * \def U_CDECL_BEGIN
88  * This is used to begin a declaration of a library private ICU C API.
89  * @stable ICU 2.4
90  */
91 
92 /**
93  * \def U_CDECL_END
94  * This is used to end a declaration of a library private ICU C API
95  * @stable ICU 2.4
96  */
97 
98 #ifdef XP_CPLUSPLUS
99 #   define U_CFUNC extern "C"
100 #   define U_CDECL_BEGIN extern "C" {
101 #   define U_CDECL_END   }
102 #else
103 #   define U_CFUNC extern
104 #   define U_CDECL_BEGIN
105 #   define U_CDECL_END
106 #endif
107 
108 /**
109  * \def U_ATTRIBUTE_DEPRECATED
110  *  This is used for GCC specific attributes
111  * @internal
112  */
113 #if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2))
114 #    define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated))
115 /**
116  * \def U_ATTRIBUTE_DEPRECATED
117  * This is used for Visual C++ specific attributes
118  * @internal
119  */
120 #elif defined(U_WINDOWS) && defined(_MSC_VER) && (_MSC_VER >= 1400)
121 #    define U_ATTRIBUTE_DEPRECATED __declspec(deprecated)
122 #else
123 #    define U_ATTRIBUTE_DEPRECATED
124 #endif
125 /** This is used to declare a function as a public ICU C API @stable ICU 2.0*/
126 #define U_CAPI U_CFUNC U_EXPORT
127 /** This is used to declare a function as a stable public ICU C API*/
128 #define U_STABLE U_CAPI
129 /** This is used to declare a function as a draft public ICU C API  */
130 #define U_DRAFT  U_CAPI
131 /** This is used to declare a function as a deprecated public ICU C API  */
132 #define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED
133 /** This is used to declare a function as an obsolete public ICU C API  */
134 #define U_OBSOLETE U_CAPI
135 /** This is used to declare a function as an internal ICU C API  */
136 #define U_INTERNAL U_CAPI
137 
138 /*==========================================================================*/
139 /* limits for int32_t etc., like in POSIX inttypes.h                        */
140 /*==========================================================================*/
141 
142 #ifndef INT8_MIN
143 /** The smallest value an 8 bit signed integer can hold @stable ICU 2.0 */
144 #   define INT8_MIN        ((int8_t)(-128))
145 #endif
146 #ifndef INT16_MIN
147 /** The smallest value a 16 bit signed integer can hold @stable ICU 2.0 */
148 #   define INT16_MIN       ((int16_t)(-32767-1))
149 #endif
150 #ifndef INT32_MIN
151 /** The smallest value a 32 bit signed integer can hold @stable ICU 2.0 */
152 #   define INT32_MIN       ((int32_t)(-2147483647-1))
153 #endif
154 
155 #ifndef INT8_MAX
156 /** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */
157 #   define INT8_MAX        ((int8_t)(127))
158 #endif
159 #ifndef INT16_MAX
160 /** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */
161 #   define INT16_MAX       ((int16_t)(32767))
162 #endif
163 #ifndef INT32_MAX
164 /** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */
165 #   define INT32_MAX       ((int32_t)(2147483647))
166 #endif
167 
168 #ifndef UINT8_MAX
169 /** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */
170 #   define UINT8_MAX       ((uint8_t)(255U))
171 #endif
172 #ifndef UINT16_MAX
173 /** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */
174 #   define UINT16_MAX      ((uint16_t)(65535U))
175 #endif
176 #ifndef UINT32_MAX
177 /** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */
178 #   define UINT32_MAX      ((uint32_t)(4294967295U))
179 #endif
180 
181 #if defined(U_INT64_T_UNAVAILABLE)
182 # error int64_t is required for decimal format and rule-based number format.
183 #else
184 # ifndef INT64_C
185 /**
186  * Provides a platform independent way to specify a signed 64-bit integer constant.
187  * note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C
188  * @stable ICU 2.8
189  */
190 #   define INT64_C(c) c ## LL
191 # endif
192 # ifndef UINT64_C
193 /**
194  * Provides a platform independent way to specify an unsigned 64-bit integer constant.
195  * note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C
196  * @stable ICU 2.8
197  */
198 #   define UINT64_C(c) c ## ULL
199 # endif
200 # ifndef U_INT64_MIN
201 /** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */
202 #     define U_INT64_MIN       ((int64_t)(INT64_C(-9223372036854775807)-1))
203 # endif
204 # ifndef U_INT64_MAX
205 /** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */
206 #     define U_INT64_MAX       ((int64_t)(INT64_C(9223372036854775807)))
207 # endif
208 # ifndef U_UINT64_MAX
209 /** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */
210 #     define U_UINT64_MAX      ((uint64_t)(UINT64_C(18446744073709551615)))
211 # endif
212 #endif
213 
214 /*==========================================================================*/
215 /* Boolean data type                                                        */
216 /*==========================================================================*/
217 
218 /** The ICU boolean type @stable ICU 2.0 */
219 typedef int8_t UBool;
220 
221 #ifndef TRUE
222 /** The TRUE value of a UBool @stable ICU 2.0 */
223 #   define TRUE  1
224 #endif
225 #ifndef FALSE
226 /** The FALSE value of a UBool @stable ICU 2.0 */
227 #   define FALSE 0
228 #endif
229 
230 
231 /*==========================================================================*/
232 /* Unicode data types                                                       */
233 /*==========================================================================*/
234 
235 /* wchar_t-related definitions -------------------------------------------- */
236 
237 /**
238  * \def U_HAVE_WCHAR_H
239  * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default.
240  *
241  * @stable ICU 2.0
242  */
243 #ifndef U_HAVE_WCHAR_H
244 #   define U_HAVE_WCHAR_H 1
245 #endif
246 
247 /**
248  * \def U_SIZEOF_WCHAR_T
249  * U_SIZEOF_WCHAR_T==sizeof(wchar_t) (0 means it is not defined or autoconf could not set it)
250  *
251  * @stable ICU 2.0
252  */
253 #if U_SIZEOF_WCHAR_T==0
254 #   undef U_SIZEOF_WCHAR_T
255 #   define U_SIZEOF_WCHAR_T 4
256 #endif
257 
258 /*
259  * \def U_WCHAR_IS_UTF16
260  * Defined if wchar_t uses UTF-16.
261  *
262  * @stable ICU 2.0
263  */
264 /*
265  * \def U_WCHAR_IS_UTF32
266  * Defined if wchar_t uses UTF-32.
267  *
268  * @stable ICU 2.0
269  */
270 #if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32)
271 #   ifdef __STDC_ISO_10646__
272 #       if (U_SIZEOF_WCHAR_T==2)
273 #           define U_WCHAR_IS_UTF16
274 #       elif (U_SIZEOF_WCHAR_T==4)
275 #           define  U_WCHAR_IS_UTF32
276 #       endif
277 #   elif defined __UCS2__
278 #       if (__OS390__ || __OS400__) && (U_SIZEOF_WCHAR_T==2)
279 #           define U_WCHAR_IS_UTF16
280 #       endif
281 #   elif defined __UCS4__
282 #       if (U_SIZEOF_WCHAR_T==4)
283 #           define U_WCHAR_IS_UTF32
284 #       endif
285 #   elif defined(U_WINDOWS)
286 #       define U_WCHAR_IS_UTF16
287 #   endif
288 #endif
289 
290 /* UChar and UChar32 definitions -------------------------------------------- */
291 
292 /** Number of bytes in a UChar. @stable ICU 2.0 */
293 #define U_SIZEOF_UCHAR 2
294 
295 /**
296  * \var UChar
297  * Define UChar to be wchar_t if that is 16 bits wide; always assumed to be unsigned.
298  * If wchar_t is not 16 bits wide, then define UChar to be uint16_t or char16_t because GCC >=4.4
299  * can handle UTF16 string literals.
300  * This makes the definition of UChar platform-dependent
301  * but allows direct string type compatibility with platforms with
302  * 16-bit wchar_t types.
303  *
304  * @draft ICU 4.4
305  */
306 
307 /* Define UChar to be compatible with wchar_t if possible. */
308 #if U_SIZEOF_WCHAR_T==2
309     typedef wchar_t UChar;
310 #elif U_GNUC_UTF16_STRING
311 #if defined _GCC_
312     typedef __CHAR16_TYPE__ char16_t;
313 #endif
314     typedef char16_t UChar;
315 #else
316     typedef uint16_t UChar;
317 #endif
318 
319 /**
320  * Define UChar32 as a type for single Unicode code points.
321  * UChar32 is a signed 32-bit integer (same as int32_t).
322  *
323  * The Unicode code point range is 0..0x10ffff.
324  * All other values (negative or >=0x110000) are illegal as Unicode code points.
325  * They may be used as sentinel values to indicate "done", "error"
326  * or similar non-code point conditions.
327  *
328  * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined
329  * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned)
330  * or else to be uint32_t.
331  * That is, the definition of UChar32 was platform-dependent.
332  *
333  * @see U_SENTINEL
334  * @stable ICU 2.4
335  */
336 typedef int32_t UChar32;
337 
338 /*==========================================================================*/
339 /* U_INLINE and U_ALIGN_CODE   Set default values if these are not already  */
340 /*                             defined.  Definitions normally are in        */
341 /*                             platform.h or the corresponding file for     */
342 /*                             the OS in use.                               */
343 /*==========================================================================*/
344 
345 #ifndef U_HIDE_INTERNAL_API
346 
347 /**
348  * \def U_ALIGN_CODE
349  * This is used to align code fragments to a specific byte boundary.
350  * This is useful for getting consistent performance test results.
351  * @internal
352  */
353 #ifndef U_ALIGN_CODE
354 #   define U_ALIGN_CODE(n)
355 #endif
356 
357 #endif /* U_HIDE_INTERNAL_API */
358 
359 /**
360  * \def U_INLINE
361  * This is used to request inlining of a function, on platforms and languages which support it.
362  */
363 
364 #ifndef U_INLINE
365 #   ifdef XP_CPLUSPLUS
366 #       define U_INLINE inline
367 #   else
368 #       define U_INLINE
369 #   endif
370 #endif
371 
372 #include "unicode/urename.h"
373 
374 #endif
375