currunit.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (c) 2004-2014, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. * Author: Alan Liu
  9. * Created: April 26, 2004
  10. * Since: ICU 3.0
  11. **********************************************************************
  12. */
  13. #ifndef __CURRENCYUNIT_H__
  14. #define __CURRENCYUNIT_H__
  15. #include "unicode/utypes.h"
  16. #if U_SHOW_CPLUSPLUS_API
  17. #if !UCONFIG_NO_FORMATTING
  18. #include "unicode/measunit.h"
  19. /**
  20. * \file
  21. * \brief C++ API: Currency Unit Information.
  22. */
  23. U_NAMESPACE_BEGIN
  24. /**
  25. * A unit of currency, such as USD (U.S. dollars) or JPY (Japanese
  26. * yen). This class is a thin wrapper over a char16_t string that
  27. * subclasses MeasureUnit, for use with Measure and MeasureFormat.
  28. *
  29. * @author Alan Liu
  30. * @stable ICU 3.0
  31. */
  32. class U_I18N_API CurrencyUnit: public MeasureUnit {
  33. public:
  34. /**
  35. * Default constructor. Initializes currency code to "XXX" (no currency).
  36. * @stable ICU 60
  37. */
  38. CurrencyUnit();
  39. /**
  40. * Construct an object with the given ISO currency code.
  41. *
  42. * @param isoCode the 3-letter ISO 4217 currency code; must have
  43. * length 3 and need not be NUL-terminated. If nullptr, the currency
  44. * is initialized to the unknown currency XXX.
  45. * @param ec input-output error code. If the isoCode is invalid,
  46. * then this will be set to a failing value.
  47. * @stable ICU 3.0
  48. */
  49. CurrencyUnit(ConstChar16Ptr isoCode, UErrorCode &ec);
  50. /**
  51. * Construct an object with the given ISO currency code.
  52. *
  53. * @param isoCode the 3-letter ISO 4217 currency code; must have
  54. * length 3. If invalid, the currency is initialized to XXX.
  55. * @param ec input-output error code. If the isoCode is invalid,
  56. * then this will be set to a failing value.
  57. * @stable ICU 64
  58. */
  59. CurrencyUnit(StringPiece isoCode, UErrorCode &ec);
  60. /**
  61. * Copy constructor
  62. * @stable ICU 3.0
  63. */
  64. CurrencyUnit(const CurrencyUnit& other);
  65. /**
  66. * Copy constructor from MeasureUnit. This constructor allows you to
  67. * restore a CurrencyUnit that was sliced to MeasureUnit.
  68. *
  69. * @param measureUnit The MeasureUnit to copy from.
  70. * @param ec Set to a failing value if the MeasureUnit is not a currency.
  71. * @stable ICU 60
  72. */
  73. CurrencyUnit(const MeasureUnit& measureUnit, UErrorCode &ec);
  74. /**
  75. * Assignment operator
  76. * @stable ICU 3.0
  77. */
  78. CurrencyUnit& operator=(const CurrencyUnit& other);
  79. /**
  80. * Return a polymorphic clone of this object. The result will
  81. * have the same class as returned by getDynamicClassID().
  82. * @stable ICU 3.0
  83. */
  84. virtual CurrencyUnit* clone() const override;
  85. /**
  86. * Destructor
  87. * @stable ICU 3.0
  88. */
  89. virtual ~CurrencyUnit();
  90. /**
  91. * Returns a unique class ID for this object POLYMORPHICALLY.
  92. * This method implements a simple form of RTTI used by ICU.
  93. * @return The class ID for this object. All objects of a given
  94. * class have the same class ID. Objects of other classes have
  95. * different class IDs.
  96. * @stable ICU 3.0
  97. */
  98. virtual UClassID getDynamicClassID() const override;
  99. /**
  100. * Returns the class ID for this class. This is used to compare to
  101. * the return value of getDynamicClassID().
  102. * @return The class ID for all objects of this class.
  103. * @stable ICU 3.0
  104. */
  105. static UClassID U_EXPORT2 getStaticClassID();
  106. /**
  107. * Return the ISO currency code of this object.
  108. * @stable ICU 3.0
  109. */
  110. inline const char16_t* getISOCurrency() const;
  111. private:
  112. /**
  113. * The ISO 4217 code of this object.
  114. */
  115. char16_t isoCode[4];
  116. };
  117. inline const char16_t* CurrencyUnit::getISOCurrency() const {
  118. return isoCode;
  119. }
  120. U_NAMESPACE_END
  121. #endif // !UCONFIG_NO_FORMATTING
  122. #endif /* U_SHOW_CPLUSPLUS_API */
  123. #endif // __CURRENCYUNIT_H__