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