michael@0: /*
michael@0: ******************************************************************************
michael@0: *
michael@0: * Copyright (C) 1999-2012, International Business Machines
michael@0: * Corporation and others. All Rights Reserved.
michael@0: *
michael@0: ******************************************************************************
michael@0: * file name: umachine.h
michael@0: * encoding: US-ASCII
michael@0: * tab size: 8 (not used)
michael@0: * indentation:4
michael@0: *
michael@0: * created on: 1999sep13
michael@0: * created by: Markus W. Scherer
michael@0: *
michael@0: * This file defines basic types and constants for utf.h to be
michael@0: * platform-independent. umachine.h and utf.h are included into
michael@0: * utypes.h to provide all the general definitions for ICU.
michael@0: * All of these definitions used to be in utypes.h before
michael@0: * the UTF-handling macros made this unmaintainable.
michael@0: */
michael@0:
michael@0: #ifndef __UMACHINE_H__
michael@0: #define __UMACHINE_H__
michael@0:
michael@0:
michael@0: /**
michael@0: * \file
michael@0: * \brief Basic types and constants for UTF
michael@0: *
michael@0: *
Basic types and constants for UTF
michael@0: * This file defines basic types and constants for utf.h to be
michael@0: * platform-independent. umachine.h and utf.h are included into
michael@0: * utypes.h to provide all the general definitions for ICU.
michael@0: * All of these definitions used to be in utypes.h before
michael@0: * the UTF-handling macros made this unmaintainable.
michael@0: *
michael@0: */
michael@0: /*==========================================================================*/
michael@0: /* Include platform-dependent definitions */
michael@0: /* which are contained in the platform-specific file platform.h */
michael@0: /*==========================================================================*/
michael@0:
michael@0: #include "unicode/ptypes.h" /* platform.h is included in ptypes.h */
michael@0:
michael@0: /*
michael@0: * ANSI C headers:
michael@0: * stddef.h defines wchar_t
michael@0: */
michael@0: #include
michael@0:
michael@0: /*==========================================================================*/
michael@0: /* For C wrappers, we use the symbol U_STABLE. */
michael@0: /* This works properly if the includer is C or C++. */
michael@0: /* Functions are declared U_STABLE return-type U_EXPORT2 function-name()... */
michael@0: /*==========================================================================*/
michael@0:
michael@0: /**
michael@0: * \def U_CFUNC
michael@0: * This is used in a declaration of a library private ICU C function.
michael@0: * @stable ICU 2.4
michael@0: */
michael@0:
michael@0: /**
michael@0: * \def U_CDECL_BEGIN
michael@0: * This is used to begin a declaration of a library private ICU C API.
michael@0: * @stable ICU 2.4
michael@0: */
michael@0:
michael@0: /**
michael@0: * \def U_CDECL_END
michael@0: * This is used to end a declaration of a library private ICU C API
michael@0: * @stable ICU 2.4
michael@0: */
michael@0:
michael@0: #ifdef __cplusplus
michael@0: # define U_CFUNC extern "C"
michael@0: # define U_CDECL_BEGIN extern "C" {
michael@0: # define U_CDECL_END }
michael@0: #else
michael@0: # define U_CFUNC extern
michael@0: # define U_CDECL_BEGIN
michael@0: # define U_CDECL_END
michael@0: #endif
michael@0:
michael@0: #ifndef U_ATTRIBUTE_DEPRECATED
michael@0: /**
michael@0: * \def U_ATTRIBUTE_DEPRECATED
michael@0: * This is used for GCC specific attributes
michael@0: * @internal
michael@0: */
michael@0: #if U_GCC_MAJOR_MINOR >= 302
michael@0: # define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated))
michael@0: /**
michael@0: * \def U_ATTRIBUTE_DEPRECATED
michael@0: * This is used for Visual C++ specific attributes
michael@0: * @internal
michael@0: */
michael@0: #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
michael@0: # define U_ATTRIBUTE_DEPRECATED __declspec(deprecated)
michael@0: #else
michael@0: # define U_ATTRIBUTE_DEPRECATED
michael@0: #endif
michael@0: #endif
michael@0:
michael@0: /** This is used to declare a function as a public ICU C API @stable ICU 2.0*/
michael@0: #define U_CAPI U_CFUNC U_EXPORT
michael@0: /** This is used to declare a function as a stable public ICU C API*/
michael@0: #define U_STABLE U_CAPI
michael@0: /** This is used to declare a function as a draft public ICU C API */
michael@0: #define U_DRAFT U_CAPI
michael@0: /** This is used to declare a function as a deprecated public ICU C API */
michael@0: #define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED
michael@0: /** This is used to declare a function as an obsolete public ICU C API */
michael@0: #define U_OBSOLETE U_CAPI
michael@0: /** This is used to declare a function as an internal ICU C API */
michael@0: #define U_INTERNAL U_CAPI
michael@0:
michael@0: /*==========================================================================*/
michael@0: /* limits for int32_t etc., like in POSIX inttypes.h */
michael@0: /*==========================================================================*/
michael@0:
michael@0: #ifndef INT8_MIN
michael@0: /** The smallest value an 8 bit signed integer can hold @stable ICU 2.0 */
michael@0: # define INT8_MIN ((int8_t)(-128))
michael@0: #endif
michael@0: #ifndef INT16_MIN
michael@0: /** The smallest value a 16 bit signed integer can hold @stable ICU 2.0 */
michael@0: # define INT16_MIN ((int16_t)(-32767-1))
michael@0: #endif
michael@0: #ifndef INT32_MIN
michael@0: /** The smallest value a 32 bit signed integer can hold @stable ICU 2.0 */
michael@0: # define INT32_MIN ((int32_t)(-2147483647-1))
michael@0: #endif
michael@0:
michael@0: #ifndef INT8_MAX
michael@0: /** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */
michael@0: # define INT8_MAX ((int8_t)(127))
michael@0: #endif
michael@0: #ifndef INT16_MAX
michael@0: /** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */
michael@0: # define INT16_MAX ((int16_t)(32767))
michael@0: #endif
michael@0: #ifndef INT32_MAX
michael@0: /** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */
michael@0: # define INT32_MAX ((int32_t)(2147483647))
michael@0: #endif
michael@0:
michael@0: #ifndef UINT8_MAX
michael@0: /** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */
michael@0: # define UINT8_MAX ((uint8_t)(255U))
michael@0: #endif
michael@0: #ifndef UINT16_MAX
michael@0: /** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */
michael@0: # define UINT16_MAX ((uint16_t)(65535U))
michael@0: #endif
michael@0: #ifndef UINT32_MAX
michael@0: /** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */
michael@0: # define UINT32_MAX ((uint32_t)(4294967295U))
michael@0: #endif
michael@0:
michael@0: #if defined(U_INT64_T_UNAVAILABLE)
michael@0: # error int64_t is required for decimal format and rule-based number format.
michael@0: #else
michael@0: # ifndef INT64_C
michael@0: /**
michael@0: * Provides a platform independent way to specify a signed 64-bit integer constant.
michael@0: * note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C
michael@0: * @stable ICU 2.8
michael@0: */
michael@0: # define INT64_C(c) c ## LL
michael@0: # endif
michael@0: # ifndef UINT64_C
michael@0: /**
michael@0: * Provides a platform independent way to specify an unsigned 64-bit integer constant.
michael@0: * note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C
michael@0: * @stable ICU 2.8
michael@0: */
michael@0: # define UINT64_C(c) c ## ULL
michael@0: # endif
michael@0: # ifndef U_INT64_MIN
michael@0: /** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */
michael@0: # define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1))
michael@0: # endif
michael@0: # ifndef U_INT64_MAX
michael@0: /** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */
michael@0: # define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807)))
michael@0: # endif
michael@0: # ifndef U_UINT64_MAX
michael@0: /** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */
michael@0: # define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615)))
michael@0: # endif
michael@0: #endif
michael@0:
michael@0: /*==========================================================================*/
michael@0: /* Boolean data type */
michael@0: /*==========================================================================*/
michael@0:
michael@0: /** The ICU boolean type @stable ICU 2.0 */
michael@0: typedef int8_t UBool;
michael@0:
michael@0: #ifndef TRUE
michael@0: /** The TRUE value of a UBool @stable ICU 2.0 */
michael@0: # define TRUE 1
michael@0: #endif
michael@0: #ifndef FALSE
michael@0: /** The FALSE value of a UBool @stable ICU 2.0 */
michael@0: # define FALSE 0
michael@0: #endif
michael@0:
michael@0:
michael@0: /*==========================================================================*/
michael@0: /* Unicode data types */
michael@0: /*==========================================================================*/
michael@0:
michael@0: /* wchar_t-related definitions -------------------------------------------- */
michael@0:
michael@0: /*
michael@0: * \def U_WCHAR_IS_UTF16
michael@0: * Defined if wchar_t uses UTF-16.
michael@0: *
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: /*
michael@0: * \def U_WCHAR_IS_UTF32
michael@0: * Defined if wchar_t uses UTF-32.
michael@0: *
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32)
michael@0: # ifdef __STDC_ISO_10646__
michael@0: # if (U_SIZEOF_WCHAR_T==2)
michael@0: # define U_WCHAR_IS_UTF16
michael@0: # elif (U_SIZEOF_WCHAR_T==4)
michael@0: # define U_WCHAR_IS_UTF32
michael@0: # endif
michael@0: # elif defined __UCS2__
michael@0: # if (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400) && (U_SIZEOF_WCHAR_T==2)
michael@0: # define U_WCHAR_IS_UTF16
michael@0: # endif
michael@0: # elif defined(__UCS4__) || (U_PLATFORM == U_PF_OS400 && defined(__UTF32__))
michael@0: # if (U_SIZEOF_WCHAR_T==4)
michael@0: # define U_WCHAR_IS_UTF32
michael@0: # endif
michael@0: # elif U_PLATFORM_IS_DARWIN_BASED || (U_SIZEOF_WCHAR_T==4 && U_PLATFORM_IS_LINUX_BASED)
michael@0: # define U_WCHAR_IS_UTF32
michael@0: # elif U_PLATFORM_HAS_WIN32_API
michael@0: # define U_WCHAR_IS_UTF16
michael@0: # endif
michael@0: #endif
michael@0:
michael@0: /* UChar and UChar32 definitions -------------------------------------------- */
michael@0:
michael@0: /** Number of bytes in a UChar. @stable ICU 2.0 */
michael@0: #define U_SIZEOF_UCHAR 2
michael@0:
michael@0: /**
michael@0: * \var UChar
michael@0: * Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t),
michael@0: * or wchar_t if that is 16 bits wide; always assumed to be unsigned.
michael@0: * If neither is available, then define UChar to be uint16_t.
michael@0: *
michael@0: * This makes the definition of UChar platform-dependent
michael@0: * but allows direct string type compatibility with platforms with
michael@0: * 16-bit wchar_t types.
michael@0: *
michael@0: * @stable ICU 4.4
michael@0: */
michael@0: #if defined(UCHAR_TYPE)
michael@0: typedef UCHAR_TYPE UChar;
michael@0: /* Not #elif U_HAVE_CHAR16_T -- because that is type-incompatible with pre-C++11 callers
michael@0: typedef char16_t UChar; */
michael@0: #elif U_SIZEOF_WCHAR_T==2
michael@0: typedef wchar_t UChar;
michael@0: #elif defined(__CHAR16_TYPE__)
michael@0: typedef __CHAR16_TYPE__ UChar;
michael@0: #else
michael@0: typedef uint16_t UChar;
michael@0: #endif
michael@0:
michael@0: /**
michael@0: * Define UChar32 as a type for single Unicode code points.
michael@0: * UChar32 is a signed 32-bit integer (same as int32_t).
michael@0: *
michael@0: * The Unicode code point range is 0..0x10ffff.
michael@0: * All other values (negative or >=0x110000) are illegal as Unicode code points.
michael@0: * They may be used as sentinel values to indicate "done", "error"
michael@0: * or similar non-code point conditions.
michael@0: *
michael@0: * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined
michael@0: * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned)
michael@0: * or else to be uint32_t.
michael@0: * That is, the definition of UChar32 was platform-dependent.
michael@0: *
michael@0: * @see U_SENTINEL
michael@0: * @stable ICU 2.4
michael@0: */
michael@0: typedef int32_t UChar32;
michael@0:
michael@0: /**
michael@0: * This value is intended for sentinel values for APIs that
michael@0: * (take or) return single code points (UChar32).
michael@0: * It is outside of the Unicode code point range 0..0x10ffff.
michael@0: *
michael@0: * For example, a "done" or "error" value in a new API
michael@0: * could be indicated with U_SENTINEL.
michael@0: *
michael@0: * ICU APIs designed before ICU 2.4 usually define service-specific "done"
michael@0: * values, mostly 0xffff.
michael@0: * Those may need to be distinguished from
michael@0: * actual U+ffff text contents by calling functions like
michael@0: * CharacterIterator::hasNext() or UnicodeString::length().
michael@0: *
michael@0: * @return -1
michael@0: * @see UChar32
michael@0: * @stable ICU 2.4
michael@0: */
michael@0: #define U_SENTINEL (-1)
michael@0:
michael@0: #include "unicode/urename.h"
michael@0:
michael@0: #endif