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