michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1996-2013, International Business Machines Corporation michael@0: * and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * File resbund.h michael@0: * michael@0: * CREATED BY michael@0: * Richard Gillam michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 2/5/97 aliu Added scanForLocaleInFile. Added michael@0: * constructor which attempts to read resource bundle michael@0: * from a specific file, without searching other files. michael@0: * 2/11/97 aliu Added UErrorCode return values to constructors. Fixed michael@0: * infinite loops in scanForFile and scanForLocale. michael@0: * Modified getRawResourceData to not delete storage michael@0: * in localeData and resourceData which it doesn't own. michael@0: * Added Mac compatibility #ifdefs for tellp() and michael@0: * ios::nocreate. michael@0: * 2/18/97 helena Updated with 100% documentation coverage. michael@0: * 3/13/97 aliu Rewrote to load in entire resource bundle and store michael@0: * it as a Hashtable of ResourceBundleData objects. michael@0: * Added state table to govern parsing of files. michael@0: * Modified to load locale index out of new file michael@0: * distinct from default.txt. michael@0: * 3/25/97 aliu Modified to support 2-d arrays, needed for timezone michael@0: * data. Added support for custom file suffixes. Again, michael@0: * needed to support timezone data. michael@0: * 4/7/97 aliu Cleaned up. michael@0: * 03/02/99 stephen Removed dependency on FILE*. michael@0: * 03/29/99 helena Merged Bertrand and Stephen's changes. michael@0: * 06/11/99 stephen Removed parsing of .txt files. michael@0: * Reworked to use new binary format. michael@0: * Cleaned up. michael@0: * 06/14/99 stephen Removed methods taking a filename suffix. michael@0: * 11/09/99 weiv Added getLocale(), fRealLocale, removed fRealLocaleID michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #ifndef RESBUND_H michael@0: #define RESBUND_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/ures.h" michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/locid.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Resource Bundle michael@0: */ michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * A class representing a collection of resource information pertaining to a given michael@0: * locale. A resource bundle provides a way of accessing locale- specfic information in michael@0: * a data file. You create a resource bundle that manages the resources for a given michael@0: * locale and then ask it for individual resources. michael@0: *
michael@0: * Resource bundles in ICU4C are currently defined using text files which conform to the following michael@0: * BNF definition. michael@0: * More on resource bundle concepts and syntax can be found in the michael@0: * Users Guide. michael@0: *
michael@0: *
michael@0: * The ResourceBundle class is not suitable for subclassing.
michael@0: *
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: class U_COMMON_API ResourceBundle : public UObject {
michael@0: public:
michael@0: /**
michael@0: * Constructor
michael@0: *
michael@0: * @param packageName The packageName and locale together point to an ICU udata object,
michael@0: * as defined by udata_open( packageName, "res", locale, err)
michael@0: * or equivalent. Typically, packageName will refer to a (.dat) file, or to
michael@0: * a package registered with udata_setAppData(). Using a full file or directory
michael@0: * pathname for packageName is deprecated.
michael@0: * @param locale This is the locale this resource bundle is for. To get resources
michael@0: * for the French locale, for example, you would create a
michael@0: * ResourceBundle passing Locale::FRENCH for the "locale" parameter,
michael@0: * and all subsequent calls to that resource bundle will return
michael@0: * resources that pertain to the French locale. If the caller doesn't
michael@0: * pass a locale parameter, the default locale for the system (as
michael@0: * returned by Locale::getDefault()) will be used.
michael@0: * @param err The Error Code.
michael@0: * The UErrorCode& err parameter is used to return status information to the user. To
michael@0: * check whether the construction succeeded or not, you should check the value of
michael@0: * U_SUCCESS(err). If you wish more detailed information, you can check for
michael@0: * informational error results which still indicate success. U_USING_FALLBACK_WARNING
michael@0: * indicates that a fall back locale was used. For example, 'de_CH' was requested,
michael@0: * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
michael@0: * the default locale data was used; neither the requested locale nor any of its
michael@0: * fall back locales could be found.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle(const UnicodeString& packageName,
michael@0: const Locale& locale,
michael@0: UErrorCode& err);
michael@0:
michael@0: /**
michael@0: * Construct a resource bundle for the default bundle in the specified package.
michael@0: *
michael@0: * @param packageName The packageName and locale together point to an ICU udata object,
michael@0: * as defined by udata_open( packageName, "res", locale, err)
michael@0: * or equivalent. Typically, packageName will refer to a (.dat) file, or to
michael@0: * a package registered with udata_setAppData(). Using a full file or directory
michael@0: * pathname for packageName is deprecated.
michael@0: * @param err A UErrorCode value
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle(const UnicodeString& packageName,
michael@0: UErrorCode& err);
michael@0:
michael@0: /**
michael@0: * Construct a resource bundle for the ICU default bundle.
michael@0: *
michael@0: * @param err A UErrorCode value
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle(UErrorCode &err);
michael@0:
michael@0: /**
michael@0: * Standard constructor, onstructs a resource bundle for the locale-specific
michael@0: * bundle in the specified package.
michael@0: *
michael@0: * @param packageName The packageName and locale together point to an ICU udata object,
michael@0: * as defined by udata_open( packageName, "res", locale, err)
michael@0: * or equivalent. Typically, packageName will refer to a (.dat) file, or to
michael@0: * a package registered with udata_setAppData(). Using a full file or directory
michael@0: * pathname for packageName is deprecated.
michael@0: * NULL is used to refer to ICU data.
michael@0: * @param locale The locale for which to open a resource bundle.
michael@0: * @param err A UErrorCode value
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle(const char* packageName,
michael@0: const Locale& locale,
michael@0: UErrorCode& err);
michael@0:
michael@0: /**
michael@0: * Copy constructor.
michael@0: *
michael@0: * @param original The resource bundle to copy.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle(const ResourceBundle &original);
michael@0:
michael@0: /**
michael@0: * Constructor from a C UResourceBundle. The resource bundle is
michael@0: * copied and not adopted. ures_close will still need to be used on the
michael@0: * original resource bundle.
michael@0: *
michael@0: * @param res A pointer to the C resource bundle.
michael@0: * @param status A UErrorCode value.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle(UResourceBundle *res,
michael@0: UErrorCode &status);
michael@0:
michael@0: /**
michael@0: * Assignment operator.
michael@0: *
michael@0: * @param other The resource bundle to copy.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle&
michael@0: operator=(const ResourceBundle& other);
michael@0:
michael@0: /** Destructor.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: virtual ~ResourceBundle();
michael@0:
michael@0: /**
michael@0: * Clone this object.
michael@0: * Clones can be used concurrently in multiple threads.
michael@0: * If an error occurs, then NULL is returned.
michael@0: * The caller must delete the clone.
michael@0: *
michael@0: * @return a clone of this object
michael@0: *
michael@0: * @see getDynamicClassID
michael@0: * @stable ICU 2.8
michael@0: */
michael@0: ResourceBundle *clone() const;
michael@0:
michael@0: /**
michael@0: * Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is
michael@0: * the number of child resources.
michael@0: * @warning Integer array is treated as a scalar type. There are no
michael@0: * APIs to access individual members of an integer array. It
michael@0: * is always returned as a whole.
michael@0: *
michael@0: * @return number of resources in a given resource.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: int32_t
michael@0: getSize(void) const;
michael@0:
michael@0: /**
michael@0: * returns a string from a string resource type
michael@0: *
michael@0: * @param status fills in the outgoing error code
michael@0: * could be U_MISSING_RESOURCE_ERROR if the key is not found
michael@0: * could be a warning
michael@0: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
michael@0: * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UnicodeString
michael@0: getString(UErrorCode& status) const;
michael@0:
michael@0: /**
michael@0: * returns a binary data from a resource. Can be used at most primitive resource types (binaries,
michael@0: * strings, ints)
michael@0: *
michael@0: * @param len fills in the length of resulting byte chunk
michael@0: * @param status fills in the outgoing error code
michael@0: * could be U_MISSING_RESOURCE_ERROR if the key is not found
michael@0: * could be a warning
michael@0: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
michael@0: * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: const uint8_t*
michael@0: getBinary(int32_t& len, UErrorCode& status) const;
michael@0:
michael@0:
michael@0: /**
michael@0: * returns an integer vector from a resource.
michael@0: *
michael@0: * @param len fills in the length of resulting integer vector
michael@0: * @param status fills in the outgoing error code
michael@0: * could be U_MISSING_RESOURCE_ERROR if the key is not found
michael@0: * could be a warning
michael@0: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
michael@0: * @return a pointer to a vector of integers that lives in a memory mapped/DLL file.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: const int32_t*
michael@0: getIntVector(int32_t& len, UErrorCode& status) const;
michael@0:
michael@0: /**
michael@0: * returns an unsigned integer from a resource.
michael@0: * This integer is originally 28 bits.
michael@0: *
michael@0: * @param status fills in the outgoing error code
michael@0: * could be U_MISSING_RESOURCE_ERROR if the key is not found
michael@0: * could be a warning
michael@0: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
michael@0: * @return an unsigned integer value
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: uint32_t
michael@0: getUInt(UErrorCode& status) const;
michael@0:
michael@0: /**
michael@0: * returns a signed integer from a resource.
michael@0: * This integer is originally 28 bit and the sign gets propagated.
michael@0: *
michael@0: * @param status fills in the outgoing error code
michael@0: * could be U_MISSING_RESOURCE_ERROR if the key is not found
michael@0: * could be a warning
michael@0: * e.g.: U_USING_FALLBACK_WARNING,U_USING_DEFAULT_WARNING
michael@0: * @return a signed integer value
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: int32_t
michael@0: getInt(UErrorCode& status) const;
michael@0:
michael@0: /**
michael@0: * Checks whether the resource has another element to iterate over.
michael@0: *
michael@0: * @return TRUE if there are more elements, FALSE if there is no more elements
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UBool
michael@0: hasNext(void) const;
michael@0:
michael@0: /**
michael@0: * Resets the internal context of a resource so that iteration starts from the first element.
michael@0: *
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: void
michael@0: resetIterator(void);
michael@0:
michael@0: /**
michael@0: * Returns the key associated with this resource. Not all the resources have a key - only
michael@0: * those that are members of a table.
michael@0: *
michael@0: * @return a key associated to this resource, or NULL if it doesn't have a key
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: const char*
michael@0: getKey(void) const;
michael@0:
michael@0: /**
michael@0: * Gets the locale ID of the resource bundle as a string.
michael@0: * Same as getLocale().getName() .
michael@0: *
michael@0: * @return the locale ID of the resource bundle as a string
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: const char*
michael@0: getName(void) const;
michael@0:
michael@0:
michael@0: /**
michael@0: * Returns the type of a resource. Available types are defined in enum UResType
michael@0: *
michael@0: * @return type of the given resource.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UResType
michael@0: getType(void) const;
michael@0:
michael@0: /**
michael@0: * Returns the next resource in a given resource or NULL if there are no more resources
michael@0: *
michael@0: * @param status fills in the outgoing error code
michael@0: * @return ResourceBundle object.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle
michael@0: getNext(UErrorCode& status);
michael@0:
michael@0: /**
michael@0: * Returns the next string in a resource or NULL if there are no more resources
michael@0: * to iterate over.
michael@0: *
michael@0: * @param status fills in the outgoing error code
michael@0: * @return an UnicodeString object.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UnicodeString
michael@0: getNextString(UErrorCode& status);
michael@0:
michael@0: /**
michael@0: * Returns the next string in a resource or NULL if there are no more resources
michael@0: * to iterate over.
michael@0: *
michael@0: * @param key fill in for key associated with this string
michael@0: * @param status fills in the outgoing error code
michael@0: * @return an UnicodeString object.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UnicodeString
michael@0: getNextString(const char ** key,
michael@0: UErrorCode& status);
michael@0:
michael@0: /**
michael@0: * Returns the resource in a resource at the specified index.
michael@0: *
michael@0: * @param index an index to the wanted resource.
michael@0: * @param status fills in the outgoing error code
michael@0: * @return ResourceBundle object. If there is an error, resource is invalid.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle
michael@0: get(int32_t index,
michael@0: UErrorCode& status) const;
michael@0:
michael@0: /**
michael@0: * Returns the string in a given resource at the specified index.
michael@0: *
michael@0: * @param index an index to the wanted string.
michael@0: * @param status fills in the outgoing error code
michael@0: * @return an UnicodeString object. If there is an error, string is bogus
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UnicodeString
michael@0: getStringEx(int32_t index,
michael@0: UErrorCode& status) const;
michael@0:
michael@0: /**
michael@0: * Returns a resource in a resource that has a given key. This procedure works only with table
michael@0: * resources.
michael@0: *
michael@0: * @param key a key associated with the wanted resource
michael@0: * @param status fills in the outgoing error code.
michael@0: * @return ResourceBundle object. If there is an error, resource is invalid.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: ResourceBundle
michael@0: get(const char* key,
michael@0: UErrorCode& status) const;
michael@0:
michael@0: /**
michael@0: * Returns a string in a resource that has a given key. This procedure works only with table
michael@0: * resources.
michael@0: *
michael@0: * @param key a key associated with the wanted string
michael@0: * @param status fills in the outgoing error code
michael@0: * @return an UnicodeString object. If there is an error, string is bogus
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UnicodeString
michael@0: getStringEx(const char* key,
michael@0: UErrorCode& status) const;
michael@0:
michael@0: #ifndef U_HIDE_DEPRECATED_API
michael@0: /**
michael@0: * Return the version number associated with this ResourceBundle as a string. Please
michael@0: * use getVersion, as this method is going to be deprecated.
michael@0: *
michael@0: * @return A version number string as specified in the resource bundle or its parent.
michael@0: * The caller does not own this string.
michael@0: * @see getVersion
michael@0: * @deprecated ICU 2.8 Use getVersion instead.
michael@0: */
michael@0: const char*
michael@0: getVersionNumber(void) const;
michael@0: #endif /* U_HIDE_DEPRECATED_API */
michael@0:
michael@0: /**
michael@0: * Return the version number associated with this ResourceBundle as a UVersionInfo array.
michael@0: *
michael@0: * @param versionInfo A UVersionInfo array that is filled with the version number
michael@0: * as specified in the resource bundle or its parent.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: void
michael@0: getVersion(UVersionInfo versionInfo) const;
michael@0:
michael@0: #ifndef U_HIDE_DEPRECATED_API
michael@0: /**
michael@0: * Return the Locale associated with this ResourceBundle.
michael@0: *
michael@0: * @return a Locale object
michael@0: * @deprecated ICU 2.8 Use getLocale(ULocDataLocaleType type, UErrorCode &status) overload instead.
michael@0: */
michael@0: const Locale&
michael@0: getLocale(void) const;
michael@0: #endif /* U_HIDE_DEPRECATED_API */
michael@0:
michael@0: /**
michael@0: * Return the Locale associated with this ResourceBundle.
michael@0: * @param type You can choose between requested, valid and actual
michael@0: * locale. For description see the definition of
michael@0: * ULocDataLocaleType in uloc.h
michael@0: * @param status just for catching illegal arguments
michael@0: *
michael@0: * @return a Locale object
michael@0: * @stable ICU 2.8
michael@0: */
michael@0: const Locale
michael@0: getLocale(ULocDataLocaleType type, UErrorCode &status) const;
michael@0: #ifndef U_HIDE_INTERNAL_API
michael@0: /**
michael@0: * This API implements multilevel fallback
michael@0: * @internal
michael@0: */
michael@0: ResourceBundle
michael@0: getWithFallback(const char* key, UErrorCode& status);
michael@0: #endif /* U_HIDE_INTERNAL_API */
michael@0: /**
michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class.
michael@0: *
michael@0: * @stable ICU 2.2
michael@0: */
michael@0: virtual UClassID getDynamicClassID() const;
michael@0:
michael@0: /**
michael@0: * ICU "poor man's RTTI", returns a UClassID for this class.
michael@0: *
michael@0: * @stable ICU 2.2
michael@0: */
michael@0: static UClassID U_EXPORT2 getStaticClassID();
michael@0:
michael@0: private:
michael@0: ResourceBundle(); // default constructor not implemented
michael@0:
michael@0: UResourceBundle *fResource;
michael@0: void constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error);
michael@0: Locale *fLocale;
michael@0: };
michael@0:
michael@0: U_NAMESPACE_END
michael@0: #endif