currpinf.h 7.0 KB

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