uresdata.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. * Copyright (C) 1999-2016, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. ******************************************************************************
  8. * file name: uresdata.h
  9. * encoding: UTF-8
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 1999dec08
  14. * created by: Markus W. Scherer
  15. * 06/24/02 weiv Added support for resource sharing
  16. */
  17. #ifndef __RESDATA_H__
  18. #define __RESDATA_H__
  19. #include "unicode/utypes.h"
  20. #include "unicode/udata.h"
  21. #include "unicode/ures.h"
  22. #include "putilimp.h"
  23. #include "udataswp.h"
  24. /**
  25. * Numeric constants for internal-only types of resource items.
  26. * These must use different numeric values than UResType constants
  27. * because they are used together.
  28. * Internal types are never returned by ures_getType().
  29. */
  30. typedef enum {
  31. /** Include a negative value so that the compiler uses the same int type as for UResType. */
  32. URES_INTERNAL_NONE=-1,
  33. /** Resource type constant for tables with 32-bit count, key offsets and values. */
  34. URES_TABLE32=4,
  35. /**
  36. * Resource type constant for tables with 16-bit count, key offsets and values.
  37. * All values are URES_STRING_V2 strings.
  38. */
  39. URES_TABLE16=5,
  40. /** Resource type constant for 16-bit Unicode strings in formatVersion 2. */
  41. URES_STRING_V2=6,
  42. /**
  43. * Resource type constant for arrays with 16-bit count and values.
  44. * All values are URES_STRING_V2 strings.
  45. */
  46. URES_ARRAY16=9
  47. /* Resource type 15 is not defined but effectively used by RES_BOGUS=0xffffffff. */
  48. } UResInternalType;
  49. /*
  50. * A Resource is a 32-bit value that has 2 bit fields:
  51. * 31..28 4-bit type, see enum below
  52. * 27..0 28-bit four-byte-offset or value according to the type
  53. */
  54. typedef uint32_t Resource;
  55. #define RES_BOGUS 0xffffffff
  56. #define RES_MAX_OFFSET 0x0fffffff
  57. #define RES_GET_TYPE(res) ((int32_t)((res)>>28UL))
  58. #define RES_GET_OFFSET(res) ((res)&0x0fffffff)
  59. #define RES_GET_POINTER(pRoot, res) ((pRoot)+RES_GET_OFFSET(res))
  60. /* get signed and unsigned integer values directly from the Resource handle
  61. * NOTE: For proper logging, please use the res_getInt() constexpr
  62. */
  63. #if U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC
  64. # define RES_GET_INT_NO_TRACE(res) (((int32_t)((res)<<4L))>>4L)
  65. #else
  66. # define RES_GET_INT_NO_TRACE(res) (int32_t)(((res)&0x08000000) ? (res)|0xf0000000 : (res)&0x07ffffff)
  67. #endif
  68. #define RES_GET_UINT_NO_TRACE(res) ((res)&0x0fffffff)
  69. #define URES_IS_ARRAY(type) ((int32_t)(type)==URES_ARRAY || (int32_t)(type)==URES_ARRAY16)
  70. #define URES_IS_TABLE(type) ((int32_t)(type)==URES_TABLE || (int32_t)(type)==URES_TABLE16 || (int32_t)(type)==URES_TABLE32)
  71. #define URES_IS_CONTAINER(type) (URES_IS_TABLE(type) || URES_IS_ARRAY(type))
  72. #define URES_MAKE_RESOURCE(type, offset) (((Resource)(type)<<28)|(Resource)(offset))
  73. #define URES_MAKE_EMPTY_RESOURCE(type) ((Resource)(type)<<28)
  74. /* indexes[] value names; indexes are generally 32-bit (Resource) indexes */
  75. enum {
  76. /**
  77. * [0] contains the length of indexes[]
  78. * which is at most URES_INDEX_TOP of the latest format version
  79. *
  80. * formatVersion==1: all bits contain the length of indexes[]
  81. * but the length is much less than 0xff;
  82. * formatVersion>1:
  83. * only bits 7..0 contain the length of indexes[],
  84. * bits 31..8 are reserved and set to 0
  85. * formatVersion>=3:
  86. * bits 31..8 poolStringIndexLimit bits 23..0
  87. */
  88. URES_INDEX_LENGTH,
  89. /**
  90. * [1] contains the top of the key strings,
  91. * same as the bottom of resources or UTF-16 strings, rounded up
  92. */
  93. URES_INDEX_KEYS_TOP,
  94. /** [2] contains the top of all resources */
  95. URES_INDEX_RESOURCES_TOP,
  96. /**
  97. * [3] contains the top of the bundle,
  98. * in case it were ever different from [2]
  99. */
  100. URES_INDEX_BUNDLE_TOP,
  101. /** [4] max. length of any table */
  102. URES_INDEX_MAX_TABLE_LENGTH,
  103. /**
  104. * [5] attributes bit set, see URES_ATT_* (new in formatVersion 1.2)
  105. *
  106. * formatVersion>=3:
  107. * bits 31..16 poolStringIndex16Limit
  108. * bits 15..12 poolStringIndexLimit bits 27..24
  109. */
  110. URES_INDEX_ATTRIBUTES,
  111. /**
  112. * [6] top of the 16-bit units (UTF-16 string v2 UChars, URES_TABLE16, URES_ARRAY16),
  113. * rounded up (new in formatVersion 2.0, ICU 4.4)
  114. */
  115. URES_INDEX_16BIT_TOP,
  116. /** [7] checksum of the pool bundle (new in formatVersion 2.0, ICU 4.4) */
  117. URES_INDEX_POOL_CHECKSUM,
  118. URES_INDEX_TOP
  119. };
  120. /*
  121. * Nofallback attribute, attribute bit 0 in indexes[URES_INDEX_ATTRIBUTES].
  122. * New in formatVersion 1.2 (ICU 3.6).
  123. *
  124. * If set, then this resource bundle is a standalone bundle.
  125. * If not set, then the bundle participates in locale fallback, eventually
  126. * all the way to the root bundle.
  127. * If indexes[] is missing or too short, then the attribute cannot be determined
  128. * reliably. Dependency checking should ignore such bundles, and loading should
  129. * use fallbacks.
  130. */
  131. #define URES_ATT_NO_FALLBACK 1
  132. /*
  133. * Attributes for bundles that are, or use, a pool bundle.
  134. * A pool bundle provides key strings that are shared among several other bundles
  135. * to reduce their total size.
  136. * New in formatVersion 2 (ICU 4.4).
  137. */
  138. #define URES_ATT_IS_POOL_BUNDLE 2
  139. #define URES_ATT_USES_POOL_BUNDLE 4
  140. /*
  141. * File format for .res resource bundle files
  142. *
  143. * ICU 56: New in formatVersion 3 compared with 2: -------------
  144. *
  145. * Resource bundles can optionally use shared string-v2 values
  146. * stored in the pool bundle.
  147. * If so, then the indexes[] contain two new values
  148. * in previously-unused bits of existing indexes[] slots:
  149. * - poolStringIndexLimit:
  150. * String-v2 offsets (in 32-bit Resource words) below this limit
  151. * point to pool bundle string-v2 values.
  152. * - poolStringIndex16Limit:
  153. * Resource16 string-v2 offsets below this limit
  154. * point to pool bundle string-v2 values.
  155. * Guarantee: poolStringIndex16Limit <= poolStringIndexLimit
  156. *
  157. * The local bundle's poolStringIndexLimit is greater than
  158. * any pool bundle string index used in the local bundle.
  159. * The poolStringIndexLimit should not be greater than
  160. * the maximum possible pool bundle string index.
  161. *
  162. * The maximum possible pool bundle string index is the index to the last non-NUL
  163. * pool string character, due to suffix sharing.
  164. *
  165. * In the pool bundle, there is no structure that lists the strings.
  166. * (The root resource is an empty Table.)
  167. * If the strings need to be enumerated (as genrb --usePoolBundle does),
  168. * then iterate through the pool bundle's 16-bit-units array from the beginning.
  169. * Stop at the end of the array, or when an explicit or implicit string length
  170. * would lead beyond the end of the array,
  171. * or when an apparent string is not NUL-terminated.
  172. * (Future genrb version might terminate the strings with
  173. * what looks like a large explicit string length.)
  174. *
  175. * ICU 4.4: New in formatVersion 2 compared with 1.3: -------------
  176. *
  177. * Three new resource types -- String-v2, Table16 and Array16 -- have their
  178. * values stored in a new array of 16-bit units between the table key strings
  179. * and the start of the other resources.
  180. *
  181. * genrb eliminates duplicates among Unicode string-v2 values.
  182. * Multiple Unicode strings may use the same offset and string data,
  183. * or a short string may point to the suffix of a longer string. ("Suffix sharing")
  184. * For example, one string "abc" may be reused for another string "bc" by pointing
  185. * to the second character. (Short strings-v2 are NUL-terminated
  186. * and not preceded by an explicit length value.)
  187. *
  188. * It is allowed for all resource types to share values.
  189. * The swapper code (ures_swap()) has been modified so that it swaps each item
  190. * exactly once.
  191. *
  192. * A resource bundle may use a special pool bundle. Some or all of the table key strings
  193. * of the using-bundle are omitted, and the key string offsets for such key strings refer
  194. * to offsets in the pool bundle.
  195. * The using-bundle's and the pool-bundle's indexes[URES_INDEX_POOL_CHECKSUM] values
  196. * must match.
  197. * Two bits in indexes[URES_INDEX_ATTRIBUTES] indicate whether a resource bundle
  198. * is or uses a pool bundle.
  199. *
  200. * Table key strings must be compared in ASCII order, even if they are not
  201. * stored in ASCII.
  202. *
  203. * New in formatVersion 1.3 compared with 1.2: -------------
  204. *
  205. * genrb eliminates duplicates among key strings.
  206. * Multiple table items may share one key string, or one item may point
  207. * to the suffix of another's key string. ("Suffix sharing")
  208. * For example, one key "abc" may be reused for another key "bc" by pointing
  209. * to the second character. (Key strings are NUL-terminated.)
  210. *
  211. * -------------
  212. *
  213. * An ICU4C resource bundle file (.res) is a binary, memory-mappable file
  214. * with nested, hierarchical data structures.
  215. * It physically contains the following:
  216. *
  217. * Resource root; -- 32-bit Resource item, root item for this bundle's tree;
  218. * currently, the root item must be a table or table32 resource item
  219. * int32_t indexes[indexes[0]]; -- array of indexes for friendly
  220. * reading and swapping; see URES_INDEX_* above
  221. * new in formatVersion 1.1 (ICU 2.8)
  222. * char keys[]; -- characters for key strings
  223. * (formatVersion 1.0: up to 65k of characters; 1.1: <2G)
  224. * (minus the space for root and indexes[]),
  225. * which consist of invariant characters (ASCII/EBCDIC) and are NUL-terminated;
  226. * padded to multiple of 4 bytes for 4-alignment of the following data
  227. * uint16_t 16BitUnits[]; -- resources that are stored entirely as sequences of 16-bit units
  228. * (new in formatVersion 2/ICU 4.4)
  229. * data is indexed by the offset values in 16-bit resource types,
  230. * with offset 0 pointing to the beginning of this array;
  231. * there is a 0 at offset 0, for empty resources;
  232. * padded to multiple of 4 bytes for 4-alignment of the following data
  233. * data; -- data directly and indirectly indexed by the root item;
  234. * the structure is determined by walking the tree
  235. *
  236. * Each resource bundle item has a 32-bit Resource handle (see typedef above)
  237. * which contains the item type number in its upper 4 bits (31..28) and either
  238. * an offset or a direct value in its lower 28 bits (27..0).
  239. * The order of items is undefined and only determined by walking the tree.
  240. * Leaves of the tree may be stored first or last or anywhere in between,
  241. * and it is in theory possible to have unreferenced holes in the file.
  242. *
  243. * 16-bit-unit values:
  244. * Starting with formatVersion 2/ICU 4.4, some resources are stored in a special
  245. * array of 16-bit units. Each resource value is a sequence of 16-bit units,
  246. * with no per-resource padding to a 4-byte boundary.
  247. * 16-bit container types (Table16 and Array16) contain Resource16 values
  248. * which are offsets to String-v2 resources in the same 16-bit-units array.
  249. *
  250. * Direct values:
  251. * - Empty Unicode strings have an offset value of 0 in the Resource handle itself.
  252. * - Starting with formatVersion 2/ICU 4.4, an offset value of 0 for
  253. * _any_ resource type indicates an empty value.
  254. * - Integer values are 28-bit values stored in the Resource handle itself;
  255. * the interpretation of unsigned vs. signed integers is up to the application.
  256. *
  257. * All other types and values use 28-bit offsets to point to the item's data.
  258. * The offset is an index to the first 32-bit word of the value, relative to the
  259. * start of the resource data (i.e., the root item handle is at offset 0).
  260. * To get byte offsets, the offset is multiplied by 4 (or shifted left by 2 bits).
  261. * All resource item values are 4-aligned.
  262. *
  263. * New in formatVersion 2/ICU 4.4: Some types use offsets into the 16-bit-units array,
  264. * indexing 16-bit units in that array.
  265. *
  266. * The structures (memory layouts) for the values for each item type are listed
  267. * in the table below.
  268. *
  269. * Nested, hierarchical structures: -------------
  270. *
  271. * Table items contain key-value pairs where the keys are offsets to char * key strings.
  272. * The values of these pairs are either Resource handles or
  273. * offsets into the 16-bit-units array, depending on the table type.
  274. *
  275. * Array items are simple vectors of Resource handles,
  276. * or of offsets into the 16-bit-units array, depending on the array type.
  277. *
  278. * Table key string offsets: -------
  279. *
  280. * Key string offsets are relative to the start of the resource data (of the root handle),
  281. * i.e., the first string has an offset of 4+sizeof(indexes).
  282. * (After the 4-byte root handle and after the indexes array.)
  283. *
  284. * If the resource bundle uses a pool bundle, then some key strings are stored
  285. * in the pool bundle rather than in the local bundle itself.
  286. * - In a Table or Table16, the 16-bit key string offset is local if it is
  287. * less than indexes[URES_INDEX_KEYS_TOP]<<2.
  288. * Otherwise, subtract indexes[URES_INDEX_KEYS_TOP]<<2 to get the offset into
  289. * the pool bundle key strings.
  290. * - In a Table32, the 32-bit key string offset is local if it is non-negative.
  291. * Otherwise, reset bit 31 to get the pool key string offset.
  292. *
  293. * Unlike the local offset, the pool key offset is relative to
  294. * the start of the key strings, not to the start of the bundle.
  295. *
  296. * An alias item is special (and new in ICU 2.4): --------------
  297. *
  298. * Its memory layout is just like for a UnicodeString, but at runtime it resolves to
  299. * another resource bundle's item according to the path in the string.
  300. * This is used to share items across bundles that are in different lookup/fallback
  301. * chains (e.g., large collation data among zh_TW and zh_HK).
  302. * This saves space (for large items) and maintenance effort (less duplication of data).
  303. *
  304. * --------------------------------------------------------------------------
  305. *
  306. * Resource types:
  307. *
  308. * Most resources have their values stored at four-byte offsets from the start
  309. * of the resource data. These values are at least 4-aligned.
  310. * Some resource values are stored directly in the offset field of the Resource itself.
  311. * See UResType in unicode/ures.h for enumeration constants for Resource types.
  312. *
  313. * Some resources have their values stored as sequences of 16-bit units,
  314. * at 2-byte offsets from the start of a contiguous 16-bit-unit array between
  315. * the table key strings and the other resources. (new in formatVersion 2/ICU 4.4)
  316. * At offset 0 of that array is a 16-bit zero value for empty 16-bit resources.
  317. *
  318. * Resource16 values in Table16 and Array16 are 16-bit offsets to String-v2
  319. * resources, with the offsets relative to the start of the 16-bit-units array.
  320. * Starting with formatVersion 3/ICU 56, if offset<poolStringIndex16Limit
  321. * then use the pool bundle's 16-bit-units array,
  322. * otherwise subtract that limit and use the local 16-bit-units array.
  323. *
  324. * Type Name Memory layout of values
  325. * (in parentheses: scalar, non-offset values)
  326. *
  327. * 0 Unicode String: int32_t length, UChar[length], (UChar)0, (padding)
  328. * or (empty string ("") if offset==0)
  329. * 1 Binary: int32_t length, uint8_t[length], (padding)
  330. * - the start of the bytes is 16-aligned -
  331. * 2 Table: uint16_t count, uint16_t keyStringOffsets[count], (uint16_t padding), Resource[count]
  332. * 3 Alias: (physically same value layout as string, new in ICU 2.4)
  333. * 4 Table32: int32_t count, int32_t keyStringOffsets[count], Resource[count]
  334. * (new in formatVersion 1.1/ICU 2.8)
  335. * 5 Table16: uint16_t count, uint16_t keyStringOffsets[count], Resource16[count]
  336. * (stored in the 16-bit-units array; new in formatVersion 2/ICU 4.4)
  337. * 6 Unicode String-v2:UChar[length], (UChar)0; length determined by the first UChar:
  338. * - if first is not a trail surrogate, then the length is implicit
  339. * and u_strlen() needs to be called
  340. * - if first<0xdfef then length=first&0x3ff (and skip first)
  341. * - if first<0xdfff then length=((first-0xdfef)<<16) | second UChar
  342. * - if first==0xdfff then length=((second UChar)<<16) | third UChar
  343. * (stored in the 16-bit-units array; new in formatVersion 2/ICU 4.4)
  344. *
  345. * Starting with formatVersion 3/ICU 56, if offset<poolStringIndexLimit
  346. * then use the pool bundle's 16-bit-units array,
  347. * otherwise subtract that limit and use the local 16-bit-units array.
  348. * (Note different limits for Resource16 vs. Resource.)
  349. *
  350. * 7 Integer: (28-bit offset is integer value)
  351. * 8 Array: int32_t count, Resource[count]
  352. * 9 Array16: uint16_t count, Resource16[count]
  353. * (stored in the 16-bit-units array; new in formatVersion 2/ICU 4.4)
  354. * 14 Integer Vector: int32_t length, int32_t[length]
  355. * 15 Reserved: This value denotes special purpose resources and is for internal use.
  356. *
  357. * Note that there are 3 types with data vector values:
  358. * - Vectors of 8-bit bytes stored as type Binary.
  359. * - Vectors of 16-bit words stored as type Unicode String or Unicode String-v2
  360. * (no value restrictions, all values 0..ffff allowed!).
  361. * - Vectors of 32-bit words stored as type Integer Vector.
  362. */
  363. /*
  364. * Structure for a single, memory-mapped ResourceBundle.
  365. */
  366. typedef struct ResourceData {
  367. UDataMemory *data;
  368. const int32_t *pRoot;
  369. const uint16_t *p16BitUnits;
  370. const char *poolBundleKeys;
  371. Resource rootRes;
  372. int32_t localKeyLimit;
  373. const uint16_t *poolBundleStrings;
  374. int32_t poolStringIndexLimit;
  375. int32_t poolStringIndex16Limit;
  376. UBool noFallback; /* see URES_ATT_NO_FALLBACK */
  377. UBool isPoolBundle;
  378. UBool usesPoolBundle;
  379. UBool useNativeStrcmp;
  380. } ResourceData;
  381. /*
  382. * Read a resource bundle from memory.
  383. */
  384. U_INTERNAL void U_EXPORT2
  385. res_read(ResourceData *pResData,
  386. const UDataInfo *pInfo, const void *inBytes, int32_t length,
  387. UErrorCode *errorCode);
  388. /*
  389. * Load a resource bundle file.
  390. * The ResourceData structure must be allocated externally.
  391. */
  392. U_CFUNC void
  393. res_load(ResourceData *pResData,
  394. const char *path, const char *name, UErrorCode *errorCode);
  395. /*
  396. * Release a resource bundle file.
  397. * This does not release the ResourceData structure itself.
  398. */
  399. U_CFUNC void
  400. res_unload(ResourceData *pResData);
  401. U_INTERNAL UResType U_EXPORT2
  402. res_getPublicType(Resource res);
  403. ///////////////////////////////////////////////////////////////////////////
  404. // To enable tracing, use the inline versions of the res_get* functions. //
  405. ///////////////////////////////////////////////////////////////////////////
  406. /*
  407. * Return a pointer to a zero-terminated, const UChar* string
  408. * and set its length in *pLength.
  409. * Returns NULL if not found.
  410. */
  411. U_INTERNAL const UChar * U_EXPORT2
  412. res_getStringNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
  413. U_INTERNAL const uint8_t * U_EXPORT2
  414. res_getBinaryNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
  415. U_INTERNAL const int32_t * U_EXPORT2
  416. res_getIntVectorNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
  417. U_INTERNAL const UChar * U_EXPORT2
  418. res_getAlias(const ResourceData *pResData, Resource res, int32_t *pLength);
  419. U_INTERNAL Resource U_EXPORT2
  420. res_getResource(const ResourceData *pResData, const char *key);
  421. U_INTERNAL int32_t U_EXPORT2
  422. res_countArrayItems(const ResourceData *pResData, Resource res);
  423. U_INTERNAL Resource U_EXPORT2
  424. res_getArrayItem(const ResourceData *pResData, Resource array, int32_t indexS);
  425. U_INTERNAL Resource U_EXPORT2
  426. res_getTableItemByIndex(const ResourceData *pResData, Resource table, int32_t indexS, const char ** key);
  427. U_INTERNAL Resource U_EXPORT2
  428. res_getTableItemByKey(const ResourceData *pResData, Resource table, int32_t *indexS, const char* * key);
  429. /**
  430. * Iterates over the path and stops when a scalar resource is found.
  431. * Follows aliases.
  432. * Modifies the contents of *path (replacing separators with NULs),
  433. * and also moves *path forward while it finds items.
  434. *
  435. * @param path input: "CollationElements/Sequence" or "zoneStrings/3/2" etc.;
  436. * output: points to the part that has not yet been processed
  437. */
  438. U_CFUNC Resource res_findResource(const ResourceData *pResData, Resource r,
  439. char** path, const char** key);
  440. #ifdef __cplusplus
  441. #include "resource.h"
  442. #include "restrace.h"
  443. U_NAMESPACE_BEGIN
  444. inline const UChar* res_getString(const ResourceTracer& traceInfo,
  445. const ResourceData *pResData, Resource res, int32_t *pLength) {
  446. traceInfo.trace("string");
  447. return res_getStringNoTrace(pResData, res, pLength);
  448. }
  449. inline const uint8_t* res_getBinary(const ResourceTracer& traceInfo,
  450. const ResourceData *pResData, Resource res, int32_t *pLength) {
  451. traceInfo.trace("binary");
  452. return res_getBinaryNoTrace(pResData, res, pLength);
  453. }
  454. inline const int32_t* res_getIntVector(const ResourceTracer& traceInfo,
  455. const ResourceData *pResData, Resource res, int32_t *pLength) {
  456. traceInfo.trace("intvector");
  457. return res_getIntVectorNoTrace(pResData, res, pLength);
  458. }
  459. inline int32_t res_getInt(const ResourceTracer& traceInfo, Resource res) {
  460. traceInfo.trace("int");
  461. return RES_GET_INT_NO_TRACE(res);
  462. }
  463. inline uint32_t res_getUInt(const ResourceTracer& traceInfo, Resource res) {
  464. traceInfo.trace("uint");
  465. return RES_GET_UINT_NO_TRACE(res);
  466. }
  467. class ResourceDataValue : public ResourceValue {
  468. public:
  469. ResourceDataValue() :
  470. res(static_cast<Resource>(URES_NONE)),
  471. fTraceInfo() {}
  472. virtual ~ResourceDataValue();
  473. void setData(const ResourceData *data) {
  474. resData = *data;
  475. }
  476. void setResource(Resource r, ResourceTracer&& traceInfo) {
  477. res = r;
  478. fTraceInfo = traceInfo;
  479. }
  480. const ResourceData &getData() const { return resData; }
  481. virtual UResType getType() const;
  482. virtual const UChar *getString(int32_t &length, UErrorCode &errorCode) const;
  483. virtual const UChar *getAliasString(int32_t &length, UErrorCode &errorCode) const;
  484. virtual int32_t getInt(UErrorCode &errorCode) const;
  485. virtual uint32_t getUInt(UErrorCode &errorCode) const;
  486. virtual const int32_t *getIntVector(int32_t &length, UErrorCode &errorCode) const;
  487. virtual const uint8_t *getBinary(int32_t &length, UErrorCode &errorCode) const;
  488. virtual ResourceArray getArray(UErrorCode &errorCode) const;
  489. virtual ResourceTable getTable(UErrorCode &errorCode) const;
  490. virtual UBool isNoInheritanceMarker() const;
  491. virtual int32_t getStringArray(UnicodeString *dest, int32_t capacity,
  492. UErrorCode &errorCode) const;
  493. virtual int32_t getStringArrayOrStringAsArray(UnicodeString *dest, int32_t capacity,
  494. UErrorCode &errorCode) const;
  495. virtual UnicodeString getStringOrFirstOfArray(UErrorCode &errorCode) const;
  496. private:
  497. // TODO(ICU-20769): If UResourceBundle.fResData becomes a pointer,
  498. // then remove this value field again and just store a pResData pointer.
  499. ResourceData resData;
  500. Resource res;
  501. ResourceTracer fTraceInfo;
  502. };
  503. U_NAMESPACE_END
  504. #endif /* __cplusplus */
  505. /**
  506. * Swap an ICU resource bundle. See udataswp.h.
  507. * @internal
  508. */
  509. U_CAPI int32_t U_EXPORT2
  510. ures_swap(const UDataSwapper *ds,
  511. const void *inData, int32_t length, void *outData,
  512. UErrorCode *pErrorCode);
  513. #endif