Home | History | Annotate | Download | only in i18n
      1 /*
      2 **********************************************************************
      3 * Copyright (c) 2004-2010, International Business Machines
      4 * Corporation and others.  All Rights Reserved.
      5 **********************************************************************
      6 * Author: Alan Liu
      7 * Created: April 20, 2004
      8 * Since: ICU 3.0
      9 **********************************************************************
     10 */
     11 #include <typeinfo>  // for 'typeid' to work
     12 
     13 #include "unicode/utypes.h"
     14 
     15 #if !UCONFIG_NO_FORMATTING
     16 
     17 #include "currfmt.h"
     18 #include "unicode/numfmt.h"
     19 
     20 U_NAMESPACE_BEGIN
     21 
     22 CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
     23     fmt(NULL)
     24 {
     25     fmt = NumberFormat::createCurrencyInstance(locale, ec);
     26 }
     27 
     28 CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
     29     MeasureFormat(other), fmt(NULL)
     30 {
     31     fmt = (NumberFormat*) other.fmt->clone();
     32 }
     33 
     34 CurrencyFormat::~CurrencyFormat() {
     35     delete fmt;
     36 }
     37 
     38 UBool CurrencyFormat::operator==(const Format& other) const {
     39     if (this == &other) {
     40         return TRUE;
     41     }
     42     if (typeid(*this) != typeid(other)) {
     43         return FALSE;
     44     }
     45     const CurrencyFormat* c = (const CurrencyFormat*) &other;
     46     return *fmt == *c->fmt;
     47 }
     48 
     49 Format* CurrencyFormat::clone() const {
     50     return new CurrencyFormat(*this);
     51 }
     52 
     53 UnicodeString& CurrencyFormat::format(const Formattable& obj,
     54                                       UnicodeString& appendTo,
     55                                       FieldPosition& pos,
     56                                       UErrorCode& ec) const
     57 {
     58     return fmt->format(obj, appendTo, pos, ec);
     59 }
     60 
     61 void CurrencyFormat::parseObject(const UnicodeString& source,
     62                                  Formattable& result,
     63                                  ParsePosition& pos) const
     64 {
     65     fmt->parseCurrency(source, result, pos);
     66 }
     67 
     68 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)
     69 
     70 U_NAMESPACE_END
     71 
     72 #endif /* #if !UCONFIG_NO_FORMATTING */
     73