]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/udata.h
2 ******************************************************************************
4 * Copyright (C) 1999-2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 1999oct25
14 * created by: Markus W. Scherer
20 #include "unicode/utypes.h"
26 * \brief C API: Data loading interface
28 * <h2>Information about data loading interface</h2>
30 * This API is used to find and efficiently load data for ICU and applications
31 * using ICU. It provides an abstract interface that specifies a data type and
32 * name to find and load the data. Normally this API is used by other ICU APIs
33 * to load required data out of the ICU data library, but it can be used to
34 * load data out of other places.
36 * See the User Guide Data Management chapter.
40 * Character used to separate package names from tree names
43 #define U_TREE_SEPARATOR '-'
46 * String used to separate package names from tree names
49 #define U_TREE_SEPARATOR_STRING "-"
52 * Character used to separate parts of entry names
55 #define U_TREE_ENTRY_SEP_CHAR '/'
58 * String used to separate parts of entry names
61 #define U_TREE_ENTRY_SEP_STRING "/"
64 * Alias for standard ICU data
67 #define U_ICUDATA_ALIAS "ICUDATA"
70 * UDataInfo contains the properties about the requested data.
73 * <p>This structure may grow in the future, indicated by the
74 * <code>size</code> field.</p>
76 * <p>The platform data property fields help determine if a data
77 * file can be efficiently used on a given machine.
78 * The particular fields are of importance only if the data
79 * is affected by the properties - if there is integer data
80 * with word sizes > 1 byte, char* text, or UChar* text.</p>
82 * <p>The implementation for the <code>udata_open[Choice]()</code>
83 * functions may reject data based on the value in <code>isBigEndian</code>.
84 * No other field is used by the <code>udata</code> API implementation.</p>
86 * <p>The <code>dataFormat</code> may be used to identify
87 * the kind of data, e.g. a converter table.</p>
89 * <p>The <code>formatVersion</code> field should be used to
90 * make sure that the format can be interpreted.
91 * I may be a good idea to check only for the one or two highest
92 * of the version elements to allow the data memory to
93 * get more or somewhat rearranged contents, for as long
94 * as the using code can still interpret the older contents.</p>
96 * <p>The <code>dataVersion</code> field is intended to be a
97 * common place to store the source version of the data;
98 * for data from the Unicode character database, this could
99 * reflect the Unicode version.</p>
103 /** sizeof(UDataInfo)
109 uint16_t reservedWord
;
111 /* platform data properties */
112 /** 0 for little-endian machine, 1 for big-endian
116 /** see U_CHARSET_FAMILY values in utypes.h
118 uint8_t charsetFamily
;
120 /** sizeof(UChar), one of { 1, 2, 4 }
126 uint8_t reservedByte
;
128 /** data format identifier
130 uint8_t dataFormat
[4];
132 /** versions: [0] major [1] minor [2] milli [3] micro
134 uint8_t formatVersion
[4];
136 /** versions: [0] major [1] minor [2] milli [3] micro
138 uint8_t dataVersion
[4];
141 /* API for reading data -----------------------------------------------------*/
144 * Forward declaration of the data memory type.
147 typedef struct UDataMemory UDataMemory
;
150 * Callback function for udata_openChoice().
151 * @param context parameter passed into <code>udata_openChoice()</code>.
152 * @param type The type of the data as passed into <code>udata_openChoice()</code>.
153 * It may be <code>NULL</code>.
154 * @param name The name of the data as passed into <code>udata_openChoice()</code>.
155 * @param pInfo A pointer to the <code>UDataInfo</code> structure
156 * of data that has been loaded and will be returned
157 * by <code>udata_openChoice()</code> if this function
158 * returns <code>TRUE</code>.
159 * @return TRUE if the current data memory is acceptable
162 typedef UBool U_CALLCONV
163 UDataMemoryIsAcceptable(void *context
,
164 const char *type
, const char *name
,
165 const UDataInfo
*pInfo
);
169 * Convenience function.
170 * This function works the same as <code>udata_openChoice</code>
171 * except that any data that matches the type and name
172 * is assumed to be acceptable.
173 * @param path Specifies an absolute path and/or a basename for the
174 * finding of the data in the file system.
175 * <code>NULL</code> for ICU data.
176 * @param type A string that specifies the type of data to be loaded.
177 * For example, resource bundles are loaded with type "res",
178 * conversion tables with type "cnv".
179 * This may be <code>NULL</code> or empty.
180 * @param name A string that specifies the name of the data.
181 * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>.
182 * @return A pointer (handle) to a data memory object, or <code>NULL</code>
183 * if an error occurs. Call <code>udata_getMemory()</code>
184 * to get a pointer to the actual data.
186 * @see udata_openChoice
189 U_STABLE UDataMemory
* U_EXPORT2
190 udata_open(const char *path
, const char *type
, const char *name
,
191 UErrorCode
*pErrorCode
);
194 * Data loading function.
195 * This function is used to find and load efficiently data for
196 * ICU and applications using ICU.
197 * It provides an abstract interface that allows to specify a data
198 * type and name to find and load the data.
200 * <p>The implementation depends on platform properties and user preferences
201 * and may involve loading shared libraries (DLLs), mapping
202 * files into memory, or fopen()/fread() files.
203 * It may also involve using static memory or database queries etc.
204 * Several or all data items may be combined into one entity
205 * (DLL, memory-mappable file).</p>
207 * <p>The data is always preceded by a header that includes
208 * a <code>UDataInfo</code> structure.
209 * The caller's <code>isAcceptable()</code> function is called to make
210 * sure that the data is useful. It may be called several times if it
211 * rejects the data and there is more than one location with data
212 * matching the type and name.</p>
214 * <p>If <code>path==NULL</code>, then ICU data is loaded.
215 * Otherwise, it is separated into a basename and a basename-less directory string.
216 * The basename is used as the data package name, and the directory is
217 * logically prepended to the ICU data directory string.</p>
219 * <p>For details about ICU data loading see the User Guide
220 * Data Management chapter. (http://oss.software.ibm.com/icu/userguide/icudata.html)</p>
222 * @param path Specifies an absolute path and/or a basename for the
223 * finding of the data in the file system.
224 * <code>NULL</code> for ICU data.
225 * @param type A string that specifies the type of data to be loaded.
226 * For example, resource bundles are loaded with type "res",
227 * conversion tables with type "cnv".
228 * This may be <code>NULL</code> or empty.
229 * @param name A string that specifies the name of the data.
230 * @param isAcceptable This function is called to verify that loaded data
231 * is useful for the client code. If it returns FALSE
232 * for all data items, then <code>udata_openChoice()</code>
233 * will return with an error.
234 * @param context Arbitrary parameter to be passed into isAcceptable.
235 * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>.
236 * @return A pointer (handle) to a data memory object, or <code>NULL</code>
237 * if an error occurs. Call <code>udata_getMemory()</code>
238 * to get a pointer to the actual data.
241 U_STABLE UDataMemory
* U_EXPORT2
242 udata_openChoice(const char *path
, const char *type
, const char *name
,
243 UDataMemoryIsAcceptable
*isAcceptable
, void *context
,
244 UErrorCode
*pErrorCode
);
247 * Close the data memory.
248 * This function must be called to allow the system to
249 * release resources associated with this data memory.
250 * @param pData The pointer to data memory object
253 U_STABLE
void U_EXPORT2
254 udata_close(UDataMemory
*pData
);
257 * Get the pointer to the actual data inside the data memory.
258 * The data is read-only.
259 * @param pData The pointer to data memory object
262 U_STABLE
const void * U_EXPORT2
263 udata_getMemory(UDataMemory
*pData
);
266 * Get the information from the data memory header.
267 * This allows to get access to the header containing
268 * platform data properties etc. which is not part of
269 * the data itself and can therefore not be accessed
270 * via the pointer that <code>udata_getMemory()</code> returns.
272 * @param pData pointer to the data memory object
273 * @param pInfo pointer to a UDataInfo object;
274 * its <code>size</code> field must be set correctly,
275 * typically to <code>sizeof(UDataInfo)</code>.
277 * <code>*pInfo</code> will be filled with the UDataInfo structure
278 * in the data memory object. If this structure is smaller than
279 * <code>pInfo->size</code>, then the <code>size</code> will be
280 * adjusted and only part of the structure will be filled.
283 U_STABLE
void U_EXPORT2
284 udata_getInfo(UDataMemory
*pData
, UDataInfo
*pInfo
);
287 * This function bypasses the normal ICU data loading process and
288 * allows you to force ICU's system data to come out of a user-specified
291 * The format of this data is that of the icu common data file, as is
292 * generated by the pkgdata tool with mode=common or mode=dll.
293 * You can read in a whole common mode file and pass the address to the start of the
294 * data, or (with the appropriate link options) pass in the pointer to
295 * the data that has been loaded from a dll by the operating system,
296 * as shown in this code:
298 * extern const char U_IMPORT U_ICUDATA_ENTRY_POINT [];
299 * // U_ICUDATA_ENTRY_POINT is same as entry point specified to pkgdata tool
300 * UErrorCode status = U_ZERO_ERROR;
302 * udata_setCommonData(&U_ICUDATA_ENTRY_POINT, &status);
304 * Warning: ICU must NOT have even attempted to access its data yet
305 * when this call is made, or U_USING_DEFAULT_WARNING code will
306 * be returned. Be careful of UnicodeStrings in static initialization which
307 * may attempt to load a converter (use the UNICODE_STRING(x) macro instead).
309 * Also note that it is important that the declaration be as above. The entry point
310 * must not be declared as an extern void*.
312 * This function has no effect on application (non ICU) data. See udata_setAppData()
313 * for similar functionality for application data.
315 * @param data pointer to ICU common data
316 * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code>
320 U_STABLE
void U_EXPORT2
321 udata_setCommonData(const void *data
, UErrorCode
*err
);
325 * This function bypasses the normal ICU data loading process for application-specific
326 * data and allows you to force the it to come out of a user-specified
329 * The format of this data is that of the icu common data file, like 'icudt26l.dat'
330 * or the corresponding shared library (DLL) file.
331 * The application must read in or otherwise construct an image of the data and then
332 * pass the address of it to this function.
335 * Warning: setAppData will set a U_USING_DEFAULT_WARNING code if
336 * data with the specifed path that has already been opened, or
337 * if setAppData with the same path has already been called.
338 * Any such calls to setAppData will have no effect.
341 * @param packageName the package name by which the application will refer
342 * to (open) this data
343 * @param data pointer to the data
344 * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code>
345 * @see udata_setCommonData
348 U_STABLE
void U_EXPORT2
349 udata_setAppData(const char *packageName
, const void *data
, UErrorCode
*err
);