]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/ucmndata.h
ICU-59180.0.1.tar.gz
[apple/icu.git] / icuSources / common / ucmndata.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ******************************************************************************
5 *
6 * Copyright (C) 1999-2011, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 ******************************************************************************/
10
11
12 /*----------------------------------------------------------------------------------
13 *
14 * UCommonData An abstract interface for dealing with ICU Common Data Files.
15 * ICU Common Data Files are a grouping of a number of individual
16 * data items (resources, converters, tables, anything) into a
17 * single file or dll. The combined format includes a table of
18 * contents for locating the individual items by name.
19 *
20 * Two formats for the table of contents are supported, which is
21 * why there is an abstract inteface involved.
22 *
23 * These functions are part of the ICU internal implementation, and
24 * are not inteded to be used directly by applications.
25 */
26
27 #ifndef __UCMNDATA_H__
28 #define __UCMNDATA_H__
29
30 #include "unicode/udata.h"
31 #include "umapfile.h"
32
33
34 #define COMMON_DATA_NAME U_ICUDATA_NAME
35
36 typedef struct {
37 uint16_t headerSize;
38 uint8_t magic1;
39 uint8_t magic2;
40 } MappedData;
41
42
43 typedef struct {
44 MappedData dataHeader;
45 UDataInfo info;
46 } DataHeader;
47
48 typedef struct {
49 uint32_t nameOffset;
50 uint32_t dataOffset;
51 } UDataOffsetTOCEntry;
52
53 typedef struct {
54 uint32_t count;
55 UDataOffsetTOCEntry entry[2]; /* Actual size of array is from count. */
56 } UDataOffsetTOC;
57
58 /**
59 * Get the header size from a const DataHeader *udh.
60 * Handles opposite-endian data.
61 *
62 * @internal
63 */
64 U_CFUNC uint16_t
65 udata_getHeaderSize(const DataHeader *udh);
66
67 /**
68 * Get the UDataInfo.size from a const UDataInfo *info.
69 * Handles opposite-endian data.
70 *
71 * @internal
72 */
73 U_CFUNC uint16_t
74 udata_getInfoSize(const UDataInfo *info);
75
76 U_CDECL_BEGIN
77 /*
78 * "Virtual" functions for data lookup.
79 * To call one, given a UDataMemory *p, the code looks like this:
80 * p->vFuncs.Lookup(p, tocEntryName, pErrorCode);
81 * (I sure do wish this was written in C++, not C)
82 */
83
84 typedef const DataHeader *
85 (U_CALLCONV * LookupFn)(const UDataMemory *pData,
86 const char *tocEntryName,
87 int32_t *pLength,
88 UErrorCode *pErrorCode);
89
90 typedef uint32_t
91 (U_CALLCONV * NumEntriesFn)(const UDataMemory *pData);
92
93 U_CDECL_END
94
95 typedef struct {
96 LookupFn Lookup;
97 NumEntriesFn NumEntries;
98 } commonDataFuncs;
99
100
101 /*
102 * Functions to check whether a UDataMemory refers to memory containing
103 * a recognizable header and table of contents a Common Data Format
104 *
105 * If a valid header and TOC are found,
106 * set the CommonDataFuncs function dispatch vector in the UDataMemory
107 * to point to the right functions for the TOC type.
108 * otherwise
109 * set an errorcode.
110 */
111 U_CFUNC void udata_checkCommonData(UDataMemory *pData, UErrorCode *pErrorCode);
112
113 #endif