umachine.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. ******************************************************************************
  3. *
  4. * Copyright (C) 1999-2015, 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 ICU 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. #include "unicode/ptypes.h" /* platform.h is included in ptypes.h */
  41. /*
  42. * ANSI C headers:
  43. * stddef.h defines wchar_t
  44. */
  45. #include <stddef.h>
  46. /*==========================================================================*/
  47. /* For C wrappers, we use the symbol U_STABLE. */
  48. /* This works properly if the includer is C or C++. */
  49. /* Functions are declared U_STABLE return-type U_EXPORT2 function-name()... */
  50. /*==========================================================================*/
  51. /**
  52. * \def U_CFUNC
  53. * This is used in a declaration of a library private ICU C function.
  54. * @stable ICU 2.4
  55. */
  56. /**
  57. * \def U_CDECL_BEGIN
  58. * This is used to begin a declaration of a library private ICU C API.
  59. * @stable ICU 2.4
  60. */
  61. /**
  62. * \def U_CDECL_END
  63. * This is used to end a declaration of a library private ICU C API
  64. * @stable ICU 2.4
  65. */
  66. #ifdef __cplusplus
  67. # define U_CFUNC extern "C"
  68. # define U_CDECL_BEGIN extern "C" {
  69. # define U_CDECL_END }
  70. #else
  71. # define U_CFUNC extern
  72. # define U_CDECL_BEGIN
  73. # define U_CDECL_END
  74. #endif
  75. #ifndef U_ATTRIBUTE_DEPRECATED
  76. /**
  77. * \def U_ATTRIBUTE_DEPRECATED
  78. * This is used for GCC specific attributes
  79. * @internal
  80. */
  81. #if U_GCC_MAJOR_MINOR >= 302
  82. # define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated))
  83. /**
  84. * \def U_ATTRIBUTE_DEPRECATED
  85. * This is used for Visual C++ specific attributes
  86. * @internal
  87. */
  88. #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
  89. # define U_ATTRIBUTE_DEPRECATED __declspec(deprecated)
  90. #else
  91. # define U_ATTRIBUTE_DEPRECATED
  92. #endif
  93. #endif
  94. /** This is used to declare a function as a public ICU C API @stable ICU 2.0*/
  95. #define U_CAPI U_CFUNC U_EXPORT
  96. /** This is used to declare a function as a stable public ICU C API*/
  97. #define U_STABLE U_CAPI
  98. /** This is used to declare a function as a draft public ICU C API */
  99. #define U_DRAFT U_CAPI
  100. /** This is used to declare a function as a deprecated public ICU C API */
  101. #define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED
  102. /** This is used to declare a function as an obsolete public ICU C API */
  103. #define U_OBSOLETE U_CAPI
  104. /** This is used to declare a function as an internal ICU C API */
  105. #define U_INTERNAL U_CAPI
  106. /**
  107. * \def U_OVERRIDE
  108. * Defined to the C++11 "override" keyword if available.
  109. * Denotes a class or member which is an override of the base class.
  110. * May result in an error if it applied to something not an override.
  111. * @internal
  112. */
  113. /**
  114. * \def U_FINAL
  115. * Defined to the C++11 "final" keyword if available.
  116. * Denotes a class or member which may not be overridden in subclasses.
  117. * May result in an error if subclasses attempt to override.
  118. * @internal
  119. */
  120. #if U_CPLUSPLUS_VERSION >= 11
  121. /* C++11 */
  122. #ifndef U_OVERRIDE
  123. #define U_OVERRIDE override
  124. #endif
  125. #ifndef U_FINAL
  126. #define U_FINAL final
  127. #endif
  128. #else
  129. /* not C++11 - define to nothing */
  130. #ifndef U_OVERRIDE
  131. #define U_OVERRIDE
  132. #endif
  133. #ifndef U_FINAL
  134. #define U_FINAL
  135. #endif
  136. #endif
  137. /*==========================================================================*/
  138. /* limits for int32_t etc., like in POSIX inttypes.h */
  139. /*==========================================================================*/
  140. #ifndef INT8_MIN
  141. /** The smallest value an 8 bit signed integer can hold @stable ICU 2.0 */
  142. # define INT8_MIN ((int8_t)(-128))
  143. #endif
  144. #ifndef INT16_MIN
  145. /** The smallest value a 16 bit signed integer can hold @stable ICU 2.0 */
  146. # define INT16_MIN ((int16_t)(-32767-1))
  147. #endif
  148. #ifndef INT32_MIN
  149. /** The smallest value a 32 bit signed integer can hold @stable ICU 2.0 */
  150. # define INT32_MIN ((int32_t)(-2147483647-1))
  151. #endif
  152. #ifndef INT8_MAX
  153. /** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */
  154. # define INT8_MAX ((int8_t)(127))
  155. #endif
  156. #ifndef INT16_MAX
  157. /** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */
  158. # define INT16_MAX ((int16_t)(32767))
  159. #endif
  160. #ifndef INT32_MAX
  161. /** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */
  162. # define INT32_MAX ((int32_t)(2147483647))
  163. #endif
  164. #ifndef UINT8_MAX
  165. /** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */
  166. # define UINT8_MAX ((uint8_t)(255U))
  167. #endif
  168. #ifndef UINT16_MAX
  169. /** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */
  170. # define UINT16_MAX ((uint16_t)(65535U))
  171. #endif
  172. #ifndef UINT32_MAX
  173. /** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */
  174. # define UINT32_MAX ((uint32_t)(4294967295U))
  175. #endif
  176. #if defined(U_INT64_T_UNAVAILABLE)
  177. # error int64_t is required for decimal format and rule-based number format.
  178. #else
  179. # ifndef INT64_C
  180. /**
  181. * Provides a platform independent way to specify a signed 64-bit integer constant.
  182. * note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C
  183. * @stable ICU 2.8
  184. */
  185. # define INT64_C(c) c ## LL
  186. # endif
  187. # ifndef UINT64_C
  188. /**
  189. * Provides a platform independent way to specify an unsigned 64-bit integer constant.
  190. * note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C
  191. * @stable ICU 2.8
  192. */
  193. # define UINT64_C(c) c ## ULL
  194. # endif
  195. # ifndef U_INT64_MIN
  196. /** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */
  197. # define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1))
  198. # endif
  199. # ifndef U_INT64_MAX
  200. /** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */
  201. # define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807)))
  202. # endif
  203. # ifndef U_UINT64_MAX
  204. /** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */
  205. # define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615)))
  206. # endif
  207. #endif
  208. /*==========================================================================*/
  209. /* Boolean data type */
  210. /*==========================================================================*/
  211. /** The ICU boolean type @stable ICU 2.0 */
  212. typedef int8_t UBool;
  213. #ifndef TRUE
  214. /** The TRUE value of a UBool @stable ICU 2.0 */
  215. # define TRUE 1
  216. #endif
  217. #ifndef FALSE
  218. /** The FALSE value of a UBool @stable ICU 2.0 */
  219. # define FALSE 0
  220. #endif
  221. /*==========================================================================*/
  222. /* Unicode data types */
  223. /*==========================================================================*/
  224. /* wchar_t-related definitions -------------------------------------------- */
  225. /*
  226. * \def U_WCHAR_IS_UTF16
  227. * Defined if wchar_t uses UTF-16.
  228. *
  229. * @stable ICU 2.0
  230. */
  231. /*
  232. * \def U_WCHAR_IS_UTF32
  233. * Defined if wchar_t uses UTF-32.
  234. *
  235. * @stable ICU 2.0
  236. */
  237. #if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32)
  238. # ifdef __STDC_ISO_10646__
  239. # if (U_SIZEOF_WCHAR_T==2)
  240. # define U_WCHAR_IS_UTF16
  241. # elif (U_SIZEOF_WCHAR_T==4)
  242. # define U_WCHAR_IS_UTF32
  243. # endif
  244. # elif defined __UCS2__
  245. # if (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400) && (U_SIZEOF_WCHAR_T==2)
  246. # define U_WCHAR_IS_UTF16
  247. # endif
  248. # elif defined(__UCS4__) || (U_PLATFORM == U_PF_OS400 && defined(__UTF32__))
  249. # if (U_SIZEOF_WCHAR_T==4)
  250. # define U_WCHAR_IS_UTF32
  251. # endif
  252. # elif U_PLATFORM_IS_DARWIN_BASED || (U_SIZEOF_WCHAR_T==4 && U_PLATFORM_IS_LINUX_BASED)
  253. # define U_WCHAR_IS_UTF32
  254. # elif U_PLATFORM_HAS_WIN32_API
  255. # define U_WCHAR_IS_UTF16
  256. # endif
  257. #endif
  258. /* UChar and UChar32 definitions -------------------------------------------- */
  259. /** Number of bytes in a UChar. @stable ICU 2.0 */
  260. #define U_SIZEOF_UCHAR 2
  261. /**
  262. * \var UChar
  263. * Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t),
  264. * or wchar_t if that is 16 bits wide; always assumed to be unsigned.
  265. * If neither is available, then define UChar to be uint16_t.
  266. *
  267. * This makes the definition of UChar platform-dependent
  268. * but allows direct string type compatibility with platforms with
  269. * 16-bit wchar_t types.
  270. *
  271. * @stable ICU 4.4
  272. */
  273. #if defined(UCHAR_TYPE)
  274. typedef UCHAR_TYPE UChar;
  275. /* Not #elif U_HAVE_CHAR16_T -- because that is type-incompatible with pre-C++11 callers
  276. typedef char16_t UChar; */
  277. #elif U_SIZEOF_WCHAR_T==2
  278. typedef wchar_t UChar;
  279. #elif defined(__CHAR16_TYPE__)
  280. typedef __CHAR16_TYPE__ UChar;
  281. #else
  282. typedef uint16_t UChar;
  283. #endif
  284. /**
  285. * Define UChar32 as a type for single Unicode code points.
  286. * UChar32 is a signed 32-bit integer (same as int32_t).
  287. *
  288. * The Unicode code point range is 0..0x10ffff.
  289. * All other values (negative or >=0x110000) are illegal as Unicode code points.
  290. * They may be used as sentinel values to indicate "done", "error"
  291. * or similar non-code point conditions.
  292. *
  293. * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined
  294. * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned)
  295. * or else to be uint32_t.
  296. * That is, the definition of UChar32 was platform-dependent.
  297. *
  298. * @see U_SENTINEL
  299. * @stable ICU 2.4
  300. */
  301. typedef int32_t UChar32;
  302. /**
  303. * This value is intended for sentinel values for APIs that
  304. * (take or) return single code points (UChar32).
  305. * It is outside of the Unicode code point range 0..0x10ffff.
  306. *
  307. * For example, a "done" or "error" value in a new API
  308. * could be indicated with U_SENTINEL.
  309. *
  310. * ICU APIs designed before ICU 2.4 usually define service-specific "done"
  311. * values, mostly 0xffff.
  312. * Those may need to be distinguished from
  313. * actual U+ffff text contents by calling functions like
  314. * CharacterIterator::hasNext() or UnicodeString::length().
  315. *
  316. * @return -1
  317. * @see UChar32
  318. * @stable ICU 2.4
  319. */
  320. #define U_SENTINEL (-1)
  321. #include "unicode/urename.h"
  322. #endif