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