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