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