curramt.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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) 2004-2006, 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 __CURRENCYAMOUNT_H__
  14. #define __CURRENCYAMOUNT_H__
  15. #include "unicode/utypes.h"
  16. #if !UCONFIG_NO_FORMATTING
  17. #include "unicode/measure.h"
  18. #include "unicode/currunit.h"
  19. /**
  20. * \file
  21. * \brief C++ API: Currency Amount Object.
  22. */
  23. U_NAMESPACE_BEGIN
  24. /**
  25. *
  26. * A currency together with a numeric amount, such as 200 USD.
  27. *
  28. * @author Alan Liu
  29. * @stable ICU 3.0
  30. */
  31. class U_I18N_API CurrencyAmount: public Measure {
  32. public:
  33. /**
  34. * Construct an object with the given numeric amount and the given
  35. * ISO currency code.
  36. * @param amount a numeric object; amount.isNumeric() must be TRUE
  37. * @param isoCode the 3-letter ISO 4217 currency code; must not be
  38. * NULL and must have length 3
  39. * @param ec input-output error code. If the amount or the isoCode
  40. * is invalid, then this will be set to a failing value.
  41. * @stable ICU 3.0
  42. */
  43. CurrencyAmount(const Formattable& amount, const UChar* isoCode,
  44. UErrorCode &ec);
  45. /**
  46. * Construct an object with the given numeric amount and the given
  47. * ISO currency code.
  48. * @param amount the amount of the given currency
  49. * @param isoCode the 3-letter ISO 4217 currency code; must not be
  50. * NULL and must have length 3
  51. * @param ec input-output error code. If the isoCode is invalid,
  52. * then this will be set to a failing value.
  53. * @stable ICU 3.0
  54. */
  55. CurrencyAmount(double amount, const UChar* isoCode,
  56. UErrorCode &ec);
  57. /**
  58. * Copy constructor
  59. * @stable ICU 3.0
  60. */
  61. CurrencyAmount(const CurrencyAmount& other);
  62. /**
  63. * Assignment operator
  64. * @stable ICU 3.0
  65. */
  66. CurrencyAmount& operator=(const CurrencyAmount& other);
  67. /**
  68. * Return a polymorphic clone of this object. The result will
  69. * have the same class as returned by getDynamicClassID().
  70. * @stable ICU 3.0
  71. */
  72. virtual UObject* clone() const;
  73. /**
  74. * Destructor
  75. * @stable ICU 3.0
  76. */
  77. virtual ~CurrencyAmount();
  78. /**
  79. * Returns a unique class ID for this object POLYMORPHICALLY.
  80. * This method implements a simple form of RTTI used by ICU.
  81. * @return The class ID for this object. All objects of a given
  82. * class have the same class ID. Objects of other classes have
  83. * different class IDs.
  84. * @stable ICU 3.0
  85. */
  86. virtual UClassID getDynamicClassID() const;
  87. /**
  88. * Returns the class ID for this class. This is used to compare to
  89. * the return value of getDynamicClassID().
  90. * @return The class ID for all objects of this class.
  91. * @stable ICU 3.0
  92. */
  93. static UClassID U_EXPORT2 getStaticClassID();
  94. /**
  95. * Return the currency unit object of this object.
  96. * @stable ICU 3.0
  97. */
  98. inline const CurrencyUnit& getCurrency() const;
  99. /**
  100. * Return the ISO currency code of this object.
  101. * @stable ICU 3.0
  102. */
  103. inline const UChar* getISOCurrency() const;
  104. };
  105. inline const CurrencyUnit& CurrencyAmount::getCurrency() const {
  106. return (const CurrencyUnit&) getUnit();
  107. }
  108. inline const UChar* CurrencyAmount::getISOCurrency() const {
  109. return getCurrency().getISOCurrency();
  110. }
  111. U_NAMESPACE_END
  112. #endif // !UCONFIG_NO_FORMATTING
  113. #endif // __CURRENCYAMOUNT_H__