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