xref: /aosp_15_r20/external/icu/libicu/cts_headers/ucmndata.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-2011, 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 
11*0e209d39SAndroid Build Coastguard Worker 
12*0e209d39SAndroid Build Coastguard Worker /*----------------------------------------------------------------------------------
13*0e209d39SAndroid Build Coastguard Worker  *
14*0e209d39SAndroid Build Coastguard Worker  *   UCommonData   An abstract interface for dealing with ICU Common Data Files.
15*0e209d39SAndroid Build Coastguard Worker  *                 ICU Common Data Files are a grouping of a number of individual
16*0e209d39SAndroid Build Coastguard Worker  *                 data items (resources, converters, tables, anything) into a
17*0e209d39SAndroid Build Coastguard Worker  *                 single file or dll.  The combined format includes a table of
18*0e209d39SAndroid Build Coastguard Worker  *                 contents for locating the individual items by name.
19*0e209d39SAndroid Build Coastguard Worker  *
20*0e209d39SAndroid Build Coastguard Worker  *                 Two formats for the table of contents are supported, which is
21*0e209d39SAndroid Build Coastguard Worker  *                 why there is an abstract interface involved.
22*0e209d39SAndroid Build Coastguard Worker  *
23*0e209d39SAndroid Build Coastguard Worker  *                 These functions are part of the ICU internal implementation, and
24*0e209d39SAndroid Build Coastguard Worker  *                 are not intended to be used directly by applications.
25*0e209d39SAndroid Build Coastguard Worker  */
26*0e209d39SAndroid Build Coastguard Worker 
27*0e209d39SAndroid Build Coastguard Worker #ifndef __UCMNDATA_H__
28*0e209d39SAndroid Build Coastguard Worker #define __UCMNDATA_H__
29*0e209d39SAndroid Build Coastguard Worker 
30*0e209d39SAndroid Build Coastguard Worker #include "unicode/udata.h"
31*0e209d39SAndroid Build Coastguard Worker #include "umapfile.h"
32*0e209d39SAndroid Build Coastguard Worker 
33*0e209d39SAndroid Build Coastguard Worker 
34*0e209d39SAndroid Build Coastguard Worker #define COMMON_DATA_NAME U_ICUDATA_NAME
35*0e209d39SAndroid Build Coastguard Worker 
36*0e209d39SAndroid Build Coastguard Worker typedef struct  {
37*0e209d39SAndroid Build Coastguard Worker     uint16_t    headerSize;
38*0e209d39SAndroid Build Coastguard Worker     uint8_t     magic1;
39*0e209d39SAndroid Build Coastguard Worker     uint8_t     magic2;
40*0e209d39SAndroid Build Coastguard Worker } MappedData;
41*0e209d39SAndroid Build Coastguard Worker 
42*0e209d39SAndroid Build Coastguard Worker 
43*0e209d39SAndroid Build Coastguard Worker typedef struct  {
44*0e209d39SAndroid Build Coastguard Worker     MappedData  dataHeader;
45*0e209d39SAndroid Build Coastguard Worker     UDataInfo   info;
46*0e209d39SAndroid Build Coastguard Worker } DataHeader;
47*0e209d39SAndroid Build Coastguard Worker 
48*0e209d39SAndroid Build Coastguard Worker typedef struct {
49*0e209d39SAndroid Build Coastguard Worker     uint32_t nameOffset;
50*0e209d39SAndroid Build Coastguard Worker     uint32_t dataOffset;
51*0e209d39SAndroid Build Coastguard Worker } UDataOffsetTOCEntry;
52*0e209d39SAndroid Build Coastguard Worker 
53*0e209d39SAndroid Build Coastguard Worker typedef struct {
54*0e209d39SAndroid Build Coastguard Worker     uint32_t count;
55*0e209d39SAndroid Build Coastguard Worker     /**
56*0e209d39SAndroid Build Coastguard Worker      * Variable-length array declared with length 1 to disable bounds checkers.
57*0e209d39SAndroid Build Coastguard Worker      * The actual array length is in the count field.
58*0e209d39SAndroid Build Coastguard Worker      */
59*0e209d39SAndroid Build Coastguard Worker     UDataOffsetTOCEntry entry[1];
60*0e209d39SAndroid Build Coastguard Worker } UDataOffsetTOC;
61*0e209d39SAndroid Build Coastguard Worker 
62*0e209d39SAndroid Build Coastguard Worker /**
63*0e209d39SAndroid Build Coastguard Worker  * Get the header size from a const DataHeader *udh.
64*0e209d39SAndroid Build Coastguard Worker  * Handles opposite-endian data.
65*0e209d39SAndroid Build Coastguard Worker  *
66*0e209d39SAndroid Build Coastguard Worker  * @internal
67*0e209d39SAndroid Build Coastguard Worker  */
68*0e209d39SAndroid Build Coastguard Worker U_CFUNC uint16_t
69*0e209d39SAndroid Build Coastguard Worker udata_getHeaderSize(const DataHeader *udh);
70*0e209d39SAndroid Build Coastguard Worker 
71*0e209d39SAndroid Build Coastguard Worker /**
72*0e209d39SAndroid Build Coastguard Worker  * Get the UDataInfo.size from a const UDataInfo *info.
73*0e209d39SAndroid Build Coastguard Worker  * Handles opposite-endian data.
74*0e209d39SAndroid Build Coastguard Worker  *
75*0e209d39SAndroid Build Coastguard Worker  * @internal
76*0e209d39SAndroid Build Coastguard Worker  */
77*0e209d39SAndroid Build Coastguard Worker U_CFUNC uint16_t
78*0e209d39SAndroid Build Coastguard Worker udata_getInfoSize(const UDataInfo *info);
79*0e209d39SAndroid Build Coastguard Worker 
80*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
81*0e209d39SAndroid Build Coastguard Worker /*
82*0e209d39SAndroid Build Coastguard Worker  *  "Virtual" functions for data lookup.
83*0e209d39SAndroid Build Coastguard Worker  *  To call one, given a UDataMemory *p, the code looks like this:
84*0e209d39SAndroid Build Coastguard Worker  *     p->vFuncs.Lookup(p, tocEntryName, pErrorCode);
85*0e209d39SAndroid Build Coastguard Worker  *          (I sure do wish this was written in C++, not C)
86*0e209d39SAndroid Build Coastguard Worker  */
87*0e209d39SAndroid Build Coastguard Worker 
88*0e209d39SAndroid Build Coastguard Worker typedef const DataHeader *
89*0e209d39SAndroid Build Coastguard Worker (U_CALLCONV * LookupFn)(const UDataMemory *pData,
90*0e209d39SAndroid Build Coastguard Worker                         const char *tocEntryName,
91*0e209d39SAndroid Build Coastguard Worker                         int32_t *pLength,
92*0e209d39SAndroid Build Coastguard Worker                         UErrorCode *pErrorCode);
93*0e209d39SAndroid Build Coastguard Worker 
94*0e209d39SAndroid Build Coastguard Worker typedef uint32_t
95*0e209d39SAndroid Build Coastguard Worker (U_CALLCONV * NumEntriesFn)(const UDataMemory *pData);
96*0e209d39SAndroid Build Coastguard Worker 
97*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
98*0e209d39SAndroid Build Coastguard Worker 
99*0e209d39SAndroid Build Coastguard Worker typedef struct {
100*0e209d39SAndroid Build Coastguard Worker     LookupFn      Lookup;
101*0e209d39SAndroid Build Coastguard Worker     NumEntriesFn  NumEntries;
102*0e209d39SAndroid Build Coastguard Worker } commonDataFuncs;
103*0e209d39SAndroid Build Coastguard Worker 
104*0e209d39SAndroid Build Coastguard Worker 
105*0e209d39SAndroid Build Coastguard Worker /*
106*0e209d39SAndroid Build Coastguard Worker  *  Functions to check whether a UDataMemory refers to memory containing
107*0e209d39SAndroid Build Coastguard Worker  *     a recognizable header and table of contents a Common Data Format
108*0e209d39SAndroid Build Coastguard Worker  *
109*0e209d39SAndroid Build Coastguard Worker  *     If a valid header and TOC are found,
110*0e209d39SAndroid Build Coastguard Worker  *         set the CommonDataFuncs function dispatch vector in the UDataMemory
111*0e209d39SAndroid Build Coastguard Worker  *             to point to the right functions for the TOC type.
112*0e209d39SAndroid Build Coastguard Worker  *     otherwise
113*0e209d39SAndroid Build Coastguard Worker  *         set an errorcode.
114*0e209d39SAndroid Build Coastguard Worker  */
115*0e209d39SAndroid Build Coastguard Worker U_CFUNC void udata_checkCommonData(UDataMemory *pData, UErrorCode *pErrorCode);
116*0e209d39SAndroid Build Coastguard Worker 
117*0e209d39SAndroid Build Coastguard Worker #endif
118