currpinf.h 7.1 KB

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