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