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