ucmndata.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 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. #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. DataHeader hdr;
  40. char padding[8];
  41. uint32_t count, reserved;
  42. /*
  43. const struct {
  44. const char *const name;
  45. const void *const data;
  46. } toc[1];
  47. */
  48. int fakeNameAndData[4]; /* TODO: Change this header type from */
  49. /* pointerTOC to OffsetTOC. */
  50. } ICU_Data_Header;
  51. typedef struct {
  52. uint32_t nameOffset;
  53. uint32_t dataOffset;
  54. } UDataOffsetTOCEntry;
  55. typedef struct {
  56. uint32_t count;
  57. /**
  58. * Variable-length array declared with length 1 to disable bounds checkers.
  59. * The actual array length is in the count field.
  60. */
  61. UDataOffsetTOCEntry entry[1];
  62. } UDataOffsetTOC;
  63. /**
  64. * Get the header size from a const DataHeader *udh.
  65. * Handles opposite-endian data.
  66. *
  67. * @internal
  68. */
  69. U_CFUNC uint16_t
  70. udata_getHeaderSize(const DataHeader *udh);
  71. /**
  72. * Get the UDataInfo.size from a const UDataInfo *info.
  73. * Handles opposite-endian data.
  74. *
  75. * @internal
  76. */
  77. U_CFUNC uint16_t
  78. udata_getInfoSize(const UDataInfo *info);
  79. U_CDECL_BEGIN
  80. /*
  81. * "Virtual" functions for data lookup.
  82. * To call one, given a UDataMemory *p, the code looks like this:
  83. * p->vFuncs.Lookup(p, tocEntryName, pErrorCode);
  84. * (I sure do wish this was written in C++, not C)
  85. */
  86. typedef const DataHeader *
  87. (U_CALLCONV * LookupFn)(const UDataMemory *pData,
  88. const char *tocEntryName,
  89. int32_t *pLength,
  90. UErrorCode *pErrorCode);
  91. typedef uint32_t
  92. (U_CALLCONV * NumEntriesFn)(const UDataMemory *pData);
  93. U_CDECL_END
  94. typedef struct {
  95. LookupFn Lookup;
  96. NumEntriesFn NumEntries;
  97. } commonDataFuncs;
  98. /*
  99. * Functions to check whether a UDataMemory refers to memory containing
  100. * a recognizable header and table of contents a Common Data Format
  101. *
  102. * If a valid header and TOC are found,
  103. * set the CommonDataFuncs function dispatch vector in the UDataMemory
  104. * to point to the right functions for the TOC type.
  105. * otherwise
  106. * set an errorcode.
  107. */
  108. U_CFUNC void udata_checkCommonData(UDataMemory *pData, UErrorCode *pErrorCode);
  109. #endif