|
||||
File indexing completed on 2025-01-18 10:13:11
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ****************************************************************************** 0005 * 0006 * Copyright (C) 1999-2014, International Business Machines 0007 * Corporation and others. All Rights Reserved. 0008 * 0009 ****************************************************************************** 0010 * file name: udata.h 0011 * encoding: UTF-8 0012 * tab size: 8 (not used) 0013 * indentation:4 0014 * 0015 * created on: 1999oct25 0016 * created by: Markus W. Scherer 0017 */ 0018 0019 #ifndef __UDATA_H__ 0020 #define __UDATA_H__ 0021 0022 #include "unicode/utypes.h" 0023 0024 #if U_SHOW_CPLUSPLUS_API 0025 #include "unicode/localpointer.h" 0026 #endif // U_SHOW_CPLUSPLUS_API 0027 0028 U_CDECL_BEGIN 0029 0030 /** 0031 * \file 0032 * \brief C API: Data loading interface 0033 * 0034 * <h2>Information about data loading interface</h2> 0035 * 0036 * This API is used to find and efficiently load data for ICU and applications 0037 * using ICU. It provides an abstract interface that specifies a data type and 0038 * name to find and load the data. Normally this API is used by other ICU APIs 0039 * to load required data out of the ICU data library, but it can be used to 0040 * load data out of other places. 0041 * 0042 * See the User Guide Data Management chapter. 0043 */ 0044 0045 #ifndef U_HIDE_INTERNAL_API 0046 /** 0047 * Character used to separate package names from tree names 0048 * @internal ICU 3.0 0049 */ 0050 #define U_TREE_SEPARATOR '-' 0051 0052 /** 0053 * String used to separate package names from tree names 0054 * @internal ICU 3.0 0055 */ 0056 #define U_TREE_SEPARATOR_STRING "-" 0057 0058 /** 0059 * Character used to separate parts of entry names 0060 * @internal ICU 3.0 0061 */ 0062 #define U_TREE_ENTRY_SEP_CHAR '/' 0063 0064 /** 0065 * String used to separate parts of entry names 0066 * @internal ICU 3.0 0067 */ 0068 #define U_TREE_ENTRY_SEP_STRING "/" 0069 0070 /** 0071 * Alias for standard ICU data 0072 * @internal ICU 3.0 0073 */ 0074 #define U_ICUDATA_ALIAS "ICUDATA" 0075 0076 #endif /* U_HIDE_INTERNAL_API */ 0077 0078 /** 0079 * UDataInfo contains the properties about the requested data. 0080 * This is meta data. 0081 * 0082 * <p>This structure may grow in the future, indicated by the 0083 * <code>size</code> field.</p> 0084 * 0085 * <p>ICU data must be at least 8-aligned, and should be 16-aligned. 0086 * The UDataInfo struct begins 4 bytes after the start of the data item, 0087 * so it is 4-aligned. 0088 * 0089 * <p>The platform data property fields help determine if a data 0090 * file can be efficiently used on a given machine. 0091 * The particular fields are of importance only if the data 0092 * is affected by the properties - if there is integer data 0093 * with word sizes > 1 byte, char* text, or UChar* text.</p> 0094 * 0095 * <p>The implementation for the <code>udata_open[Choice]()</code> 0096 * functions may reject data based on the value in <code>isBigEndian</code>. 0097 * No other field is used by the <code>udata</code> API implementation.</p> 0098 * 0099 * <p>The <code>dataFormat</code> may be used to identify 0100 * the kind of data, e.g. a converter table.</p> 0101 * 0102 * <p>The <code>formatVersion</code> field should be used to 0103 * make sure that the format can be interpreted. 0104 * It may be a good idea to check only for the one or two highest 0105 * of the version elements to allow the data memory to 0106 * get more or somewhat rearranged contents, for as long 0107 * as the using code can still interpret the older contents.</p> 0108 * 0109 * <p>The <code>dataVersion</code> field is intended to be a 0110 * common place to store the source version of the data; 0111 * for data from the Unicode character database, this could 0112 * reflect the Unicode version.</p> 0113 * 0114 * @stable ICU 2.0 0115 */ 0116 typedef struct { 0117 /** sizeof(UDataInfo) 0118 * @stable ICU 2.0 */ 0119 uint16_t size; 0120 0121 /** unused, set to 0 0122 * @stable ICU 2.0*/ 0123 uint16_t reservedWord; 0124 0125 /* platform data properties */ 0126 /** 0 for little-endian machine, 1 for big-endian 0127 * @stable ICU 2.0 */ 0128 uint8_t isBigEndian; 0129 0130 /** see U_CHARSET_FAMILY values in utypes.h 0131 * @stable ICU 2.0*/ 0132 uint8_t charsetFamily; 0133 0134 /** sizeof(UChar), one of { 1, 2, 4 } 0135 * @stable ICU 2.0*/ 0136 uint8_t sizeofUChar; 0137 0138 /** unused, set to 0 0139 * @stable ICU 2.0*/ 0140 uint8_t reservedByte; 0141 0142 /** data format identifier 0143 * @stable ICU 2.0*/ 0144 uint8_t dataFormat[4]; 0145 0146 /** versions: [0] major [1] minor [2] milli [3] micro 0147 * @stable ICU 2.0*/ 0148 uint8_t formatVersion[4]; 0149 0150 /** versions: [0] major [1] minor [2] milli [3] micro 0151 * @stable ICU 2.0*/ 0152 uint8_t dataVersion[4]; 0153 } UDataInfo; 0154 0155 /* API for reading data -----------------------------------------------------*/ 0156 0157 /** 0158 * Forward declaration of the data memory type. 0159 * @stable ICU 2.0 0160 */ 0161 typedef struct UDataMemory UDataMemory; 0162 0163 /** 0164 * Callback function for udata_openChoice(). 0165 * @param context parameter passed into <code>udata_openChoice()</code>. 0166 * @param type The type of the data as passed into <code>udata_openChoice()</code>. 0167 * It may be <code>NULL</code>. 0168 * @param name The name of the data as passed into <code>udata_openChoice()</code>. 0169 * @param pInfo A pointer to the <code>UDataInfo</code> structure 0170 * of data that has been loaded and will be returned 0171 * by <code>udata_openChoice()</code> if this function 0172 * returns <code>true</code>. 0173 * @return true if the current data memory is acceptable 0174 * @stable ICU 2.0 0175 */ 0176 typedef UBool U_CALLCONV 0177 UDataMemoryIsAcceptable(void *context, 0178 const char *type, const char *name, 0179 const UDataInfo *pInfo); 0180 0181 0182 /** 0183 * Convenience function. 0184 * This function works the same as <code>udata_openChoice</code> 0185 * except that any data that matches the type and name 0186 * is assumed to be acceptable. 0187 * @param path Specifies an absolute path and/or a basename for the 0188 * finding of the data in the file system. 0189 * <code>NULL</code> for ICU data. 0190 * @param type A string that specifies the type of data to be loaded. 0191 * For example, resource bundles are loaded with type "res", 0192 * conversion tables with type "cnv". 0193 * This may be <code>NULL</code> or empty. 0194 * @param name A string that specifies the name of the data. 0195 * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>. 0196 * @return A pointer (handle) to a data memory object, or <code>NULL</code> 0197 * if an error occurs. Call <code>udata_getMemory()</code> 0198 * to get a pointer to the actual data. 0199 * 0200 * @see udata_openChoice 0201 * @stable ICU 2.0 0202 */ 0203 U_CAPI UDataMemory * U_EXPORT2 0204 udata_open(const char *path, const char *type, const char *name, 0205 UErrorCode *pErrorCode); 0206 0207 /** 0208 * Data loading function. 0209 * This function is used to find and load efficiently data for 0210 * ICU and applications using ICU. 0211 * It provides an abstract interface that allows to specify a data 0212 * type and name to find and load the data. 0213 * 0214 * <p>The implementation depends on platform properties and user preferences 0215 * and may involve loading shared libraries (DLLs), mapping 0216 * files into memory, or fopen()/fread() files. 0217 * It may also involve using static memory or database queries etc. 0218 * Several or all data items may be combined into one entity 0219 * (DLL, memory-mappable file).</p> 0220 * 0221 * <p>The data is always preceded by a header that includes 0222 * a <code>UDataInfo</code> structure. 0223 * The caller's <code>isAcceptable()</code> function is called to make 0224 * sure that the data is useful. It may be called several times if it 0225 * rejects the data and there is more than one location with data 0226 * matching the type and name.</p> 0227 * 0228 * <p>If <code>path==NULL</code>, then ICU data is loaded. 0229 * Otherwise, it is separated into a basename and a basename-less directory string. 0230 * The basename is used as the data package name, and the directory is 0231 * logically prepended to the ICU data directory string.</p> 0232 * 0233 * <p>For details about ICU data loading see the User Guide 0234 * Data Management chapter. (https://unicode-org.github.io/icu/userguide/icu_data/)</p> 0235 * 0236 * @param path Specifies an absolute path and/or a basename for the 0237 * finding of the data in the file system. 0238 * <code>NULL</code> for ICU data. 0239 * @param type A string that specifies the type of data to be loaded. 0240 * For example, resource bundles are loaded with type "res", 0241 * conversion tables with type "cnv". 0242 * This may be <code>NULL</code> or empty. 0243 * @param name A string that specifies the name of the data. 0244 * @param isAcceptable This function is called to verify that loaded data 0245 * is useful for the client code. If it returns false 0246 * for all data items, then <code>udata_openChoice()</code> 0247 * will return with an error. 0248 * @param context Arbitrary parameter to be passed into isAcceptable. 0249 * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>. 0250 * @return A pointer (handle) to a data memory object, or <code>NULL</code> 0251 * if an error occurs. Call <code>udata_getMemory()</code> 0252 * to get a pointer to the actual data. 0253 * @stable ICU 2.0 0254 */ 0255 U_CAPI UDataMemory * U_EXPORT2 0256 udata_openChoice(const char *path, const char *type, const char *name, 0257 UDataMemoryIsAcceptable *isAcceptable, void *context, 0258 UErrorCode *pErrorCode); 0259 0260 /** 0261 * Close the data memory. 0262 * This function must be called to allow the system to 0263 * release resources associated with this data memory. 0264 * @param pData The pointer to data memory object 0265 * @stable ICU 2.0 0266 */ 0267 U_CAPI void U_EXPORT2 0268 udata_close(UDataMemory *pData); 0269 0270 /** 0271 * Get the pointer to the actual data inside the data memory. 0272 * The data is read-only. 0273 * 0274 * ICU data must be at least 8-aligned, and should be 16-aligned. 0275 * 0276 * @param pData The pointer to data memory object 0277 * @stable ICU 2.0 0278 */ 0279 U_CAPI const void * U_EXPORT2 0280 udata_getMemory(UDataMemory *pData); 0281 0282 /** 0283 * Get the information from the data memory header. 0284 * This allows to get access to the header containing 0285 * platform data properties etc. which is not part of 0286 * the data itself and can therefore not be accessed 0287 * via the pointer that <code>udata_getMemory()</code> returns. 0288 * 0289 * @param pData pointer to the data memory object 0290 * @param pInfo pointer to a UDataInfo object; 0291 * its <code>size</code> field must be set correctly, 0292 * typically to <code>sizeof(UDataInfo)</code>. 0293 * 0294 * <code>*pInfo</code> will be filled with the UDataInfo structure 0295 * in the data memory object. If this structure is smaller than 0296 * <code>pInfo->size</code>, then the <code>size</code> will be 0297 * adjusted and only part of the structure will be filled. 0298 * @stable ICU 2.0 0299 */ 0300 U_CAPI void U_EXPORT2 0301 udata_getInfo(UDataMemory *pData, UDataInfo *pInfo); 0302 0303 /** 0304 * This function bypasses the normal ICU data loading process and 0305 * allows you to force ICU's system data to come out of a user-specified 0306 * area in memory. 0307 * 0308 * ICU data must be at least 8-aligned, and should be 16-aligned. 0309 * See https://unicode-org.github.io/icu/userguide/icu_data 0310 * 0311 * The format of this data is that of the icu common data file, as is 0312 * generated by the pkgdata tool with mode=common or mode=dll. 0313 * You can read in a whole common mode file and pass the address to the start of the 0314 * data, or (with the appropriate link options) pass in the pointer to 0315 * the data that has been loaded from a dll by the operating system, 0316 * as shown in this code: 0317 * 0318 * extern const char U_IMPORT U_ICUDATA_ENTRY_POINT []; 0319 * // U_ICUDATA_ENTRY_POINT is same as entry point specified to pkgdata tool 0320 * UErrorCode status = U_ZERO_ERROR; 0321 * 0322 * udata_setCommonData(&U_ICUDATA_ENTRY_POINT, &status); 0323 * 0324 * It is important that the declaration be as above. The entry point 0325 * must not be declared as an extern void*. 0326 * 0327 * Starting with ICU 4.4, it is possible to set several data packages, 0328 * one per call to this function. 0329 * udata_open() will look for data in the multiple data packages in the order 0330 * in which they were set. 0331 * The position of the linked-in or default-name ICU .data package in the 0332 * search list depends on when the first data item is loaded that is not contained 0333 * in the already explicitly set packages. 0334 * If data was loaded implicitly before the first call to this function 0335 * (for example, via opening a converter, constructing a UnicodeString 0336 * from default-codepage data, using formatting or collation APIs, etc.), 0337 * then the default data will be first in the list. 0338 * 0339 * This function has no effect on application (non ICU) data. See udata_setAppData() 0340 * for similar functionality for application data. 0341 * 0342 * @param data pointer to ICU common data 0343 * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code> 0344 * @stable ICU 2.0 0345 */ 0346 U_CAPI void U_EXPORT2 0347 udata_setCommonData(const void *data, UErrorCode *err); 0348 0349 0350 /** 0351 * This function bypasses the normal ICU data loading process for application-specific 0352 * data and allows you to force the it to come out of a user-specified 0353 * pointer. 0354 * 0355 * ICU data must be at least 8-aligned, and should be 16-aligned. 0356 * See https://unicode-org.github.io/icu/userguide/icu_data 0357 * 0358 * The format of this data is that of the icu common data file, like 'icudt26l.dat' 0359 * or the corresponding shared library (DLL) file. 0360 * The application must read in or otherwise construct an image of the data and then 0361 * pass the address of it to this function. 0362 * 0363 * 0364 * Warning: setAppData will set a U_USING_DEFAULT_WARNING code if 0365 * data with the specified path that has already been opened, or 0366 * if setAppData with the same path has already been called. 0367 * Any such calls to setAppData will have no effect. 0368 * 0369 * 0370 * @param packageName the package name by which the application will refer 0371 * to (open) this data 0372 * @param data pointer to the data 0373 * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code> 0374 * @see udata_setCommonData 0375 * @stable ICU 2.0 0376 */ 0377 U_CAPI void U_EXPORT2 0378 udata_setAppData(const char *packageName, const void *data, UErrorCode *err); 0379 0380 /** 0381 * Possible settings for udata_setFileAccess() 0382 * @see udata_setFileAccess 0383 * @stable ICU 3.4 0384 */ 0385 typedef enum UDataFileAccess { 0386 /** ICU looks for data in single files first, then in packages. (default) @stable ICU 3.4 */ 0387 UDATA_FILES_FIRST, 0388 /** An alias for the default access mode. @stable ICU 3.4 */ 0389 UDATA_DEFAULT_ACCESS = UDATA_FILES_FIRST, 0390 /** ICU only loads data from packages, not from single files. @stable ICU 3.4 */ 0391 UDATA_ONLY_PACKAGES, 0392 /** ICU loads data from packages first, and only from single files 0393 if the data cannot be found in a package. @stable ICU 3.4 */ 0394 UDATA_PACKAGES_FIRST, 0395 /** ICU does not access the file system for data loading. @stable ICU 3.4 */ 0396 UDATA_NO_FILES, 0397 #ifndef U_HIDE_DEPRECATED_API 0398 /** 0399 * Number of real UDataFileAccess values. 0400 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0401 */ 0402 UDATA_FILE_ACCESS_COUNT 0403 #endif // U_HIDE_DEPRECATED_API 0404 } UDataFileAccess; 0405 0406 /** 0407 * This function may be called to control how ICU loads data. It must be called 0408 * before any ICU data is loaded, including application data loaded with 0409 * ures/ResourceBundle or udata APIs. This function is not multithread safe. 0410 * The results of calling it while other threads are loading data are undefined. 0411 * @param access The type of file access to be used 0412 * @param status Error code. 0413 * @see UDataFileAccess 0414 * @stable ICU 3.4 0415 */ 0416 U_CAPI void U_EXPORT2 0417 udata_setFileAccess(UDataFileAccess access, UErrorCode *status); 0418 0419 U_CDECL_END 0420 0421 #if U_SHOW_CPLUSPLUS_API 0422 0423 U_NAMESPACE_BEGIN 0424 0425 /** 0426 * \class LocalUDataMemoryPointer 0427 * "Smart pointer" class, closes a UDataMemory via udata_close(). 0428 * For most methods see the LocalPointerBase base class. 0429 * 0430 * @see LocalPointerBase 0431 * @see LocalPointer 0432 * @stable ICU 4.4 0433 */ 0434 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDataMemoryPointer, UDataMemory, udata_close); 0435 0436 U_NAMESPACE_END 0437 0438 #endif // U_SHOW_CPLUSPLUS_API 0439 0440 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |