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: udata.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 1999oct25 michael@0: * created by: Markus W. Scherer michael@0: */ michael@0: michael@0: #ifndef __UDATA_H__ michael@0: #define __UDATA_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/localpointer.h" michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Data loading interface michael@0: * michael@0: *
This structure may grow in the future, indicated by the
michael@0: * size
field.
The platform data property fields help determine if a data michael@0: * file can be efficiently used on a given machine. michael@0: * The particular fields are of importance only if the data michael@0: * is affected by the properties - if there is integer data michael@0: * with word sizes > 1 byte, char* text, or UChar* text.
michael@0: * michael@0: *The implementation for the udata_open[Choice]()
michael@0: * functions may reject data based on the value in isBigEndian
.
michael@0: * No other field is used by the udata
API implementation.
The dataFormat
may be used to identify
michael@0: * the kind of data, e.g. a converter table.
The formatVersion
field should be used to
michael@0: * make sure that the format can be interpreted.
michael@0: * I may be a good idea to check only for the one or two highest
michael@0: * of the version elements to allow the data memory to
michael@0: * get more or somewhat rearranged contents, for as long
michael@0: * as the using code can still interpret the older contents.
The dataVersion
field is intended to be a
michael@0: * common place to store the source version of the data;
michael@0: * for data from the Unicode character database, this could
michael@0: * reflect the Unicode version.
udata_openChoice()
.
michael@0: * @param type The type of the data as passed into udata_openChoice()
.
michael@0: * It may be NULL
.
michael@0: * @param name The name of the data as passed into udata_openChoice()
.
michael@0: * @param pInfo A pointer to the UDataInfo
structure
michael@0: * of data that has been loaded and will be returned
michael@0: * by udata_openChoice()
if this function
michael@0: * returns TRUE
.
michael@0: * @return TRUE if the current data memory is acceptable
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: typedef UBool U_CALLCONV
michael@0: UDataMemoryIsAcceptable(void *context,
michael@0: const char *type, const char *name,
michael@0: const UDataInfo *pInfo);
michael@0:
michael@0:
michael@0: /**
michael@0: * Convenience function.
michael@0: * This function works the same as udata_openChoice
michael@0: * except that any data that matches the type and name
michael@0: * is assumed to be acceptable.
michael@0: * @param path Specifies an absolute path and/or a basename for the
michael@0: * finding of the data in the file system.
michael@0: * NULL
for ICU data.
michael@0: * @param type A string that specifies the type of data to be loaded.
michael@0: * For example, resource bundles are loaded with type "res",
michael@0: * conversion tables with type "cnv".
michael@0: * This may be NULL
or empty.
michael@0: * @param name A string that specifies the name of the data.
michael@0: * @param pErrorCode An ICU UErrorCode parameter. It must not be NULL
.
michael@0: * @return A pointer (handle) to a data memory object, or NULL
michael@0: * if an error occurs. Call udata_getMemory()
michael@0: * to get a pointer to the actual data.
michael@0: *
michael@0: * @see udata_openChoice
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UDataMemory * U_EXPORT2
michael@0: udata_open(const char *path, const char *type, const char *name,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Data loading function.
michael@0: * This function is used to find and load efficiently data for
michael@0: * ICU and applications using ICU.
michael@0: * It provides an abstract interface that allows to specify a data
michael@0: * type and name to find and load the data.
michael@0: *
michael@0: * The implementation depends on platform properties and user preferences michael@0: * and may involve loading shared libraries (DLLs), mapping michael@0: * files into memory, or fopen()/fread() files. michael@0: * It may also involve using static memory or database queries etc. michael@0: * Several or all data items may be combined into one entity michael@0: * (DLL, memory-mappable file).
michael@0: * michael@0: *The data is always preceded by a header that includes
michael@0: * a UDataInfo
structure.
michael@0: * The caller's isAcceptable()
function is called to make
michael@0: * sure that the data is useful. It may be called several times if it
michael@0: * rejects the data and there is more than one location with data
michael@0: * matching the type and name.
If path==NULL
, then ICU data is loaded.
michael@0: * Otherwise, it is separated into a basename and a basename-less directory string.
michael@0: * The basename is used as the data package name, and the directory is
michael@0: * logically prepended to the ICU data directory string.
For details about ICU data loading see the User Guide michael@0: * Data Management chapter. (http://icu-project.org/userguide/icudata.html)
michael@0: * michael@0: * @param path Specifies an absolute path and/or a basename for the michael@0: * finding of the data in the file system. michael@0: *NULL
for ICU data.
michael@0: * @param type A string that specifies the type of data to be loaded.
michael@0: * For example, resource bundles are loaded with type "res",
michael@0: * conversion tables with type "cnv".
michael@0: * This may be NULL
or empty.
michael@0: * @param name A string that specifies the name of the data.
michael@0: * @param isAcceptable This function is called to verify that loaded data
michael@0: * is useful for the client code. If it returns FALSE
michael@0: * for all data items, then udata_openChoice()
michael@0: * will return with an error.
michael@0: * @param context Arbitrary parameter to be passed into isAcceptable.
michael@0: * @param pErrorCode An ICU UErrorCode parameter. It must not be NULL
.
michael@0: * @return A pointer (handle) to a data memory object, or NULL
michael@0: * if an error occurs. Call udata_getMemory()
michael@0: * to get a pointer to the actual data.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UDataMemory * U_EXPORT2
michael@0: udata_openChoice(const char *path, const char *type, const char *name,
michael@0: UDataMemoryIsAcceptable *isAcceptable, void *context,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Close the data memory.
michael@0: * This function must be called to allow the system to
michael@0: * release resources associated with this data memory.
michael@0: * @param pData The pointer to data memory object
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: udata_close(UDataMemory *pData);
michael@0:
michael@0: #if U_SHOW_CPLUSPLUS_API
michael@0:
michael@0: U_NAMESPACE_BEGIN
michael@0:
michael@0: /**
michael@0: * \class LocalUDataMemoryPointer
michael@0: * "Smart pointer" class, closes a UDataMemory via udata_close().
michael@0: * For most methods see the LocalPointerBase base class.
michael@0: *
michael@0: * @see LocalPointerBase
michael@0: * @see LocalPointer
michael@0: * @stable ICU 4.4
michael@0: */
michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUDataMemoryPointer, UDataMemory, udata_close);
michael@0:
michael@0: U_NAMESPACE_END
michael@0:
michael@0: #endif
michael@0:
michael@0: /**
michael@0: * Get the pointer to the actual data inside the data memory.
michael@0: * The data is read-only.
michael@0: * @param pData The pointer to data memory object
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE const void * U_EXPORT2
michael@0: udata_getMemory(UDataMemory *pData);
michael@0:
michael@0: /**
michael@0: * Get the information from the data memory header.
michael@0: * This allows to get access to the header containing
michael@0: * platform data properties etc. which is not part of
michael@0: * the data itself and can therefore not be accessed
michael@0: * via the pointer that udata_getMemory()
returns.
michael@0: *
michael@0: * @param pData pointer to the data memory object
michael@0: * @param pInfo pointer to a UDataInfo object;
michael@0: * its size
field must be set correctly,
michael@0: * typically to sizeof(UDataInfo)
.
michael@0: *
michael@0: * *pInfo
will be filled with the UDataInfo structure
michael@0: * in the data memory object. If this structure is smaller than
michael@0: * pInfo->size
, then the size
will be
michael@0: * adjusted and only part of the structure will be filled.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: udata_getInfo(UDataMemory *pData, UDataInfo *pInfo);
michael@0:
michael@0: /**
michael@0: * This function bypasses the normal ICU data loading process and
michael@0: * allows you to force ICU's system data to come out of a user-specified
michael@0: * area in memory.
michael@0: *
michael@0: * The format of this data is that of the icu common data file, as is
michael@0: * generated by the pkgdata tool with mode=common or mode=dll.
michael@0: * You can read in a whole common mode file and pass the address to the start of the
michael@0: * data, or (with the appropriate link options) pass in the pointer to
michael@0: * the data that has been loaded from a dll by the operating system,
michael@0: * as shown in this code:
michael@0: *
michael@0: * extern const char U_IMPORT U_ICUDATA_ENTRY_POINT [];
michael@0: * // U_ICUDATA_ENTRY_POINT is same as entry point specified to pkgdata tool
michael@0: * UErrorCode status = U_ZERO_ERROR;
michael@0: *
michael@0: * udata_setCommonData(&U_ICUDATA_ENTRY_POINT, &status);
michael@0: *
michael@0: * It is important that the declaration be as above. The entry point
michael@0: * must not be declared as an extern void*.
michael@0: *
michael@0: * Starting with ICU 4.4, it is possible to set several data packages,
michael@0: * one per call to this function.
michael@0: * udata_open() will look for data in the multiple data packages in the order
michael@0: * in which they were set.
michael@0: * The position of the linked-in or default-name ICU .data package in the
michael@0: * search list depends on when the first data item is loaded that is not contained
michael@0: * in the already explicitly set packages.
michael@0: * If data was loaded implicitly before the first call to this function
michael@0: * (for example, via opening a converter, constructing a UnicodeString
michael@0: * from default-codepage data, using formatting or collation APIs, etc.),
michael@0: * then the default data will be first in the list.
michael@0: *
michael@0: * This function has no effect on application (non ICU) data. See udata_setAppData()
michael@0: * for similar functionality for application data.
michael@0: *
michael@0: * @param data pointer to ICU common data
michael@0: * @param err outgoing error status U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: udata_setCommonData(const void *data, UErrorCode *err);
michael@0:
michael@0:
michael@0: /**
michael@0: * This function bypasses the normal ICU data loading process for application-specific
michael@0: * data and allows you to force the it to come out of a user-specified
michael@0: * pointer.
michael@0: *
michael@0: * The format of this data is that of the icu common data file, like 'icudt26l.dat'
michael@0: * or the corresponding shared library (DLL) file.
michael@0: * The application must read in or otherwise construct an image of the data and then
michael@0: * pass the address of it to this function.
michael@0: *
michael@0: *
michael@0: * Warning: setAppData will set a U_USING_DEFAULT_WARNING code if
michael@0: * data with the specifed path that has already been opened, or
michael@0: * if setAppData with the same path has already been called.
michael@0: * Any such calls to setAppData will have no effect.
michael@0: *
michael@0: *
michael@0: * @param packageName the package name by which the application will refer
michael@0: * to (open) this data
michael@0: * @param data pointer to the data
michael@0: * @param err outgoing error status U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR
michael@0: * @see udata_setCommonData
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: udata_setAppData(const char *packageName, const void *data, UErrorCode *err);
michael@0:
michael@0: /**
michael@0: * Possible settings for udata_setFileAccess()
michael@0: * @see udata_setFileAccess
michael@0: * @stable ICU 3.4
michael@0: */
michael@0: typedef enum UDataFileAccess {
michael@0: /** ICU looks for data in single files first, then in packages. (default) @stable ICU 3.4 */
michael@0: UDATA_FILES_FIRST,
michael@0: /** An alias for the default access mode. @stable ICU 3.4 */
michael@0: UDATA_DEFAULT_ACCESS = UDATA_FILES_FIRST,
michael@0: /** ICU only loads data from packages, not from single files. @stable ICU 3.4 */
michael@0: UDATA_ONLY_PACKAGES,
michael@0: /** ICU loads data from packages first, and only from single files
michael@0: if the data cannot be found in a package. @stable ICU 3.4 */
michael@0: UDATA_PACKAGES_FIRST,
michael@0: /** ICU does not access the file system for data loading. @stable ICU 3.4 */
michael@0: UDATA_NO_FILES,
michael@0: /** Number of real UDataFileAccess values. @stable ICU 3.4 */
michael@0: UDATA_FILE_ACCESS_COUNT
michael@0: } UDataFileAccess;
michael@0:
michael@0: /**
michael@0: * This function may be called to control how ICU loads data. It must be called
michael@0: * before any ICU data is loaded, including application data loaded with
michael@0: * ures/ResourceBundle or udata APIs. This function is not multithread safe.
michael@0: * The results of calling it while other threads are loading data are undefined.
michael@0: * @param access The type of file access to be used
michael@0: * @param status Error code.
michael@0: * @see UDataFileAccess
michael@0: * @stable ICU 3.4
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: udata_setFileAccess(UDataFileAccess access, UErrorCode *status);
michael@0:
michael@0: U_CDECL_END
michael@0:
michael@0: #endif