+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
-* Copyright (C) 1999-2015, International Business Machines
+* Copyright (C) 1999-2016, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: uresdata.h
-* encoding: US-ASCII
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
#define RES_GET_OFFSET(res) ((res)&0x0fffffff)
#define RES_GET_POINTER(pRoot, res) ((pRoot)+RES_GET_OFFSET(res))
-/* get signed and unsigned integer values directly from the Resource handle */
+/* get signed and unsigned integer values directly from the Resource handle
+ * NOTE: For proper logging, please use the res_getInt() constexpr
+ */
#if U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC
-# define RES_GET_INT(res) (((int32_t)((res)<<4L))>>4L)
+# define RES_GET_INT_NO_TRACE(res) (((int32_t)((res)<<4L))>>4L)
#else
-# define RES_GET_INT(res) (int32_t)(((res)&0x08000000) ? (res)|0xf0000000 : (res)&0x07ffffff)
+# define RES_GET_INT_NO_TRACE(res) (int32_t)(((res)&0x08000000) ? (res)|0xf0000000 : (res)&0x07ffffff)
#endif
-#define RES_GET_UINT(res) ((res)&0x0fffffff)
+#define RES_GET_UINT_NO_TRACE(res) ((res)&0x0fffffff)
#define URES_IS_ARRAY(type) ((int32_t)(type)==URES_ARRAY || (int32_t)(type)==URES_ARRAY16)
#define URES_IS_TABLE(type) ((int32_t)(type)==URES_TABLE || (int32_t)(type)==URES_TABLE16 || (int32_t)(type)==URES_TABLE32)
/*
* Structure for a single, memory-mapped ResourceBundle.
*/
-typedef struct {
+typedef struct ResourceData {
UDataMemory *data;
const int32_t *pRoot;
const uint16_t *p16BitUnits;
U_INTERNAL UResType U_EXPORT2
res_getPublicType(Resource res);
+///////////////////////////////////////////////////////////////////////////
+// To enable tracing, use the inline versions of the res_get* functions. //
+///////////////////////////////////////////////////////////////////////////
+
/*
* Return a pointer to a zero-terminated, const UChar* string
* and set its length in *pLength.
* Returns NULL if not found.
*/
U_INTERNAL const UChar * U_EXPORT2
-res_getString(const ResourceData *pResData, Resource res, int32_t *pLength);
-
-U_INTERNAL const UChar * U_EXPORT2
-res_getAlias(const ResourceData *pResData, Resource res, int32_t *pLength);
+res_getStringNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
U_INTERNAL const uint8_t * U_EXPORT2
-res_getBinary(const ResourceData *pResData, Resource res, int32_t *pLength);
+res_getBinaryNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
U_INTERNAL const int32_t * U_EXPORT2
-res_getIntVector(const ResourceData *pResData, Resource res, int32_t *pLength);
+res_getIntVectorNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
+
+U_INTERNAL const UChar * U_EXPORT2
+res_getAlias(const ResourceData *pResData, Resource res, int32_t *pLength);
U_INTERNAL Resource U_EXPORT2
res_getResource(const ResourceData *pResData, const char *key);
#ifdef __cplusplus
#include "resource.h"
+#include "restrace.h"
U_NAMESPACE_BEGIN
+inline const UChar* res_getString(const ResourceTracer& traceInfo,
+ const ResourceData *pResData, Resource res, int32_t *pLength) {
+ traceInfo.trace("string");
+ return res_getStringNoTrace(pResData, res, pLength);
+}
+
+inline const uint8_t* res_getBinary(const ResourceTracer& traceInfo,
+ const ResourceData *pResData, Resource res, int32_t *pLength) {
+ traceInfo.trace("binary");
+ return res_getBinaryNoTrace(pResData, res, pLength);
+}
+
+inline const int32_t* res_getIntVector(const ResourceTracer& traceInfo,
+ const ResourceData *pResData, Resource res, int32_t *pLength) {
+ traceInfo.trace("intvector");
+ return res_getIntVectorNoTrace(pResData, res, pLength);
+}
+
+inline int32_t res_getInt(const ResourceTracer& traceInfo, Resource res) {
+ traceInfo.trace("int");
+ return RES_GET_INT_NO_TRACE(res);
+}
+
+inline uint32_t res_getUInt(const ResourceTracer& traceInfo, Resource res) {
+ traceInfo.trace("uint");
+ return RES_GET_UINT_NO_TRACE(res);
+}
+
class ResourceDataValue : public ResourceValue {
public:
- ResourceDataValue() : pResData(NULL), res(URES_NONE) {}
+ ResourceDataValue() :
+ res(static_cast<Resource>(URES_NONE)),
+ fTraceInfo() {}
virtual ~ResourceDataValue();
- void setData(const ResourceData *data) { pResData = data; }
- void setResource(Resource r) { res = r; }
+ void setData(const ResourceData *data) {
+ resData = *data;
+ }
+
+ void setResource(Resource r, ResourceTracer&& traceInfo) {
+ res = r;
+ fTraceInfo = traceInfo;
+ }
+ const ResourceData &getData() const { return resData; }
virtual UResType getType() const;
virtual const UChar *getString(int32_t &length, UErrorCode &errorCode) const;
virtual const UChar *getAliasString(int32_t &length, UErrorCode &errorCode) const;
virtual uint32_t getUInt(UErrorCode &errorCode) const;
virtual const int32_t *getIntVector(int32_t &length, UErrorCode &errorCode) const;
virtual const uint8_t *getBinary(int32_t &length, UErrorCode &errorCode) const;
-
- const ResourceData *pResData;
+ virtual ResourceArray getArray(UErrorCode &errorCode) const;
+ virtual ResourceTable getTable(UErrorCode &errorCode) const;
+ virtual UBool isNoInheritanceMarker() const;
+ virtual int32_t getStringArray(UnicodeString *dest, int32_t capacity,
+ UErrorCode &errorCode) const;
+ virtual int32_t getStringArrayOrStringAsArray(UnicodeString *dest, int32_t capacity,
+ UErrorCode &errorCode) const;
+ virtual UnicodeString getStringOrFirstOfArray(UErrorCode &errorCode) const;
private:
+ // TODO(ICU-20769): If UResourceBundle.fResData becomes a pointer,
+ // then remove this value field again and just store a pResData pointer.
+ ResourceData resData;
Resource res;
+ ResourceTracer fTraceInfo;
};
U_NAMESPACE_END
-/**
- * @param value will be set during enumeration; input contents is ignored
- * @param sink receives all table item key-value pairs
- */
-U_CFUNC void
-ures_getAllTableItems(const ResourceData *pResData, Resource table,
- icu::ResourceDataValue &value, icu::ResourceTableSink &sink,
- UErrorCode &errorCode);
-
-/**
- * @param value will be set during enumeration; input contents is ignored
- * @param sink receives all array item values
- */
-U_CFUNC void
-ures_getAllArrayItems(const ResourceData *pResData, Resource array,
- icu::ResourceDataValue &value, icu::ResourceArraySink &sink,
- UErrorCode &errorCode);
-
#endif /* __cplusplus */
/**