]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/udata.h
   2 ****************************************************************************** 
   4 *   Copyright (C) 1999-2003, 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  * UDataInfo contains the properties about the requested data. 
  43  * <p>This structure may grow in the future, indicated by the 
  44  * <code>size</code> field.</p> 
  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> 
  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> 
  56  * <p>The <code>dataFormat</code> may be used to identify 
  57  * the kind of data, e.g. a converter table.</p> 
  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> 
  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> 
  73     /** @memo sizeof(UDataInfo) 
  77     /** @memo unused, set to 0  
  79     uint16_t reservedWord
; 
  81     /* platform data properties */ 
  82     /** @memo 0 for little-endian machine, 1 for big-endian 
  86     /** @memo see U_CHARSET_FAMILY values in utypes.h  
  88     uint8_t charsetFamily
; 
  90     /** @memo sizeof(UChar), one of { 1, 2, 4 }  
  94     /** @memo unused, set to 0  
  98     /** @memo data format identifier  
 100     uint8_t dataFormat
[4]; 
 102     /** @memo versions: [0] major [1] minor [2] milli [3] micro  
 104     uint8_t formatVersion
[4]; 
 106     /** @memo versions: [0] major [1] minor [2] milli [3] micro  
 108     uint8_t dataVersion
[4]; 
 111 /* API for reading data -----------------------------------------------------*/ 
 114  * Forward declaration of the data memory type. 
 117 typedef struct UDataMemory UDataMemory
; 
 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 
 132 typedef UBool U_CALLCONV
 
 133 UDataMemoryIsAcceptable(void *context
, 
 134                         const char *type
, const char *name
, 
 135                         const UDataInfo 
*pInfo
); 
 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. 
 156  * @see udata_openChoice 
 159 U_CAPI UDataMemory 
* U_EXPORT2
 
 160 udata_open(const char *path
, const char *type
, const char *name
, 
 161            UErrorCode 
*pErrorCode
); 
 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. 
 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> 
 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> 
 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> 
 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> 
 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. 
 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
); 
 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 
 223 U_CAPI 
void U_EXPORT2
 
 224 udata_close(UDataMemory 
*pData
); 
 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 
 232 U_CAPI 
const void * U_EXPORT2
 
 233 udata_getMemory(UDataMemory 
*pData
); 
 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. 
 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>. 
 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. 
 253 U_CAPI 
void U_EXPORT2
 
 254 udata_getInfo(UDataMemory 
*pData
, UDataInfo 
*pInfo
); 
 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 
 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: 
 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; 
 272  *       udata_setCommonData(&U_ICUDATA_ENTRY_POINT, &status); 
 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). 
 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*. 
 282  * This function has no effect on application (non ICU) data.  See udata_setAppData() 
 283  * for similar functionality for application data. 
 285  * @param data pointer to ICU common data 
 286  * @param err outgoing error status <code>U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR</code> 
 290 U_CAPI 
void U_EXPORT2
 
 291 udata_setCommonData(const void *data
, UErrorCode 
*err
); 
 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 
 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. 
 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. 
 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 
 318 U_CAPI 
void U_EXPORT2
 
 319 udata_setAppData(const char *packageName
, const void *data
, UErrorCode 
*err
);