ucmndata.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * 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 interface involved.
  20. *
  21. * These functions are part of the ICU internal implementation, and
  22. * are not intended to be used directly by applications.
  23. */
  24. #ifndef __UCMNDATA_H__
  25. #define __UCMNDATA_H__
  26. #include "unicode/udata.h"
  27. #include "umapfile.h"
  28. #define COMMON_DATA_NAME U_ICUDATA_NAME
  29. typedef struct {
  30. uint16_t headerSize;
  31. uint8_t magic1;
  32. uint8_t magic2;
  33. } MappedData;
  34. typedef struct {
  35. MappedData dataHeader;
  36. UDataInfo info;
  37. } DataHeader;
  38. typedef struct {
  39. uint32_t nameOffset;
  40. uint32_t dataOffset;
  41. } UDataOffsetTOCEntry;
  42. typedef struct {
  43. uint32_t count;
  44. /**
  45. * Variable-length array declared with length 1 to disable bounds checkers.
  46. * The actual array length is in the count field.
  47. */
  48. UDataOffsetTOCEntry entry[1];
  49. } UDataOffsetTOC;
  50. /**
  51. * Get the header size from a const DataHeader *udh.
  52. * Handles opposite-endian data.
  53. *
  54. * @internal
  55. */
  56. U_CFUNC uint16_t
  57. udata_getHeaderSize(const DataHeader *udh);
  58. /**
  59. * Get the UDataInfo.size from a const UDataInfo *info.
  60. * Handles opposite-endian data.
  61. *
  62. * @internal
  63. */
  64. U_CFUNC uint16_t
  65. udata_getInfoSize(const UDataInfo *info);
  66. U_CDECL_BEGIN
  67. /*
  68. * "Virtual" functions for data lookup.
  69. * To call one, given a UDataMemory *p, the code looks like this:
  70. * p->vFuncs.Lookup(p, tocEntryName, pErrorCode);
  71. * (I sure do wish this was written in C++, not C)
  72. */
  73. typedef const DataHeader *
  74. (U_CALLCONV * LookupFn)(const UDataMemory *pData,
  75. const char *tocEntryName,
  76. int32_t *pLength,
  77. UErrorCode *pErrorCode);
  78. typedef uint32_t
  79. (U_CALLCONV * NumEntriesFn)(const UDataMemory *pData);
  80. U_CDECL_END
  81. typedef struct {
  82. LookupFn Lookup;
  83. NumEntriesFn NumEntries;
  84. } commonDataFuncs;
  85. /*
  86. * Functions to check whether a UDataMemory refers to memory containing
  87. * a recognizable header and table of contents a Common Data Format
  88. *
  89. * If a valid header and TOC are found,
  90. * set the CommonDataFuncs function dispatch vector in the UDataMemory
  91. * to point to the right functions for the TOC type.
  92. * otherwise
  93. * set an errorcode.
  94. */
  95. U_CFUNC void udata_checkCommonData(UDataMemory *pData, UErrorCode *pErrorCode);
  96. #endif