]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ****************************************************************************** | |
3 | * | |
4 | * Copyright (C) 1999-2003, International Business Machines | |
5 | * Corporation and others. All Rights Reserved. | |
6 | * | |
7 | ****************************************************************************** | |
8 | * file name: udata.h | |
9 | * encoding: US-ASCII | |
10 | * tab size: 8 (not used) | |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 1999oct25 | |
14 | * created by: Markus W. Scherer | |
15 | */ | |
16 | ||
17 | #ifndef __UDATA_H__ | |
18 | #define __UDATA_H__ | |
19 | ||
20 | #include "unicode/utypes.h" | |
21 | ||
22 | U_CDECL_BEGIN | |
23 | ||
24 | /** | |
25 | * \file | |
26 | * \brief C API: Data loading interface | |
27 | * | |
28 | * <h2>Information about data loading interface</h2> | |
29 | * | |
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. | |
35 | * | |
36 | * See the User Guide Data Management chapter. | |
37 | */ | |
38 | ||
39 | /** | |
40 | * UDataInfo contains the properties about the requested data. | |
41 | * This is meta data. | |
42 | * | |
43 | * <p>This structure may grow in the future, indicated by the | |
44 | * <code>size</code> field.</p> | |
45 | * | |
46 | * <p>The platform data property fields help determine if a data | |
47 | * file can be efficiently used on a given machine. | |
48 | * The particular fields are of importance only if the data | |
49 | * is affected by the properties - if there is integer data | |
50 | * with word sizes > 1 byte, char* text, or UChar* text.</p> | |
51 | * | |
52 | * <p>The implementation for the <code>udata_open[Choice]()</code> | |
53 | * functions may reject data based on the value in <code>isBigEndian</code>. | |
54 | * No other field is used by the <code>udata</code> API implementation.</p> | |
55 | * | |
56 | * <p>The <code>dataFormat</code> may be used to identify | |
57 | * the kind of data, e.g. a converter table.</p> | |
58 | * | |
59 | * <p>The <code>formatVersion</code> field should be used to | |
60 | * make sure that the format can be interpreted. | |
61 | * I may be a good idea to check only for the one or two highest | |
62 | * of the version elements to allow the data memory to | |
63 | * get more or somewhat rearranged contents, for as long | |
64 | * as the using code can still interpret the older contents.</p> | |
65 | * | |
66 | * <p>The <code>dataVersion</code> field is intended to be a | |
67 | * common place to store the source version of the data; | |
68 | * for data from the Unicode character database, this could | |
69 | * reflect the Unicode version.</p> | |
70 | * @stable ICU 2.0 | |
71 | */ | |
72 | typedef struct { | |
73 | /** @memo sizeof(UDataInfo) | |
74 | * @stable ICU 2.0 */ | |
75 | uint16_t size; | |
76 | ||
77 | /** @memo unused, set to 0 | |
78 | * @stable ICU 2.0*/ | |
79 | uint16_t reservedWord; | |
80 | ||
81 | /* platform data properties */ | |
82 | /** @memo 0 for little-endian machine, 1 for big-endian | |
83 | * @stable ICU 2.0 */ | |
84 | uint8_t isBigEndian; | |
85 | ||
86 | /** @memo see U_CHARSET_FAMILY values in utypes.h | |
87 | * @stable ICU 2.0*/ | |
88 | uint8_t charsetFamily; | |
89 | ||
90 | /** @memo sizeof(UChar), one of { 1, 2, 4 } | |
91 | * @stable ICU 2.0*/ | |
92 | uint8_t sizeofUChar; | |
93 | ||
94 | /** @memo unused, set to 0 | |
95 | * @stable ICU 2.0*/ | |
96 | uint8_t reservedByte; | |
97 | ||
98 | /** @memo data format identifier | |
99 | * @stable ICU 2.0*/ | |
100 | uint8_t dataFormat[4]; | |
101 | ||
102 | /** @memo versions: [0] major [1] minor [2] milli [3] micro | |
103 | * @stable ICU 2.0*/ | |
104 | uint8_t formatVersion[4]; | |
105 | ||
106 | /** @memo versions: [0] major [1] minor [2] milli [3] micro | |
107 | * @stable ICU 2.0*/ | |
108 | uint8_t dataVersion[4]; | |
109 | } UDataInfo; | |
110 | ||
111 | /* API for reading data -----------------------------------------------------*/ | |
112 | ||
113 | /** | |
114 | * Forward declaration of the data memory type. | |
115 | * @stable ICU 2.0 | |
116 | */ | |
117 | typedef struct UDataMemory UDataMemory; | |
118 | ||
119 | /** | |
120 | * Callback function for udata_openChoice(). | |
121 | * @param context parameter passed into <code>udata_openChoice()</code>. | |
122 | * @param type The type of the data as passed into <code>udata_openChoice()</code>. | |
123 | * It may be <code>NULL</code>. | |
124 | * @param name The name of the data as passed into <code>udata_openChoice()</code>. | |
125 | * @param pInfo A pointer to the <code>UDataInfo</code> structure | |
126 | * of data that has been loaded and will be returned | |
127 | * by <code>udata_openChoice()</code> if this function | |
128 | * returns <code>TRUE</code>. | |
129 | * @return TRUE if the current data memory is acceptable | |
130 | * @stable ICU 2.0 | |
131 | */ | |
132 | typedef UBool U_CALLCONV | |
133 | UDataMemoryIsAcceptable(void *context, | |
134 | const char *type, const char *name, | |
135 | const UDataInfo *pInfo); | |
136 | ||
137 | ||
138 | /** | |
139 | * Convenience function. | |
140 | * This function works the same as <code>udata_openChoice</code> | |
141 | * except that any data that matches the type and name | |
142 | * is assumed to be acceptable. | |
143 | * @param path Specifies an absolute path and/or a basename for the | |
144 | * finding of the data in the file system. | |
145 | * <code>NULL</code> for ICU data. | |
146 | * @param type A string that specifies the type of data to be loaded. | |
147 | * For example, resource bundles are loaded with type "res", | |
148 | * conversion tables with type "cnv". | |
149 | * This may be <code>NULL</code> or empty. | |
150 | * @param name A string that specifies the name of the data. | |
151 | * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>. | |
152 | * @return A pointer (handle) to a data memory object, or <code>NULL</code> | |
153 | * if an error occurs. Call <code>udata_getMemory()</code> | |
154 | * to get a pointer to the actual data. | |
155 | * | |
156 | * @see udata_openChoice | |
157 | * @stable ICU 2.0 | |
158 | */ | |
159 | U_CAPI UDataMemory * U_EXPORT2 | |
160 | udata_open(const char *path, const char *type, const char *name, | |
161 | UErrorCode *pErrorCode); | |
162 | ||
163 | /** | |
164 | * Data loading function. | |
165 | * This function is used to find and load efficiently data for | |
166 | * ICU and applications using ICU. | |
167 | * It provides an abstract interface that allows to specify a data | |
168 | * type and name to find and load the data. | |
169 | * | |
170 | * <p>The implementation depends on platform properties and user preferences | |
171 | * and may involve loading shared libraries (DLLs), mapping | |
172 | * files into memory, or fopen()/fread() files. | |
173 | * It may also involve using static memory or database queries etc. | |
174 | * Several or all data items may be combined into one entity | |
175 | * (DLL, memory-mappable file).</p> | |
176 | * | |
177 | * <p>The data is always preceded by a header that includes | |
178 | * a <code>UDataInfo</code> structure. | |
179 | * The caller's <code>isAcceptable()</code> function is called to make | |
180 | * sure that the data is useful. It may be called several times if it | |
181 | * rejects the data and there is more than one location with data | |
182 | * matching the type and name.</p> | |
183 | * | |
184 | * <p>If <code>path==NULL</code>, then ICU data is loaded. | |
185 | * Otherwise, it is separated into a basename and a basename-less directory string. | |
186 | * The basename is used as the data package name, and the directory is | |
187 | * logically prepended to the ICU data directory string.</p> | |
188 | * | |
189 | * <p>For details about ICU data loading see the User Guide | |
190 | * Data Management chapter. (http://oss.software.ibm.com/icu/userguide/icudata.html)</p> | |
191 | * | |
192 | * @param path Specifies an absolute path and/or a basename for the | |
193 | * finding of the data in the file system. | |
194 | * <code>NULL</code> for ICU data. | |
195 | * @param type A string that specifies the type of data to be loaded. | |
196 | * For example, resource bundles are loaded with type "res", | |
197 | * conversion tables with type "cnv". | |
198 | * This may be <code>NULL</code> or empty. | |
199 | * @param name A string that specifies the name of the data. | |
200 | * @param isAcceptable This function is called to verify that loaded data | |
201 | * is useful for the client code. If it returns FALSE | |
202 | * for all data items, then <code>udata_openChoice()</code> | |
203 | * will return with an error. | |
204 | * @param context Arbitrary parameter to be passed into isAcceptable. | |
205 | * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>. | |
206 | * @return A pointer (handle) to a data memory object, or <code>NULL</code> | |
207 | * if an error occurs. Call <code>udata_getMemory()</code> | |
208 | * to get a pointer to the actual data. | |
209 | * @stable ICU 2.0 | |
210 | */ | |
211 | U_CAPI UDataMemory * U_EXPORT2 | |
212 | udata_openChoice(const char *path, const char *type, const char *name, | |
213 | UDataMemoryIsAcceptable *isAcceptable, void *context, | |
214 | UErrorCode *pErrorCode); | |
215 | ||
216 | /** | |
217 | * Close the data memory. | |
218 | * This function must be called to allow the system to | |
219 | * release resources associated with this data memory. | |
220 | * @param pData The pointer to data memory object | |
221 | * @stable ICU 2.0 | |
222 | */ | |
223 | U_CAPI void U_EXPORT2 | |
224 | udata_close(UDataMemory *pData); | |
225 | ||
226 | /** | |
227 | * Get the pointer to the actual data inside the data memory. | |
228 | * The data is read-only. | |
229 | * @param pData The pointer to data memory object | |
230 | * @stable ICU 2.0 | |
231 | */ | |
232 | U_CAPI const void * U_EXPORT2 | |
233 | udata_getMemory(UDataMemory *pData); | |
234 | ||
235 | /** | |
236 | * Get the information from the data memory header. | |
237 | * This allows to get access to the header containing | |
238 | * platform data properties etc. which is not part of | |
239 | * the data itself and can therefore not be accessed | |
240 | * via the pointer that <code>udata_getMemory()</code> returns. | |
241 | * | |
242 | * @param pData pointer to the data memory object | |
243 | * @param pInfo pointer to a UDataInfo object; | |
244 | * its <code>size</code> field must be set correctly, | |
245 | * typically to <code>sizeof(UDataInfo)</code>. | |
246 | * | |
247 | * <code>*pInfo</code> will be filled with the UDataInfo structure | |
248 | * in the data memory object. If this structure is smaller than | |
249 | * <code>pInfo->size</code>, then the <code>size</code> will be | |
250 | * adjusted and only part of the structure will be filled. | |
251 | * @stable ICU 2.0 | |
252 | */ | |
253 | U_CAPI void U_EXPORT2 | |
254 | udata_getInfo(UDataMemory *pData, UDataInfo *pInfo); | |
255 | ||
256 | /** | |
257 | * This function bypasses the normal ICU data loading process and | |
258 | * allows you to force ICU's system data to come out of a user-specified | |
259 | * area in memory. | |
260 | * | |
261 | * The format of this data is that of the icu common data file, as is | |
262 | * generated by the pkgdata tool with mode=common or mode=dll. | |
263 | * You can read in a whole common mode file and pass the address to the start of the | |
264 | * data, or (with the appropriate link options) pass in the pointer to | |
265 | * the data that has been loaded from a dll by the operating system, | |
266 | * as shown in this code: | |
267 | * | |
268 | * extern const char U_IMPORT U_ICUDATA_ENTRY_POINT []; | |
269 | * // U_ICUDATA_ENTRY_POINT is same as entry point specified to pkgdata tool | |
270 | * UErrorCode status = U_ZERO_ERROR; | |
271 | * | |
272 | * udata_setCommonData(&U_ICUDATA_ENTRY_POINT, &status); | |
273 | * | |
274 | * Warning: ICU must NOT have even attempted to access its data yet | |
275 | * when this call is made, or U_USING_DEFAULT_WARNING code will | |
276 | * be returned. Be careful of UnicodeStrings in static initialization which | |
277 | * may attempt to load a converter (use the UNICODE_STRING(x) macro instead). | |
278 | * | |
279 | * Also note that it is important that the declaration be as above. The entry point | |
280 | * must not be declared as an extern void*. | |
281 | * | |
282 | * This function has no effect on application (non ICU) data. See udata_setAppData() | |
283 | * for similar functionality for application data. | |
284 | * | |
285 | * @param data pointer to ICU common data | |
286 | * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code> | |
287 | * @stable ICU 2.0 | |
288 | */ | |
289 | ||
290 | U_CAPI void U_EXPORT2 | |
291 | udata_setCommonData(const void *data, UErrorCode *err); | |
292 | ||
293 | ||
294 | /** | |
295 | * This function bypasses the normal ICU data loading process for application-specific | |
296 | * data and allows you to force the it to come out of a user-specified | |
297 | * pointer. | |
298 | * | |
299 | * The format of this data is that of the icu common data file, like 'icudt26l.dat' | |
300 | * or the corresponding shared library (DLL) file. | |
301 | * The application must read in or otherwise construct an image of the data and then | |
302 | * pass the address of it to this function. | |
303 | * | |
304 | * | |
305 | * Warning: setAppData will set a U_USING_DEFAULT_WARNING code if | |
306 | * data with the specifed path that has already been opened, or | |
307 | * if setAppData with the same path has already been called. | |
308 | * Any such calls to setAppData will have no effect. | |
309 | * | |
310 | * | |
311 | * @param packageName the package name by which the application will refer | |
312 | * to (open) this data | |
313 | * @param data pointer to the data | |
314 | * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code> | |
315 | * @see udata_setCommonData | |
316 | * @stable ICU 2.0 | |
317 | */ | |
318 | U_CAPI void U_EXPORT2 | |
319 | udata_setAppData(const char *packageName, const void *data, UErrorCode *err); | |
320 | ||
321 | U_CDECL_END | |
322 | ||
323 | #endif |