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