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