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