umachine.h 12 KB

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