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