Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/resbund.h
38827 views
/*1******************************************************************************2*3* Copyright (C) 1996-2013, International Business Machines Corporation4* and others. All Rights Reserved.5*6******************************************************************************7*8* File resbund.h9*10* CREATED BY11* Richard Gillam12*13* Modification History:14*15* Date Name Description16* 2/5/97 aliu Added scanForLocaleInFile. Added17* constructor which attempts to read resource bundle18* from a specific file, without searching other files.19* 2/11/97 aliu Added UErrorCode return values to constructors. Fixed20* infinite loops in scanForFile and scanForLocale.21* Modified getRawResourceData to not delete storage22* in localeData and resourceData which it doesn't own.23* Added Mac compatibility #ifdefs for tellp() and24* ios::nocreate.25* 2/18/97 helena Updated with 100% documentation coverage.26* 3/13/97 aliu Rewrote to load in entire resource bundle and store27* it as a Hashtable of ResourceBundleData objects.28* Added state table to govern parsing of files.29* Modified to load locale index out of new file30* distinct from default.txt.31* 3/25/97 aliu Modified to support 2-d arrays, needed for timezone32* data. Added support for custom file suffixes. Again,33* needed to support timezone data.34* 4/7/97 aliu Cleaned up.35* 03/02/99 stephen Removed dependency on FILE*.36* 03/29/99 helena Merged Bertrand and Stephen's changes.37* 06/11/99 stephen Removed parsing of .txt files.38* Reworked to use new binary format.39* Cleaned up.40* 06/14/99 stephen Removed methods taking a filename suffix.41* 11/09/99 weiv Added getLocale(), fRealLocale, removed fRealLocaleID42******************************************************************************43*/4445#ifndef RESBUND_H46#define RESBUND_H4748#include "unicode/utypes.h"49#include "unicode/uobject.h"50#include "unicode/ures.h"51#include "unicode/unistr.h"52#include "unicode/locid.h"5354/**55* \file56* \brief C++ API: Resource Bundle57*/5859U_NAMESPACE_BEGIN6061/**62* A class representing a collection of resource information pertaining to a given63* locale. A resource bundle provides a way of accessing locale- specfic information in64* a data file. You create a resource bundle that manages the resources for a given65* locale and then ask it for individual resources.66* <P>67* Resource bundles in ICU4C are currently defined using text files which conform to the following68* <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.69* More on resource bundle concepts and syntax can be found in the70* <a href="http://icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.71* <P>72*73* The ResourceBundle class is not suitable for subclassing.74*75* @stable ICU 2.076*/77class U_COMMON_API ResourceBundle : public UObject {78public:79/**80* Constructor81*82* @param packageName The packageName and locale together point to an ICU udata object,83* as defined by <code> udata_open( packageName, "res", locale, err) </code>84* or equivalent. Typically, packageName will refer to a (.dat) file, or to85* a package registered with udata_setAppData(). Using a full file or directory86* pathname for packageName is deprecated.87* @param locale This is the locale this resource bundle is for. To get resources88* for the French locale, for example, you would create a89* ResourceBundle passing Locale::FRENCH for the "locale" parameter,90* and all subsequent calls to that resource bundle will return91* resources that pertain to the French locale. If the caller doesn't92* pass a locale parameter, the default locale for the system (as93* returned by Locale::getDefault()) will be used.94* @param err The Error Code.95* The UErrorCode& err parameter is used to return status information to the user. To96* check whether the construction succeeded or not, you should check the value of97* U_SUCCESS(err). If you wish more detailed information, you can check for98* informational error results which still indicate success. U_USING_FALLBACK_WARNING99* indicates that a fall back locale was used. For example, 'de_CH' was requested,100* but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that101* the default locale data was used; neither the requested locale nor any of its102* fall back locales could be found.103* @stable ICU 2.0104*/105ResourceBundle(const UnicodeString& packageName,106const Locale& locale,107UErrorCode& err);108109/**110* Construct a resource bundle for the default bundle in the specified package.111*112* @param packageName The packageName and locale together point to an ICU udata object,113* as defined by <code> udata_open( packageName, "res", locale, err) </code>114* or equivalent. Typically, packageName will refer to a (.dat) file, or to115* a package registered with udata_setAppData(). Using a full file or directory116* pathname for packageName is deprecated.117* @param err A UErrorCode value118* @stable ICU 2.0119*/120ResourceBundle(const UnicodeString& packageName,121UErrorCode& err);122123/**124* Construct a resource bundle for the ICU default bundle.125*126* @param err A UErrorCode value127* @stable ICU 2.0128*/129ResourceBundle(UErrorCode &err);130131/**132* Standard constructor, onstructs a resource bundle for the locale-specific133* bundle in the specified package.134*135* @param packageName The packageName and locale together point to an ICU udata object,136* as defined by <code> udata_open( packageName, "res", locale, err) </code>137* or equivalent. Typically, packageName will refer to a (.dat) file, or to138* a package registered with udata_setAppData(). Using a full file or directory139* pathname for packageName is deprecated.140* NULL is used to refer to ICU data.141* @param locale The locale for which to open a resource bundle.142* @param err A UErrorCode value143* @stable ICU 2.0144*/145ResourceBundle(const char* packageName,146const Locale& locale,147UErrorCode& err);148149/**150* Copy constructor.151*152* @param original The resource bundle to copy.153* @stable ICU 2.0154*/155ResourceBundle(const ResourceBundle &original);156157/**158* Constructor from a C UResourceBundle. The resource bundle is159* copied and not adopted. ures_close will still need to be used on the160* original resource bundle.161*162* @param res A pointer to the C resource bundle.163* @param status A UErrorCode value.164* @stable ICU 2.0165*/166ResourceBundle(UResourceBundle *res,167UErrorCode &status);168169/**170* Assignment operator.171*172* @param other The resource bundle to copy.173* @stable ICU 2.0174*/175ResourceBundle&176operator=(const ResourceBundle& other);177178/** Destructor.179* @stable ICU 2.0180*/181virtual ~ResourceBundle();182183/**184* Clone this object.185* Clones can be used concurrently in multiple threads.186* If an error occurs, then NULL is returned.187* The caller must delete the clone.188*189* @return a clone of this object190*191* @see getDynamicClassID192* @stable ICU 2.8193*/194ResourceBundle *clone() const;195196/**197* Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is198* the number of child resources.199* @warning Integer array is treated as a scalar type. There are no200* APIs to access individual members of an integer array. It201* is always returned as a whole.202*203* @return number of resources in a given resource.204* @stable ICU 2.0205*/206int32_t207getSize(void) const;208209/**210* returns a string from a string resource type211*212* @param status fills in the outgoing error code213* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found214* could be a warning215* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>216* @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.217* @stable ICU 2.0218*/219UnicodeString220getString(UErrorCode& status) const;221222/**223* returns a binary data from a resource. Can be used at most primitive resource types (binaries,224* strings, ints)225*226* @param len fills in the length of resulting byte chunk227* @param status fills in the outgoing error code228* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found229* could be a warning230* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>231* @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.232* @stable ICU 2.0233*/234const uint8_t*235getBinary(int32_t& len, UErrorCode& status) const;236237238/**239* returns an integer vector from a resource.240*241* @param len fills in the length of resulting integer vector242* @param status fills in the outgoing error code243* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found244* could be a warning245* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>246* @return a pointer to a vector of integers that lives in a memory mapped/DLL file.247* @stable ICU 2.0248*/249const int32_t*250getIntVector(int32_t& len, UErrorCode& status) const;251252/**253* returns an unsigned integer from a resource.254* This integer is originally 28 bits.255*256* @param status fills in the outgoing error code257* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found258* could be a warning259* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>260* @return an unsigned integer value261* @stable ICU 2.0262*/263uint32_t264getUInt(UErrorCode& status) const;265266/**267* returns a signed integer from a resource.268* This integer is originally 28 bit and the sign gets propagated.269*270* @param status fills in the outgoing error code271* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found272* could be a warning273* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>274* @return a signed integer value275* @stable ICU 2.0276*/277int32_t278getInt(UErrorCode& status) const;279280/**281* Checks whether the resource has another element to iterate over.282*283* @return TRUE if there are more elements, FALSE if there is no more elements284* @stable ICU 2.0285*/286UBool287hasNext(void) const;288289/**290* Resets the internal context of a resource so that iteration starts from the first element.291*292* @stable ICU 2.0293*/294void295resetIterator(void);296297/**298* Returns the key associated with this resource. Not all the resources have a key - only299* those that are members of a table.300*301* @return a key associated to this resource, or NULL if it doesn't have a key302* @stable ICU 2.0303*/304const char*305getKey(void) const;306307/**308* Gets the locale ID of the resource bundle as a string.309* Same as getLocale().getName() .310*311* @return the locale ID of the resource bundle as a string312* @stable ICU 2.0313*/314const char*315getName(void) const;316317318/**319* Returns the type of a resource. Available types are defined in enum UResType320*321* @return type of the given resource.322* @stable ICU 2.0323*/324UResType325getType(void) const;326327/**328* Returns the next resource in a given resource or NULL if there are no more resources329*330* @param status fills in the outgoing error code331* @return ResourceBundle object.332* @stable ICU 2.0333*/334ResourceBundle335getNext(UErrorCode& status);336337/**338* Returns the next string in a resource or NULL if there are no more resources339* to iterate over.340*341* @param status fills in the outgoing error code342* @return an UnicodeString object.343* @stable ICU 2.0344*/345UnicodeString346getNextString(UErrorCode& status);347348/**349* Returns the next string in a resource or NULL if there are no more resources350* to iterate over.351*352* @param key fill in for key associated with this string353* @param status fills in the outgoing error code354* @return an UnicodeString object.355* @stable ICU 2.0356*/357UnicodeString358getNextString(const char ** key,359UErrorCode& status);360361/**362* Returns the resource in a resource at the specified index.363*364* @param index an index to the wanted resource.365* @param status fills in the outgoing error code366* @return ResourceBundle object. If there is an error, resource is invalid.367* @stable ICU 2.0368*/369ResourceBundle370get(int32_t index,371UErrorCode& status) const;372373/**374* Returns the string in a given resource at the specified index.375*376* @param index an index to the wanted string.377* @param status fills in the outgoing error code378* @return an UnicodeString object. If there is an error, string is bogus379* @stable ICU 2.0380*/381UnicodeString382getStringEx(int32_t index,383UErrorCode& status) const;384385/**386* Returns a resource in a resource that has a given key. This procedure works only with table387* resources.388*389* @param key a key associated with the wanted resource390* @param status fills in the outgoing error code.391* @return ResourceBundle object. If there is an error, resource is invalid.392* @stable ICU 2.0393*/394ResourceBundle395get(const char* key,396UErrorCode& status) const;397398/**399* Returns a string in a resource that has a given key. This procedure works only with table400* resources.401*402* @param key a key associated with the wanted string403* @param status fills in the outgoing error code404* @return an UnicodeString object. If there is an error, string is bogus405* @stable ICU 2.0406*/407UnicodeString408getStringEx(const char* key,409UErrorCode& status) const;410411#ifndef U_HIDE_DEPRECATED_API412/**413* Return the version number associated with this ResourceBundle as a string. Please414* use getVersion, as this method is going to be deprecated.415*416* @return A version number string as specified in the resource bundle or its parent.417* The caller does not own this string.418* @see getVersion419* @deprecated ICU 2.8 Use getVersion instead.420*/421const char*422getVersionNumber(void) const;423#endif /* U_HIDE_DEPRECATED_API */424425/**426* Return the version number associated with this ResourceBundle as a UVersionInfo array.427*428* @param versionInfo A UVersionInfo array that is filled with the version number429* as specified in the resource bundle or its parent.430* @stable ICU 2.0431*/432void433getVersion(UVersionInfo versionInfo) const;434435#ifndef U_HIDE_DEPRECATED_API436/**437* Return the Locale associated with this ResourceBundle.438*439* @return a Locale object440* @deprecated ICU 2.8 Use getLocale(ULocDataLocaleType type, UErrorCode &status) overload instead.441*/442const Locale&443getLocale(void) const;444#endif /* U_HIDE_DEPRECATED_API */445446/**447* Return the Locale associated with this ResourceBundle.448* @param type You can choose between requested, valid and actual449* locale. For description see the definition of450* ULocDataLocaleType in uloc.h451* @param status just for catching illegal arguments452*453* @return a Locale object454* @stable ICU 2.8455*/456const Locale457getLocale(ULocDataLocaleType type, UErrorCode &status) const;458#ifndef U_HIDE_INTERNAL_API459/**460* This API implements multilevel fallback461* @internal462*/463ResourceBundle464getWithFallback(const char* key, UErrorCode& status);465#endif /* U_HIDE_INTERNAL_API */466/**467* ICU "poor man's RTTI", returns a UClassID for the actual class.468*469* @stable ICU 2.2470*/471virtual UClassID getDynamicClassID() const;472473/**474* ICU "poor man's RTTI", returns a UClassID for this class.475*476* @stable ICU 2.2477*/478static UClassID U_EXPORT2 getStaticClassID();479480private:481ResourceBundle(); // default constructor not implemented482483UResourceBundle *fResource;484void constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error);485Locale *fLocale;486};487488U_NAMESPACE_END489#endif490491492