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