intl/icu/source/common/unicode/udata.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1999-2012, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 ******************************************************************************
michael@0 8 * file name: udata.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 1999oct25
michael@0 14 * created by: Markus W. Scherer
michael@0 15 */
michael@0 16
michael@0 17 #ifndef __UDATA_H__
michael@0 18 #define __UDATA_H__
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21 #include "unicode/localpointer.h"
michael@0 22
michael@0 23 U_CDECL_BEGIN
michael@0 24
michael@0 25 /**
michael@0 26 * \file
michael@0 27 * \brief C API: Data loading interface
michael@0 28 *
michael@0 29 * <h2>Information about data loading interface</h2>
michael@0 30 *
michael@0 31 * This API is used to find and efficiently load data for ICU and applications
michael@0 32 * using ICU. It provides an abstract interface that specifies a data type and
michael@0 33 * name to find and load the data. Normally this API is used by other ICU APIs
michael@0 34 * to load required data out of the ICU data library, but it can be used to
michael@0 35 * load data out of other places.
michael@0 36 *
michael@0 37 * See the User Guide Data Management chapter.
michael@0 38 */
michael@0 39
michael@0 40 #ifndef U_HIDE_INTERNAL_API
michael@0 41 /**
michael@0 42 * Character used to separate package names from tree names
michael@0 43 * @internal ICU 3.0
michael@0 44 */
michael@0 45 #define U_TREE_SEPARATOR '-'
michael@0 46
michael@0 47 /**
michael@0 48 * String used to separate package names from tree names
michael@0 49 * @internal ICU 3.0
michael@0 50 */
michael@0 51 #define U_TREE_SEPARATOR_STRING "-"
michael@0 52
michael@0 53 /**
michael@0 54 * Character used to separate parts of entry names
michael@0 55 * @internal ICU 3.0
michael@0 56 */
michael@0 57 #define U_TREE_ENTRY_SEP_CHAR '/'
michael@0 58
michael@0 59 /**
michael@0 60 * String used to separate parts of entry names
michael@0 61 * @internal ICU 3.0
michael@0 62 */
michael@0 63 #define U_TREE_ENTRY_SEP_STRING "/"
michael@0 64
michael@0 65 /**
michael@0 66 * Alias for standard ICU data
michael@0 67 * @internal ICU 3.0
michael@0 68 */
michael@0 69 #define U_ICUDATA_ALIAS "ICUDATA"
michael@0 70
michael@0 71 #endif /* U_HIDE_INTERNAL_API */
michael@0 72
michael@0 73 /**
michael@0 74 * UDataInfo contains the properties about the requested data.
michael@0 75 * This is meta data.
michael@0 76 *
michael@0 77 * <p>This structure may grow in the future, indicated by the
michael@0 78 * <code>size</code> field.</p>
michael@0 79 *
michael@0 80 * <p>The platform data property fields help determine if a data
michael@0 81 * file can be efficiently used on a given machine.
michael@0 82 * The particular fields are of importance only if the data
michael@0 83 * is affected by the properties - if there is integer data
michael@0 84 * with word sizes > 1 byte, char* text, or UChar* text.</p>
michael@0 85 *
michael@0 86 * <p>The implementation for the <code>udata_open[Choice]()</code>
michael@0 87 * functions may reject data based on the value in <code>isBigEndian</code>.
michael@0 88 * No other field is used by the <code>udata</code> API implementation.</p>
michael@0 89 *
michael@0 90 * <p>The <code>dataFormat</code> may be used to identify
michael@0 91 * the kind of data, e.g. a converter table.</p>
michael@0 92 *
michael@0 93 * <p>The <code>formatVersion</code> field should be used to
michael@0 94 * make sure that the format can be interpreted.
michael@0 95 * I may be a good idea to check only for the one or two highest
michael@0 96 * of the version elements to allow the data memory to
michael@0 97 * get more or somewhat rearranged contents, for as long
michael@0 98 * as the using code can still interpret the older contents.</p>
michael@0 99 *
michael@0 100 * <p>The <code>dataVersion</code> field is intended to be a
michael@0 101 * common place to store the source version of the data;
michael@0 102 * for data from the Unicode character database, this could
michael@0 103 * reflect the Unicode version.</p>
michael@0 104 * @stable ICU 2.0
michael@0 105 */
michael@0 106 typedef struct {
michael@0 107 /** sizeof(UDataInfo)
michael@0 108 * @stable ICU 2.0 */
michael@0 109 uint16_t size;
michael@0 110
michael@0 111 /** unused, set to 0
michael@0 112 * @stable ICU 2.0*/
michael@0 113 uint16_t reservedWord;
michael@0 114
michael@0 115 /* platform data properties */
michael@0 116 /** 0 for little-endian machine, 1 for big-endian
michael@0 117 * @stable ICU 2.0 */
michael@0 118 uint8_t isBigEndian;
michael@0 119
michael@0 120 /** see U_CHARSET_FAMILY values in utypes.h
michael@0 121 * @stable ICU 2.0*/
michael@0 122 uint8_t charsetFamily;
michael@0 123
michael@0 124 /** sizeof(UChar), one of { 1, 2, 4 }
michael@0 125 * @stable ICU 2.0*/
michael@0 126 uint8_t sizeofUChar;
michael@0 127
michael@0 128 /** unused, set to 0
michael@0 129 * @stable ICU 2.0*/
michael@0 130 uint8_t reservedByte;
michael@0 131
michael@0 132 /** data format identifier
michael@0 133 * @stable ICU 2.0*/
michael@0 134 uint8_t dataFormat[4];
michael@0 135
michael@0 136 /** versions: [0] major [1] minor [2] milli [3] micro
michael@0 137 * @stable ICU 2.0*/
michael@0 138 uint8_t formatVersion[4];
michael@0 139
michael@0 140 /** versions: [0] major [1] minor [2] milli [3] micro
michael@0 141 * @stable ICU 2.0*/
michael@0 142 uint8_t dataVersion[4];
michael@0 143 } UDataInfo;
michael@0 144
michael@0 145 /* API for reading data -----------------------------------------------------*/
michael@0 146
michael@0 147 /**
michael@0 148 * Forward declaration of the data memory type.
michael@0 149 * @stable ICU 2.0
michael@0 150 */
michael@0 151 typedef struct UDataMemory UDataMemory;
michael@0 152
michael@0 153 /**
michael@0 154 * Callback function for udata_openChoice().
michael@0 155 * @param context parameter passed into <code>udata_openChoice()</code>.
michael@0 156 * @param type The type of the data as passed into <code>udata_openChoice()</code>.
michael@0 157 * It may be <code>NULL</code>.
michael@0 158 * @param name The name of the data as passed into <code>udata_openChoice()</code>.
michael@0 159 * @param pInfo A pointer to the <code>UDataInfo</code> structure
michael@0 160 * of data that has been loaded and will be returned
michael@0 161 * by <code>udata_openChoice()</code> if this function
michael@0 162 * returns <code>TRUE</code>.
michael@0 163 * @return TRUE if the current data memory is acceptable
michael@0 164 * @stable ICU 2.0
michael@0 165 */
michael@0 166 typedef UBool U_CALLCONV
michael@0 167 UDataMemoryIsAcceptable(void *context,
michael@0 168 const char *type, const char *name,
michael@0 169 const UDataInfo *pInfo);
michael@0 170
michael@0 171
michael@0 172 /**
michael@0 173 * Convenience function.
michael@0 174 * This function works the same as <code>udata_openChoice</code>
michael@0 175 * except that any data that matches the type and name
michael@0 176 * is assumed to be acceptable.
michael@0 177 * @param path Specifies an absolute path and/or a basename for the
michael@0 178 * finding of the data in the file system.
michael@0 179 * <code>NULL</code> for ICU data.
michael@0 180 * @param type A string that specifies the type of data to be loaded.
michael@0 181 * For example, resource bundles are loaded with type "res",
michael@0 182 * conversion tables with type "cnv".
michael@0 183 * This may be <code>NULL</code> or empty.
michael@0 184 * @param name A string that specifies the name of the data.
michael@0 185 * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>.
michael@0 186 * @return A pointer (handle) to a data memory object, or <code>NULL</code>
michael@0 187 * if an error occurs. Call <code>udata_getMemory()</code>
michael@0 188 * to get a pointer to the actual data.
michael@0 189 *
michael@0 190 * @see udata_openChoice
michael@0 191 * @stable ICU 2.0
michael@0 192 */
michael@0 193 U_STABLE UDataMemory * U_EXPORT2
michael@0 194 udata_open(const char *path, const char *type, const char *name,
michael@0 195 UErrorCode *pErrorCode);
michael@0 196
michael@0 197 /**
michael@0 198 * Data loading function.
michael@0 199 * This function is used to find and load efficiently data for
michael@0 200 * ICU and applications using ICU.
michael@0 201 * It provides an abstract interface that allows to specify a data
michael@0 202 * type and name to find and load the data.
michael@0 203 *
michael@0 204 * <p>The implementation depends on platform properties and user preferences
michael@0 205 * and may involve loading shared libraries (DLLs), mapping
michael@0 206 * files into memory, or fopen()/fread() files.
michael@0 207 * It may also involve using static memory or database queries etc.
michael@0 208 * Several or all data items may be combined into one entity
michael@0 209 * (DLL, memory-mappable file).</p>
michael@0 210 *
michael@0 211 * <p>The data is always preceded by a header that includes
michael@0 212 * a <code>UDataInfo</code> structure.
michael@0 213 * The caller's <code>isAcceptable()</code> function is called to make
michael@0 214 * sure that the data is useful. It may be called several times if it
michael@0 215 * rejects the data and there is more than one location with data
michael@0 216 * matching the type and name.</p>
michael@0 217 *
michael@0 218 * <p>If <code>path==NULL</code>, then ICU data is loaded.
michael@0 219 * Otherwise, it is separated into a basename and a basename-less directory string.
michael@0 220 * The basename is used as the data package name, and the directory is
michael@0 221 * logically prepended to the ICU data directory string.</p>
michael@0 222 *
michael@0 223 * <p>For details about ICU data loading see the User Guide
michael@0 224 * Data Management chapter. (http://icu-project.org/userguide/icudata.html)</p>
michael@0 225 *
michael@0 226 * @param path Specifies an absolute path and/or a basename for the
michael@0 227 * finding of the data in the file system.
michael@0 228 * <code>NULL</code> for ICU data.
michael@0 229 * @param type A string that specifies the type of data to be loaded.
michael@0 230 * For example, resource bundles are loaded with type "res",
michael@0 231 * conversion tables with type "cnv".
michael@0 232 * This may be <code>NULL</code> or empty.
michael@0 233 * @param name A string that specifies the name of the data.
michael@0 234 * @param isAcceptable This function is called to verify that loaded data
michael@0 235 * is useful for the client code. If it returns FALSE
michael@0 236 * for all data items, then <code>udata_openChoice()</code>
michael@0 237 * will return with an error.
michael@0 238 * @param context Arbitrary parameter to be passed into isAcceptable.
michael@0 239 * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>.
michael@0 240 * @return A pointer (handle) to a data memory object, or <code>NULL</code>
michael@0 241 * if an error occurs. Call <code>udata_getMemory()</code>
michael@0 242 * to get a pointer to the actual data.
michael@0 243 * @stable ICU 2.0
michael@0 244 */
michael@0 245 U_STABLE UDataMemory * U_EXPORT2
michael@0 246 udata_openChoice(const char *path, const char *type, const char *name,
michael@0 247 UDataMemoryIsAcceptable *isAcceptable, void *context,
michael@0 248 UErrorCode *pErrorCode);
michael@0 249
michael@0 250 /**
michael@0 251 * Close the data memory.
michael@0 252 * This function must be called to allow the system to
michael@0 253 * release resources associated with this data memory.
michael@0 254 * @param pData The pointer to data memory object
michael@0 255 * @stable ICU 2.0
michael@0 256 */
michael@0 257 U_STABLE void U_EXPORT2
michael@0 258 udata_close(UDataMemory *pData);
michael@0 259
michael@0 260 #if U_SHOW_CPLUSPLUS_API
michael@0 261
michael@0 262 U_NAMESPACE_BEGIN
michael@0 263
michael@0 264 /**
michael@0 265 * \class LocalUDataMemoryPointer
michael@0 266 * "Smart pointer" class, closes a UDataMemory via udata_close().
michael@0 267 * For most methods see the LocalPointerBase base class.
michael@0 268 *
michael@0 269 * @see LocalPointerBase
michael@0 270 * @see LocalPointer
michael@0 271 * @stable ICU 4.4
michael@0 272 */
michael@0 273 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDataMemoryPointer, UDataMemory, udata_close);
michael@0 274
michael@0 275 U_NAMESPACE_END
michael@0 276
michael@0 277 #endif
michael@0 278
michael@0 279 /**
michael@0 280 * Get the pointer to the actual data inside the data memory.
michael@0 281 * The data is read-only.
michael@0 282 * @param pData The pointer to data memory object
michael@0 283 * @stable ICU 2.0
michael@0 284 */
michael@0 285 U_STABLE const void * U_EXPORT2
michael@0 286 udata_getMemory(UDataMemory *pData);
michael@0 287
michael@0 288 /**
michael@0 289 * Get the information from the data memory header.
michael@0 290 * This allows to get access to the header containing
michael@0 291 * platform data properties etc. which is not part of
michael@0 292 * the data itself and can therefore not be accessed
michael@0 293 * via the pointer that <code>udata_getMemory()</code> returns.
michael@0 294 *
michael@0 295 * @param pData pointer to the data memory object
michael@0 296 * @param pInfo pointer to a UDataInfo object;
michael@0 297 * its <code>size</code> field must be set correctly,
michael@0 298 * typically to <code>sizeof(UDataInfo)</code>.
michael@0 299 *
michael@0 300 * <code>*pInfo</code> will be filled with the UDataInfo structure
michael@0 301 * in the data memory object. If this structure is smaller than
michael@0 302 * <code>pInfo->size</code>, then the <code>size</code> will be
michael@0 303 * adjusted and only part of the structure will be filled.
michael@0 304 * @stable ICU 2.0
michael@0 305 */
michael@0 306 U_STABLE void U_EXPORT2
michael@0 307 udata_getInfo(UDataMemory *pData, UDataInfo *pInfo);
michael@0 308
michael@0 309 /**
michael@0 310 * This function bypasses the normal ICU data loading process and
michael@0 311 * allows you to force ICU's system data to come out of a user-specified
michael@0 312 * area in memory.
michael@0 313 *
michael@0 314 * The format of this data is that of the icu common data file, as is
michael@0 315 * generated by the pkgdata tool with mode=common or mode=dll.
michael@0 316 * You can read in a whole common mode file and pass the address to the start of the
michael@0 317 * data, or (with the appropriate link options) pass in the pointer to
michael@0 318 * the data that has been loaded from a dll by the operating system,
michael@0 319 * as shown in this code:
michael@0 320 *
michael@0 321 * extern const char U_IMPORT U_ICUDATA_ENTRY_POINT [];
michael@0 322 * // U_ICUDATA_ENTRY_POINT is same as entry point specified to pkgdata tool
michael@0 323 * UErrorCode status = U_ZERO_ERROR;
michael@0 324 *
michael@0 325 * udata_setCommonData(&U_ICUDATA_ENTRY_POINT, &status);
michael@0 326 *
michael@0 327 * It is important that the declaration be as above. The entry point
michael@0 328 * must not be declared as an extern void*.
michael@0 329 *
michael@0 330 * Starting with ICU 4.4, it is possible to set several data packages,
michael@0 331 * one per call to this function.
michael@0 332 * udata_open() will look for data in the multiple data packages in the order
michael@0 333 * in which they were set.
michael@0 334 * The position of the linked-in or default-name ICU .data package in the
michael@0 335 * search list depends on when the first data item is loaded that is not contained
michael@0 336 * in the already explicitly set packages.
michael@0 337 * If data was loaded implicitly before the first call to this function
michael@0 338 * (for example, via opening a converter, constructing a UnicodeString
michael@0 339 * from default-codepage data, using formatting or collation APIs, etc.),
michael@0 340 * then the default data will be first in the list.
michael@0 341 *
michael@0 342 * This function has no effect on application (non ICU) data. See udata_setAppData()
michael@0 343 * for similar functionality for application data.
michael@0 344 *
michael@0 345 * @param data pointer to ICU common data
michael@0 346 * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code>
michael@0 347 * @stable ICU 2.0
michael@0 348 */
michael@0 349 U_STABLE void U_EXPORT2
michael@0 350 udata_setCommonData(const void *data, UErrorCode *err);
michael@0 351
michael@0 352
michael@0 353 /**
michael@0 354 * This function bypasses the normal ICU data loading process for application-specific
michael@0 355 * data and allows you to force the it to come out of a user-specified
michael@0 356 * pointer.
michael@0 357 *
michael@0 358 * The format of this data is that of the icu common data file, like 'icudt26l.dat'
michael@0 359 * or the corresponding shared library (DLL) file.
michael@0 360 * The application must read in or otherwise construct an image of the data and then
michael@0 361 * pass the address of it to this function.
michael@0 362 *
michael@0 363 *
michael@0 364 * Warning: setAppData will set a U_USING_DEFAULT_WARNING code if
michael@0 365 * data with the specifed path that has already been opened, or
michael@0 366 * if setAppData with the same path has already been called.
michael@0 367 * Any such calls to setAppData will have no effect.
michael@0 368 *
michael@0 369 *
michael@0 370 * @param packageName the package name by which the application will refer
michael@0 371 * to (open) this data
michael@0 372 * @param data pointer to the data
michael@0 373 * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code>
michael@0 374 * @see udata_setCommonData
michael@0 375 * @stable ICU 2.0
michael@0 376 */
michael@0 377 U_STABLE void U_EXPORT2
michael@0 378 udata_setAppData(const char *packageName, const void *data, UErrorCode *err);
michael@0 379
michael@0 380 /**
michael@0 381 * Possible settings for udata_setFileAccess()
michael@0 382 * @see udata_setFileAccess
michael@0 383 * @stable ICU 3.4
michael@0 384 */
michael@0 385 typedef enum UDataFileAccess {
michael@0 386 /** ICU looks for data in single files first, then in packages. (default) @stable ICU 3.4 */
michael@0 387 UDATA_FILES_FIRST,
michael@0 388 /** An alias for the default access mode. @stable ICU 3.4 */
michael@0 389 UDATA_DEFAULT_ACCESS = UDATA_FILES_FIRST,
michael@0 390 /** ICU only loads data from packages, not from single files. @stable ICU 3.4 */
michael@0 391 UDATA_ONLY_PACKAGES,
michael@0 392 /** ICU loads data from packages first, and only from single files
michael@0 393 if the data cannot be found in a package. @stable ICU 3.4 */
michael@0 394 UDATA_PACKAGES_FIRST,
michael@0 395 /** ICU does not access the file system for data loading. @stable ICU 3.4 */
michael@0 396 UDATA_NO_FILES,
michael@0 397 /** Number of real UDataFileAccess values. @stable ICU 3.4 */
michael@0 398 UDATA_FILE_ACCESS_COUNT
michael@0 399 } UDataFileAccess;
michael@0 400
michael@0 401 /**
michael@0 402 * This function may be called to control how ICU loads data. It must be called
michael@0 403 * before any ICU data is loaded, including application data loaded with
michael@0 404 * ures/ResourceBundle or udata APIs. This function is not multithread safe.
michael@0 405 * The results of calling it while other threads are loading data are undefined.
michael@0 406 * @param access The type of file access to be used
michael@0 407 * @param status Error code.
michael@0 408 * @see UDataFileAccess
michael@0 409 * @stable ICU 3.4
michael@0 410 */
michael@0 411 U_STABLE void U_EXPORT2
michael@0 412 udata_setFileAccess(UDataFileAccess access, UErrorCode *status);
michael@0 413
michael@0 414 U_CDECL_END
michael@0 415
michael@0 416 #endif

mercurial