michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1999-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************/ michael@0: michael@0: michael@0: /*---------------------------------------------------------------------------------- michael@0: * michael@0: * UCommonData An abstract interface for dealing with ICU Common Data Files. michael@0: * ICU Common Data Files are a grouping of a number of individual michael@0: * data items (resources, converters, tables, anything) into a michael@0: * single file or dll. The combined format includes a table of michael@0: * contents for locating the individual items by name. michael@0: * michael@0: * Two formats for the table of contents are supported, which is michael@0: * why there is an abstract inteface involved. michael@0: * michael@0: * These functions are part of the ICU internal implementation, and michael@0: * are not inteded to be used directly by applications. michael@0: */ michael@0: michael@0: #ifndef __UCMNDATA_H__ michael@0: #define __UCMNDATA_H__ michael@0: michael@0: #include "unicode/udata.h" michael@0: #include "umapfile.h" michael@0: michael@0: michael@0: #define COMMON_DATA_NAME U_ICUDATA_NAME michael@0: michael@0: typedef struct { michael@0: uint16_t headerSize; michael@0: uint8_t magic1; michael@0: uint8_t magic2; michael@0: } MappedData; michael@0: michael@0: michael@0: typedef struct { michael@0: MappedData dataHeader; michael@0: UDataInfo info; michael@0: } DataHeader; michael@0: michael@0: typedef struct { michael@0: uint32_t nameOffset; michael@0: uint32_t dataOffset; michael@0: } UDataOffsetTOCEntry; michael@0: michael@0: typedef struct { michael@0: uint32_t count; michael@0: UDataOffsetTOCEntry entry[2]; /* Actual size of array is from count. */ michael@0: } UDataOffsetTOC; michael@0: michael@0: /** michael@0: * Get the header size from a const DataHeader *udh. michael@0: * Handles opposite-endian data. michael@0: * michael@0: * @internal michael@0: */ michael@0: U_CFUNC uint16_t michael@0: udata_getHeaderSize(const DataHeader *udh); michael@0: michael@0: /** michael@0: * Get the UDataInfo.size from a const UDataInfo *info. michael@0: * Handles opposite-endian data. michael@0: * michael@0: * @internal michael@0: */ michael@0: U_CFUNC uint16_t michael@0: udata_getInfoSize(const UDataInfo *info); michael@0: michael@0: U_CDECL_BEGIN michael@0: /* michael@0: * "Virtual" functions for data lookup. michael@0: * To call one, given a UDataMemory *p, the code looks like this: michael@0: * p->vFuncs.Lookup(p, tocEntryName, pErrorCode); michael@0: * (I sure do wish this was written in C++, not C) michael@0: */ michael@0: michael@0: typedef const DataHeader * michael@0: (U_CALLCONV * LookupFn)(const UDataMemory *pData, michael@0: const char *tocEntryName, michael@0: int32_t *pLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: typedef uint32_t michael@0: (U_CALLCONV * NumEntriesFn)(const UDataMemory *pData); michael@0: michael@0: U_CDECL_END michael@0: michael@0: typedef struct { michael@0: LookupFn Lookup; michael@0: NumEntriesFn NumEntries; michael@0: } commonDataFuncs; michael@0: michael@0: michael@0: /* michael@0: * Functions to check whether a UDataMemory refers to memory containing michael@0: * a recognizable header and table of contents a Common Data Format michael@0: * michael@0: * If a valid header and TOC are found, michael@0: * set the CommonDataFuncs function dispatch vector in the UDataMemory michael@0: * to point to the right functions for the TOC type. michael@0: * otherwise michael@0: * set an errorcode. michael@0: */ michael@0: U_CFUNC void udata_checkCommonData(UDataMemory *pData, UErrorCode *pErrorCode); michael@0: michael@0: #endif