]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/uresimp.h
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / common / uresimp.h
index b8ec5a61cac83089e51a98dfe7fe2c7fc15f4b72..51db6c52634848ac2edf541eadb889d59d45d79c 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 **********************************************************************
-*   Copyright (C) 2000-2014, International Business Machines
+*   Copyright (C) 2000-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 */
@@ -9,6 +11,7 @@
 #define URESIMP_H
 
 #include "unicode/ures.h"
+#include "unicode/utypes.h"
 
 #include "uresdata.h"
 
@@ -80,6 +83,60 @@ struct UResourceBundle {
 
 U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
 
+#ifdef __cplusplus
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class StackUResourceBundle
+ * "Smart pointer" like class, closes a UResourceBundle via ures_close().
+ *
+ * This code:
+ *
+ *   StackUResourceBundle bundle;
+ *   foo(bundle.getAlias());
+ *
+ * Is equivalent to this code:
+ *
+ *   UResourceBundle bundle;
+ *   ures_initStackObject(&bundle);
+ *   foo(&bundle);
+ *   ures_close(&bundle);
+ *
+ * @see LocalUResourceBundlePointer
+ * @internal
+ */
+class U_COMMON_API StackUResourceBundle {
+public:
+    // No heap allocation. Use only on the stack.
+    static void* U_EXPORT2 operator new(size_t) U_NOEXCEPT = delete;
+    static void* U_EXPORT2 operator new[](size_t) U_NOEXCEPT = delete;
+#if U_HAVE_PLACEMENT_NEW
+    static void* U_EXPORT2 operator new(size_t, void*) U_NOEXCEPT = delete;
+#endif
+
+    StackUResourceBundle();
+    ~StackUResourceBundle();
+
+    UResourceBundle* getAlias() { return &bundle; }
+
+    UResourceBundle& ref() { return bundle; }
+    const UResourceBundle& ref() const { return bundle; }
+
+    StackUResourceBundle(const StackUResourceBundle&) = delete;
+    StackUResourceBundle& operator=(const StackUResourceBundle&) = delete;
+
+    StackUResourceBundle(StackUResourceBundle&&) = delete;
+    StackUResourceBundle& operator=(StackUResourceBundle&&) = delete;
+
+private:
+    UResourceBundle bundle;
+};
+
+U_NAMESPACE_END
+
+#endif  /* __cplusplus */
+
 /**
  * Opens a resource bundle for the locale;
  * if there is not even a base language bundle, then loads the root bundle;
@@ -222,6 +279,14 @@ ures_getStringByKeyWithFallback(const UResourceBundle *resB,
                           int32_t* len,
                           UErrorCode *status);
 
+#ifdef __cplusplus
+
+U_CAPI void U_EXPORT2
+ures_getAllItemsWithFallback(const UResourceBundle *bundle, const char *path,
+                             icu::ResourceSink &sink, UErrorCode &errorCode);
+
+#endif  /* __cplusplus */
+
 /**
  * Get a version number by key
  * @param resB bundle containing version number
@@ -265,4 +330,27 @@ U_CAPI const char* U_EXPORT2
 ures_getLocaleInternal(const UResourceBundle* resourceBundle, 
                UErrorCode* status);
 
+/**
+ * Same as ures_openDirect() but uses the fill-in parameter instead of allocating a new bundle.
+ * 
+ * @param r The existing UResourceBundle to fill in. If NULL then status will be
+ *          set to U_ILLEGAL_ARGUMENT_ERROR.
+ * @param packageName   The packageName and locale together point to an ICU udata object,
+ *                      as defined by <code> udata_open( packageName, "res", locale, err) </code>
+ *                      or equivalent.  Typically, packageName will refer to a (.dat) file, or to
+ *                      a package registered with udata_setAppData(). Using a full file or directory
+ *                      pathname for packageName is deprecated. If NULL, ICU data will be used.
+ * @param locale  specifies the locale for which we want to open the resource
+ *                if NULL, the default locale will be used. If strlen(locale) == 0
+ *                root locale will be used.
+ * @param status The error code.
+ * @see ures_openDirect
+ * @internal
+ */
+U_CAPI void U_EXPORT2
+ures_openDirectFillIn(UResourceBundle *r,
+                      const char *packageName,
+                      const char *locale,
+                      UErrorCode *status);
+
 #endif /*URESIMP_H*/