currpinf.h 7.3 KB

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