jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ****************************************************************************** jpayne@69: * jpayne@69: * Copyright (C) 1999-2014, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: * jpayne@69: ****************************************************************************** jpayne@69: * file name: udata.h jpayne@69: * encoding: UTF-8 jpayne@69: * tab size: 8 (not used) jpayne@69: * indentation:4 jpayne@69: * jpayne@69: * created on: 1999oct25 jpayne@69: * created by: Markus W. Scherer jpayne@69: */ jpayne@69: jpayne@69: #ifndef __UDATA_H__ jpayne@69: #define __UDATA_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: #include "unicode/localpointer.h" jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Data loading interface jpayne@69: * jpayne@69: *

Information about data loading interface

jpayne@69: * jpayne@69: * This API is used to find and efficiently load data for ICU and applications jpayne@69: * using ICU. It provides an abstract interface that specifies a data type and jpayne@69: * name to find and load the data. Normally this API is used by other ICU APIs jpayne@69: * to load required data out of the ICU data library, but it can be used to jpayne@69: * load data out of other places. jpayne@69: * jpayne@69: * See the User Guide Data Management chapter. jpayne@69: */ jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Character used to separate package names from tree names jpayne@69: * @internal ICU 3.0 jpayne@69: */ jpayne@69: #define U_TREE_SEPARATOR '-' jpayne@69: jpayne@69: /** jpayne@69: * String used to separate package names from tree names jpayne@69: * @internal ICU 3.0 jpayne@69: */ jpayne@69: #define U_TREE_SEPARATOR_STRING "-" jpayne@69: jpayne@69: /** jpayne@69: * Character used to separate parts of entry names jpayne@69: * @internal ICU 3.0 jpayne@69: */ jpayne@69: #define U_TREE_ENTRY_SEP_CHAR '/' jpayne@69: jpayne@69: /** jpayne@69: * String used to separate parts of entry names jpayne@69: * @internal ICU 3.0 jpayne@69: */ jpayne@69: #define U_TREE_ENTRY_SEP_STRING "/" jpayne@69: jpayne@69: /** jpayne@69: * Alias for standard ICU data jpayne@69: * @internal ICU 3.0 jpayne@69: */ jpayne@69: #define U_ICUDATA_ALIAS "ICUDATA" jpayne@69: jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * UDataInfo contains the properties about the requested data. jpayne@69: * This is meta data. jpayne@69: * jpayne@69: *

This structure may grow in the future, indicated by the jpayne@69: * size field.

jpayne@69: * jpayne@69: *

ICU data must be at least 8-aligned, and should be 16-aligned. jpayne@69: * The UDataInfo struct begins 4 bytes after the start of the data item, jpayne@69: * so it is 4-aligned. jpayne@69: * jpayne@69: *

The platform data property fields help determine if a data jpayne@69: * file can be efficiently used on a given machine. jpayne@69: * The particular fields are of importance only if the data jpayne@69: * is affected by the properties - if there is integer data jpayne@69: * with word sizes > 1 byte, char* text, or UChar* text.

jpayne@69: * jpayne@69: *

The implementation for the udata_open[Choice]() jpayne@69: * functions may reject data based on the value in isBigEndian. jpayne@69: * No other field is used by the udata API implementation.

jpayne@69: * jpayne@69: *

The dataFormat may be used to identify jpayne@69: * the kind of data, e.g. a converter table.

jpayne@69: * jpayne@69: *

The formatVersion field should be used to jpayne@69: * make sure that the format can be interpreted. jpayne@69: * It may be a good idea to check only for the one or two highest jpayne@69: * of the version elements to allow the data memory to jpayne@69: * get more or somewhat rearranged contents, for as long jpayne@69: * as the using code can still interpret the older contents.

jpayne@69: * jpayne@69: *

The dataVersion field is intended to be a jpayne@69: * common place to store the source version of the data; jpayne@69: * for data from the Unicode character database, this could jpayne@69: * reflect the Unicode version.

jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef struct { jpayne@69: /** sizeof(UDataInfo) jpayne@69: * @stable ICU 2.0 */ jpayne@69: uint16_t size; jpayne@69: jpayne@69: /** unused, set to 0 jpayne@69: * @stable ICU 2.0*/ jpayne@69: uint16_t reservedWord; jpayne@69: jpayne@69: /* platform data properties */ jpayne@69: /** 0 for little-endian machine, 1 for big-endian jpayne@69: * @stable ICU 2.0 */ jpayne@69: uint8_t isBigEndian; jpayne@69: jpayne@69: /** see U_CHARSET_FAMILY values in utypes.h jpayne@69: * @stable ICU 2.0*/ jpayne@69: uint8_t charsetFamily; jpayne@69: jpayne@69: /** sizeof(UChar), one of { 1, 2, 4 } jpayne@69: * @stable ICU 2.0*/ jpayne@69: uint8_t sizeofUChar; jpayne@69: jpayne@69: /** unused, set to 0 jpayne@69: * @stable ICU 2.0*/ jpayne@69: uint8_t reservedByte; jpayne@69: jpayne@69: /** data format identifier jpayne@69: * @stable ICU 2.0*/ jpayne@69: uint8_t dataFormat[4]; jpayne@69: jpayne@69: /** versions: [0] major [1] minor [2] milli [3] micro jpayne@69: * @stable ICU 2.0*/ jpayne@69: uint8_t formatVersion[4]; jpayne@69: jpayne@69: /** versions: [0] major [1] minor [2] milli [3] micro jpayne@69: * @stable ICU 2.0*/ jpayne@69: uint8_t dataVersion[4]; jpayne@69: } UDataInfo; jpayne@69: jpayne@69: /* API for reading data -----------------------------------------------------*/ jpayne@69: jpayne@69: /** jpayne@69: * Forward declaration of the data memory type. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef struct UDataMemory UDataMemory; jpayne@69: jpayne@69: /** jpayne@69: * Callback function for udata_openChoice(). jpayne@69: * @param context parameter passed into udata_openChoice(). jpayne@69: * @param type The type of the data as passed into udata_openChoice(). jpayne@69: * It may be NULL. jpayne@69: * @param name The name of the data as passed into udata_openChoice(). jpayne@69: * @param pInfo A pointer to the UDataInfo structure jpayne@69: * of data that has been loaded and will be returned jpayne@69: * by udata_openChoice() if this function jpayne@69: * returns TRUE. jpayne@69: * @return TRUE if the current data memory is acceptable jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef UBool U_CALLCONV jpayne@69: UDataMemoryIsAcceptable(void *context, jpayne@69: const char *type, const char *name, jpayne@69: const UDataInfo *pInfo); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Convenience function. jpayne@69: * This function works the same as udata_openChoice jpayne@69: * except that any data that matches the type and name jpayne@69: * is assumed to be acceptable. jpayne@69: * @param path Specifies an absolute path and/or a basename for the jpayne@69: * finding of the data in the file system. jpayne@69: * NULL for ICU data. jpayne@69: * @param type A string that specifies the type of data to be loaded. jpayne@69: * For example, resource bundles are loaded with type "res", jpayne@69: * conversion tables with type "cnv". jpayne@69: * This may be NULL or empty. jpayne@69: * @param name A string that specifies the name of the data. jpayne@69: * @param pErrorCode An ICU UErrorCode parameter. It must not be NULL. jpayne@69: * @return A pointer (handle) to a data memory object, or NULL jpayne@69: * if an error occurs. Call udata_getMemory() jpayne@69: * to get a pointer to the actual data. jpayne@69: * jpayne@69: * @see udata_openChoice jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UDataMemory * U_EXPORT2 jpayne@69: udata_open(const char *path, const char *type, const char *name, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Data loading function. jpayne@69: * This function is used to find and load efficiently data for jpayne@69: * ICU and applications using ICU. jpayne@69: * It provides an abstract interface that allows to specify a data jpayne@69: * type and name to find and load the data. jpayne@69: * jpayne@69: *

The implementation depends on platform properties and user preferences jpayne@69: * and may involve loading shared libraries (DLLs), mapping jpayne@69: * files into memory, or fopen()/fread() files. jpayne@69: * It may also involve using static memory or database queries etc. jpayne@69: * Several or all data items may be combined into one entity jpayne@69: * (DLL, memory-mappable file).

jpayne@69: * jpayne@69: *

The data is always preceded by a header that includes jpayne@69: * a UDataInfo structure. jpayne@69: * The caller's isAcceptable() function is called to make jpayne@69: * sure that the data is useful. It may be called several times if it jpayne@69: * rejects the data and there is more than one location with data jpayne@69: * matching the type and name.

jpayne@69: * jpayne@69: *

If path==NULL, then ICU data is loaded. jpayne@69: * Otherwise, it is separated into a basename and a basename-less directory string. jpayne@69: * The basename is used as the data package name, and the directory is jpayne@69: * logically prepended to the ICU data directory string.

jpayne@69: * jpayne@69: *

For details about ICU data loading see the User Guide jpayne@69: * Data Management chapter. (http://icu-project.org/userguide/icudata.html)

jpayne@69: * jpayne@69: * @param path Specifies an absolute path and/or a basename for the jpayne@69: * finding of the data in the file system. jpayne@69: * NULL for ICU data. jpayne@69: * @param type A string that specifies the type of data to be loaded. jpayne@69: * For example, resource bundles are loaded with type "res", jpayne@69: * conversion tables with type "cnv". jpayne@69: * This may be NULL or empty. jpayne@69: * @param name A string that specifies the name of the data. jpayne@69: * @param isAcceptable This function is called to verify that loaded data jpayne@69: * is useful for the client code. If it returns FALSE jpayne@69: * for all data items, then udata_openChoice() jpayne@69: * will return with an error. jpayne@69: * @param context Arbitrary parameter to be passed into isAcceptable. jpayne@69: * @param pErrorCode An ICU UErrorCode parameter. It must not be NULL. jpayne@69: * @return A pointer (handle) to a data memory object, or NULL jpayne@69: * if an error occurs. Call udata_getMemory() jpayne@69: * to get a pointer to the actual data. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UDataMemory * U_EXPORT2 jpayne@69: udata_openChoice(const char *path, const char *type, const char *name, jpayne@69: UDataMemoryIsAcceptable *isAcceptable, void *context, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Close the data memory. jpayne@69: * This function must be called to allow the system to jpayne@69: * release resources associated with this data memory. jpayne@69: * @param pData The pointer to data memory object jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: udata_close(UDataMemory *pData); jpayne@69: jpayne@69: /** jpayne@69: * Get the pointer to the actual data inside the data memory. jpayne@69: * The data is read-only. jpayne@69: * jpayne@69: * ICU data must be at least 8-aligned, and should be 16-aligned. jpayne@69: * jpayne@69: * @param pData The pointer to data memory object jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const void * U_EXPORT2 jpayne@69: udata_getMemory(UDataMemory *pData); jpayne@69: jpayne@69: /** jpayne@69: * Get the information from the data memory header. jpayne@69: * This allows to get access to the header containing jpayne@69: * platform data properties etc. which is not part of jpayne@69: * the data itself and can therefore not be accessed jpayne@69: * via the pointer that udata_getMemory() returns. jpayne@69: * jpayne@69: * @param pData pointer to the data memory object jpayne@69: * @param pInfo pointer to a UDataInfo object; jpayne@69: * its size field must be set correctly, jpayne@69: * typically to sizeof(UDataInfo). jpayne@69: * jpayne@69: * *pInfo will be filled with the UDataInfo structure jpayne@69: * in the data memory object. If this structure is smaller than jpayne@69: * pInfo->size, then the size will be jpayne@69: * adjusted and only part of the structure will be filled. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: udata_getInfo(UDataMemory *pData, UDataInfo *pInfo); jpayne@69: jpayne@69: /** jpayne@69: * This function bypasses the normal ICU data loading process and jpayne@69: * allows you to force ICU's system data to come out of a user-specified jpayne@69: * area in memory. jpayne@69: * jpayne@69: * ICU data must be at least 8-aligned, and should be 16-aligned. jpayne@69: * See http://userguide.icu-project.org/icudata jpayne@69: * jpayne@69: * The format of this data is that of the icu common data file, as is jpayne@69: * generated by the pkgdata tool with mode=common or mode=dll. jpayne@69: * You can read in a whole common mode file and pass the address to the start of the jpayne@69: * data, or (with the appropriate link options) pass in the pointer to jpayne@69: * the data that has been loaded from a dll by the operating system, jpayne@69: * as shown in this code: jpayne@69: * jpayne@69: * extern const char U_IMPORT U_ICUDATA_ENTRY_POINT []; jpayne@69: * // U_ICUDATA_ENTRY_POINT is same as entry point specified to pkgdata tool jpayne@69: * UErrorCode status = U_ZERO_ERROR; jpayne@69: * jpayne@69: * udata_setCommonData(&U_ICUDATA_ENTRY_POINT, &status); jpayne@69: * jpayne@69: * It is important that the declaration be as above. The entry point jpayne@69: * must not be declared as an extern void*. jpayne@69: * jpayne@69: * Starting with ICU 4.4, it is possible to set several data packages, jpayne@69: * one per call to this function. jpayne@69: * udata_open() will look for data in the multiple data packages in the order jpayne@69: * in which they were set. jpayne@69: * The position of the linked-in or default-name ICU .data package in the jpayne@69: * search list depends on when the first data item is loaded that is not contained jpayne@69: * in the already explicitly set packages. jpayne@69: * If data was loaded implicitly before the first call to this function jpayne@69: * (for example, via opening a converter, constructing a UnicodeString jpayne@69: * from default-codepage data, using formatting or collation APIs, etc.), jpayne@69: * then the default data will be first in the list. jpayne@69: * jpayne@69: * This function has no effect on application (non ICU) data. See udata_setAppData() jpayne@69: * for similar functionality for application data. jpayne@69: * jpayne@69: * @param data pointer to ICU common data jpayne@69: * @param err outgoing error status U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: udata_setCommonData(const void *data, UErrorCode *err); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * This function bypasses the normal ICU data loading process for application-specific jpayne@69: * data and allows you to force the it to come out of a user-specified jpayne@69: * pointer. jpayne@69: * jpayne@69: * ICU data must be at least 8-aligned, and should be 16-aligned. jpayne@69: * See http://userguide.icu-project.org/icudata jpayne@69: * jpayne@69: * The format of this data is that of the icu common data file, like 'icudt26l.dat' jpayne@69: * or the corresponding shared library (DLL) file. jpayne@69: * The application must read in or otherwise construct an image of the data and then jpayne@69: * pass the address of it to this function. jpayne@69: * jpayne@69: * jpayne@69: * Warning: setAppData will set a U_USING_DEFAULT_WARNING code if jpayne@69: * data with the specifed path that has already been opened, or jpayne@69: * if setAppData with the same path has already been called. jpayne@69: * Any such calls to setAppData will have no effect. jpayne@69: * jpayne@69: * jpayne@69: * @param packageName the package name by which the application will refer jpayne@69: * to (open) this data jpayne@69: * @param data pointer to the data jpayne@69: * @param err outgoing error status U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR jpayne@69: * @see udata_setCommonData jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: udata_setAppData(const char *packageName, const void *data, UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Possible settings for udata_setFileAccess() jpayne@69: * @see udata_setFileAccess jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: typedef enum UDataFileAccess { jpayne@69: /** ICU looks for data in single files first, then in packages. (default) @stable ICU 3.4 */ jpayne@69: UDATA_FILES_FIRST, jpayne@69: /** An alias for the default access mode. @stable ICU 3.4 */ jpayne@69: UDATA_DEFAULT_ACCESS = UDATA_FILES_FIRST, jpayne@69: /** ICU only loads data from packages, not from single files. @stable ICU 3.4 */ jpayne@69: UDATA_ONLY_PACKAGES, jpayne@69: /** ICU loads data from packages first, and only from single files jpayne@69: if the data cannot be found in a package. @stable ICU 3.4 */ jpayne@69: UDATA_PACKAGES_FIRST, jpayne@69: /** ICU does not access the file system for data loading. @stable ICU 3.4 */ jpayne@69: UDATA_NO_FILES, jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Number of real UDataFileAccess values. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UDATA_FILE_ACCESS_COUNT jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: } UDataFileAccess; jpayne@69: jpayne@69: /** jpayne@69: * This function may be called to control how ICU loads data. It must be called jpayne@69: * before any ICU data is loaded, including application data loaded with jpayne@69: * ures/ResourceBundle or udata APIs. This function is not multithread safe. jpayne@69: * The results of calling it while other threads are loading data are undefined. jpayne@69: * @param access The type of file access to be used jpayne@69: * @param status Error code. jpayne@69: * @see UDataFileAccess jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: udata_setFileAccess(UDataFileAccess access, UErrorCode *status); jpayne@69: jpayne@69: U_CDECL_END jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \class LocalUDataMemoryPointer jpayne@69: * "Smart pointer" class, closes a UDataMemory via udata_close(). jpayne@69: * For most methods see the LocalPointerBase base class. jpayne@69: * jpayne@69: * @see LocalPointerBase jpayne@69: * @see LocalPointer jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: U_DEFINE_LOCAL_OPEN_POINTER(LocalUDataMemoryPointer, UDataMemory, udata_close); jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif // U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #endif