Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * Copyright (C) 2009-2011, International Business Machines Corporation and * |
michael@0 | 4 | * others. All Rights Reserved. * |
michael@0 | 5 | ******************************************************************************* |
michael@0 | 6 | */ |
michael@0 | 7 | #ifndef CURRPINF_H |
michael@0 | 8 | #define CURRPINF_H |
michael@0 | 9 | |
michael@0 | 10 | #include "unicode/utypes.h" |
michael@0 | 11 | |
michael@0 | 12 | /** |
michael@0 | 13 | * \file |
michael@0 | 14 | * \brief C++ API: Currency Plural Information used by Decimal Format |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 18 | |
michael@0 | 19 | #include "unicode/unistr.h" |
michael@0 | 20 | |
michael@0 | 21 | U_NAMESPACE_BEGIN |
michael@0 | 22 | |
michael@0 | 23 | class Locale; |
michael@0 | 24 | class PluralRules; |
michael@0 | 25 | class Hashtable; |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * This class represents the information needed by |
michael@0 | 29 | * DecimalFormat to format currency plural, |
michael@0 | 30 | * such as "3.00 US dollars" or "1.00 US dollar". |
michael@0 | 31 | * DecimalFormat creates for itself an instance of |
michael@0 | 32 | * CurrencyPluralInfo from its locale data. |
michael@0 | 33 | * If you need to change any of these symbols, you can get the |
michael@0 | 34 | * CurrencyPluralInfo object from your |
michael@0 | 35 | * DecimalFormat and modify it. |
michael@0 | 36 | * |
michael@0 | 37 | * Following are the information needed for currency plural format and parse: |
michael@0 | 38 | * locale information, |
michael@0 | 39 | * plural rule of the locale, |
michael@0 | 40 | * currency plural pattern of the locale. |
michael@0 | 41 | * |
michael@0 | 42 | * @stable ICU 4.2 |
michael@0 | 43 | */ |
michael@0 | 44 | class U_I18N_API CurrencyPluralInfo : public UObject { |
michael@0 | 45 | public: |
michael@0 | 46 | |
michael@0 | 47 | /** |
michael@0 | 48 | * Create a CurrencyPluralInfo object for the default locale. |
michael@0 | 49 | * @param status output param set to success/failure code on exit |
michael@0 | 50 | * @stable ICU 4.2 |
michael@0 | 51 | */ |
michael@0 | 52 | CurrencyPluralInfo(UErrorCode& status); |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * Create a CurrencyPluralInfo object for the given locale. |
michael@0 | 56 | * @param locale the locale |
michael@0 | 57 | * @param status output param set to success/failure code on exit |
michael@0 | 58 | * @stable ICU 4.2 |
michael@0 | 59 | */ |
michael@0 | 60 | CurrencyPluralInfo(const Locale& locale, UErrorCode& status); |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * Copy constructor |
michael@0 | 64 | * |
michael@0 | 65 | * @stable ICU 4.2 |
michael@0 | 66 | */ |
michael@0 | 67 | CurrencyPluralInfo(const CurrencyPluralInfo& info); |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Assignment operator |
michael@0 | 72 | * |
michael@0 | 73 | * @stable ICU 4.2 |
michael@0 | 74 | */ |
michael@0 | 75 | CurrencyPluralInfo& operator=(const CurrencyPluralInfo& info); |
michael@0 | 76 | |
michael@0 | 77 | |
michael@0 | 78 | /** |
michael@0 | 79 | * Destructor |
michael@0 | 80 | * |
michael@0 | 81 | * @stable ICU 4.2 |
michael@0 | 82 | */ |
michael@0 | 83 | virtual ~CurrencyPluralInfo(); |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Equal operator. |
michael@0 | 88 | * |
michael@0 | 89 | * @stable ICU 4.2 |
michael@0 | 90 | */ |
michael@0 | 91 | UBool operator==(const CurrencyPluralInfo& info) const; |
michael@0 | 92 | |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * Not equal operator |
michael@0 | 96 | * |
michael@0 | 97 | * @stable ICU 4.2 |
michael@0 | 98 | */ |
michael@0 | 99 | UBool operator!=(const CurrencyPluralInfo& info) const; |
michael@0 | 100 | |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * Clone |
michael@0 | 104 | * |
michael@0 | 105 | * @stable ICU 4.2 |
michael@0 | 106 | */ |
michael@0 | 107 | CurrencyPluralInfo* clone() const; |
michael@0 | 108 | |
michael@0 | 109 | |
michael@0 | 110 | /** |
michael@0 | 111 | * Gets plural rules of this locale, used for currency plural format |
michael@0 | 112 | * |
michael@0 | 113 | * @return plural rule |
michael@0 | 114 | * @stable ICU 4.2 |
michael@0 | 115 | */ |
michael@0 | 116 | const PluralRules* getPluralRules() const; |
michael@0 | 117 | |
michael@0 | 118 | /** |
michael@0 | 119 | * Given a plural count, gets currency plural pattern of this locale, |
michael@0 | 120 | * used for currency plural format |
michael@0 | 121 | * |
michael@0 | 122 | * @param pluralCount currency plural count |
michael@0 | 123 | * @param result output param to receive the pattern |
michael@0 | 124 | * @return a currency plural pattern based on plural count |
michael@0 | 125 | * @stable ICU 4.2 |
michael@0 | 126 | */ |
michael@0 | 127 | UnicodeString& getCurrencyPluralPattern(const UnicodeString& pluralCount, |
michael@0 | 128 | UnicodeString& result) const; |
michael@0 | 129 | |
michael@0 | 130 | /** |
michael@0 | 131 | * Get locale |
michael@0 | 132 | * |
michael@0 | 133 | * @return locale |
michael@0 | 134 | * @stable ICU 4.2 |
michael@0 | 135 | */ |
michael@0 | 136 | const Locale& getLocale() const; |
michael@0 | 137 | |
michael@0 | 138 | /** |
michael@0 | 139 | * Set plural rules. |
michael@0 | 140 | * The plural rule is set when CurrencyPluralInfo |
michael@0 | 141 | * instance is created. |
michael@0 | 142 | * You can call this method to reset plural rules only if you want |
michael@0 | 143 | * to modify the default plural rule of the locale. |
michael@0 | 144 | * |
michael@0 | 145 | * @param ruleDescription new plural rule description |
michael@0 | 146 | * @param status output param set to success/failure code on exit |
michael@0 | 147 | * @stable ICU 4.2 |
michael@0 | 148 | */ |
michael@0 | 149 | void setPluralRules(const UnicodeString& ruleDescription, |
michael@0 | 150 | UErrorCode& status); |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * Set currency plural pattern. |
michael@0 | 154 | * The currency plural pattern is set when CurrencyPluralInfo |
michael@0 | 155 | * instance is created. |
michael@0 | 156 | * You can call this method to reset currency plural pattern only if |
michael@0 | 157 | * you want to modify the default currency plural pattern of the locale. |
michael@0 | 158 | * |
michael@0 | 159 | * @param pluralCount the plural count for which the currency pattern will |
michael@0 | 160 | * be overridden. |
michael@0 | 161 | * @param pattern the new currency plural pattern |
michael@0 | 162 | * @param status output param set to success/failure code on exit |
michael@0 | 163 | * @stable ICU 4.2 |
michael@0 | 164 | */ |
michael@0 | 165 | void setCurrencyPluralPattern(const UnicodeString& pluralCount, |
michael@0 | 166 | const UnicodeString& pattern, |
michael@0 | 167 | UErrorCode& status); |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * Set locale |
michael@0 | 171 | * |
michael@0 | 172 | * @param loc the new locale to set |
michael@0 | 173 | * @param status output param set to success/failure code on exit |
michael@0 | 174 | * @stable ICU 4.2 |
michael@0 | 175 | */ |
michael@0 | 176 | void setLocale(const Locale& loc, UErrorCode& status); |
michael@0 | 177 | |
michael@0 | 178 | /** |
michael@0 | 179 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 180 | * |
michael@0 | 181 | * @stable ICU 4.2 |
michael@0 | 182 | */ |
michael@0 | 183 | virtual UClassID getDynamicClassID() const; |
michael@0 | 184 | |
michael@0 | 185 | /** |
michael@0 | 186 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 187 | * |
michael@0 | 188 | * @stable ICU 4.2 |
michael@0 | 189 | */ |
michael@0 | 190 | static UClassID U_EXPORT2 getStaticClassID(); |
michael@0 | 191 | |
michael@0 | 192 | private: |
michael@0 | 193 | friend class DecimalFormat; |
michael@0 | 194 | |
michael@0 | 195 | void initialize(const Locale& loc, UErrorCode& status); |
michael@0 | 196 | |
michael@0 | 197 | void setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status); |
michael@0 | 198 | |
michael@0 | 199 | /* |
michael@0 | 200 | * delete hash table |
michael@0 | 201 | * |
michael@0 | 202 | * @param hTable hash table to be deleted |
michael@0 | 203 | */ |
michael@0 | 204 | void deleteHash(Hashtable* hTable); |
michael@0 | 205 | |
michael@0 | 206 | |
michael@0 | 207 | /* |
michael@0 | 208 | * initialize hash table |
michael@0 | 209 | * |
michael@0 | 210 | * @param status output param set to success/failure code on exit |
michael@0 | 211 | * @return hash table initialized |
michael@0 | 212 | */ |
michael@0 | 213 | Hashtable* initHash(UErrorCode& status); |
michael@0 | 214 | |
michael@0 | 215 | |
michael@0 | 216 | |
michael@0 | 217 | /** |
michael@0 | 218 | * copy hash table |
michael@0 | 219 | * |
michael@0 | 220 | * @param source the source to copy from |
michael@0 | 221 | * @param target the target to copy to |
michael@0 | 222 | * @param status error code |
michael@0 | 223 | */ |
michael@0 | 224 | void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); |
michael@0 | 225 | |
michael@0 | 226 | //-------------------- private data member --------------------- |
michael@0 | 227 | // map from plural count to currency plural pattern, for example |
michael@0 | 228 | // a plural pattern defined in "CurrencyUnitPatterns" is |
michael@0 | 229 | // "one{{0} {1}}", in which "one" is a plural count |
michael@0 | 230 | // and "{0} {1}" is a currency plural pattern". |
michael@0 | 231 | // The currency plural pattern saved in this mapping is the pattern |
michael@0 | 232 | // defined in "CurrencyUnitPattern" by replacing |
michael@0 | 233 | // {0} with the number format pattern, |
michael@0 | 234 | // and {1} with 3 currency sign. |
michael@0 | 235 | Hashtable* fPluralCountToCurrencyUnitPattern; |
michael@0 | 236 | |
michael@0 | 237 | /* |
michael@0 | 238 | * The plural rule is used to format currency plural name, |
michael@0 | 239 | * for example: "3.00 US Dollars". |
michael@0 | 240 | * If there are 3 currency signs in the currency patttern, |
michael@0 | 241 | * the 3 currency signs will be replaced by currency plural name. |
michael@0 | 242 | */ |
michael@0 | 243 | PluralRules* fPluralRules; |
michael@0 | 244 | |
michael@0 | 245 | // locale |
michael@0 | 246 | Locale* fLocale; |
michael@0 | 247 | }; |
michael@0 | 248 | |
michael@0 | 249 | |
michael@0 | 250 | inline UBool |
michael@0 | 251 | CurrencyPluralInfo::operator!=(const CurrencyPluralInfo& info) const { return !operator==(info); } |
michael@0 | 252 | |
michael@0 | 253 | U_NAMESPACE_END |
michael@0 | 254 | |
michael@0 | 255 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 256 | |
michael@0 | 257 | #endif // _CURRPINFO |
michael@0 | 258 | //eof |