michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2009-2011, International Business Machines Corporation and * michael@0: * others. All Rights Reserved. * michael@0: ******************************************************************************* michael@0: */ michael@0: #ifndef CURRPINF_H michael@0: #define CURRPINF_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Currency Plural Information used by Decimal Format michael@0: */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/unistr.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class Locale; michael@0: class PluralRules; michael@0: class Hashtable; michael@0: michael@0: /** michael@0: * This class represents the information needed by michael@0: * DecimalFormat to format currency plural, michael@0: * such as "3.00 US dollars" or "1.00 US dollar". michael@0: * DecimalFormat creates for itself an instance of michael@0: * CurrencyPluralInfo from its locale data. michael@0: * If you need to change any of these symbols, you can get the michael@0: * CurrencyPluralInfo object from your michael@0: * DecimalFormat and modify it. michael@0: * michael@0: * Following are the information needed for currency plural format and parse: michael@0: * locale information, michael@0: * plural rule of the locale, michael@0: * currency plural pattern of the locale. michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: class U_I18N_API CurrencyPluralInfo : public UObject { michael@0: public: michael@0: michael@0: /** michael@0: * Create a CurrencyPluralInfo object for the default locale. michael@0: * @param status output param set to success/failure code on exit michael@0: * @stable ICU 4.2 michael@0: */ michael@0: CurrencyPluralInfo(UErrorCode& status); michael@0: michael@0: /** michael@0: * Create a CurrencyPluralInfo object for the given locale. michael@0: * @param locale the locale michael@0: * @param status output param set to success/failure code on exit michael@0: * @stable ICU 4.2 michael@0: */ michael@0: CurrencyPluralInfo(const Locale& locale, UErrorCode& status); michael@0: michael@0: /** michael@0: * Copy constructor michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: CurrencyPluralInfo(const CurrencyPluralInfo& info); michael@0: michael@0: michael@0: /** michael@0: * Assignment operator michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: CurrencyPluralInfo& operator=(const CurrencyPluralInfo& info); michael@0: michael@0: michael@0: /** michael@0: * Destructor michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual ~CurrencyPluralInfo(); michael@0: michael@0: michael@0: /** michael@0: * Equal operator. michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: UBool operator==(const CurrencyPluralInfo& info) const; michael@0: michael@0: michael@0: /** michael@0: * Not equal operator michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: UBool operator!=(const CurrencyPluralInfo& info) const; michael@0: michael@0: michael@0: /** michael@0: * Clone michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: CurrencyPluralInfo* clone() const; michael@0: michael@0: michael@0: /** michael@0: * Gets plural rules of this locale, used for currency plural format michael@0: * michael@0: * @return plural rule michael@0: * @stable ICU 4.2 michael@0: */ michael@0: const PluralRules* getPluralRules() const; michael@0: michael@0: /** michael@0: * Given a plural count, gets currency plural pattern of this locale, michael@0: * used for currency plural format michael@0: * michael@0: * @param pluralCount currency plural count michael@0: * @param result output param to receive the pattern michael@0: * @return a currency plural pattern based on plural count michael@0: * @stable ICU 4.2 michael@0: */ michael@0: UnicodeString& getCurrencyPluralPattern(const UnicodeString& pluralCount, michael@0: UnicodeString& result) const; michael@0: michael@0: /** michael@0: * Get locale michael@0: * michael@0: * @return locale michael@0: * @stable ICU 4.2 michael@0: */ michael@0: const Locale& getLocale() const; michael@0: michael@0: /** michael@0: * Set plural rules. michael@0: * The plural rule is set when CurrencyPluralInfo michael@0: * instance is created. michael@0: * You can call this method to reset plural rules only if you want michael@0: * to modify the default plural rule of the locale. michael@0: * michael@0: * @param ruleDescription new plural rule description michael@0: * @param status output param set to success/failure code on exit michael@0: * @stable ICU 4.2 michael@0: */ michael@0: void setPluralRules(const UnicodeString& ruleDescription, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Set currency plural pattern. michael@0: * The currency plural pattern is set when CurrencyPluralInfo michael@0: * instance is created. michael@0: * You can call this method to reset currency plural pattern only if michael@0: * you want to modify the default currency plural pattern of the locale. michael@0: * michael@0: * @param pluralCount the plural count for which the currency pattern will michael@0: * be overridden. michael@0: * @param pattern the new currency plural pattern michael@0: * @param status output param set to success/failure code on exit michael@0: * @stable ICU 4.2 michael@0: */ michael@0: void setCurrencyPluralPattern(const UnicodeString& pluralCount, michael@0: const UnicodeString& pattern, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Set locale michael@0: * michael@0: * @param loc the new locale to set michael@0: * @param status output param set to success/failure code on exit michael@0: * @stable ICU 4.2 michael@0: */ michael@0: void setLocale(const Locale& loc, UErrorCode& status); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: * michael@0: * @stable ICU 4.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 4.2 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: private: michael@0: friend class DecimalFormat; michael@0: michael@0: void initialize(const Locale& loc, UErrorCode& status); michael@0: michael@0: void setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status); michael@0: michael@0: /* michael@0: * delete hash table michael@0: * michael@0: * @param hTable hash table to be deleted michael@0: */ michael@0: void deleteHash(Hashtable* hTable); michael@0: michael@0: michael@0: /* michael@0: * initialize hash table michael@0: * michael@0: * @param status output param set to success/failure code on exit michael@0: * @return hash table initialized michael@0: */ michael@0: Hashtable* initHash(UErrorCode& status); michael@0: michael@0: michael@0: michael@0: /** michael@0: * copy hash table michael@0: * michael@0: * @param source the source to copy from michael@0: * @param target the target to copy to michael@0: * @param status error code michael@0: */ michael@0: void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); michael@0: michael@0: //-------------------- private data member --------------------- michael@0: // map from plural count to currency plural pattern, for example michael@0: // a plural pattern defined in "CurrencyUnitPatterns" is michael@0: // "one{{0} {1}}", in which "one" is a plural count michael@0: // and "{0} {1}" is a currency plural pattern". michael@0: // The currency plural pattern saved in this mapping is the pattern michael@0: // defined in "CurrencyUnitPattern" by replacing michael@0: // {0} with the number format pattern, michael@0: // and {1} with 3 currency sign. michael@0: Hashtable* fPluralCountToCurrencyUnitPattern; michael@0: michael@0: /* michael@0: * The plural rule is used to format currency plural name, michael@0: * for example: "3.00 US Dollars". michael@0: * If there are 3 currency signs in the currency patttern, michael@0: * the 3 currency signs will be replaced by currency plural name. michael@0: */ michael@0: PluralRules* fPluralRules; michael@0: michael@0: // locale michael@0: Locale* fLocale; michael@0: }; michael@0: michael@0: michael@0: inline UBool michael@0: CurrencyPluralInfo::operator!=(const CurrencyPluralInfo& info) const { return !operator==(info); } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // _CURRPINFO michael@0: //eof