michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (c) 2004-2012 International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Author: Alan Liu michael@0: * Created: April 20, 2004 michael@0: * Since: ICU 3.0 michael@0: ********************************************************************** michael@0: */ michael@0: #include "utypeinfo.h" // for 'typeid' to work michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "currfmt.h" michael@0: #include "unicode/numfmt.h" michael@0: #include "unicode/curramt.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) : michael@0: fmt(NULL) michael@0: { michael@0: fmt = NumberFormat::createCurrencyInstance(locale, ec); michael@0: } michael@0: michael@0: CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) : michael@0: MeasureFormat(other), fmt(NULL) michael@0: { michael@0: fmt = (NumberFormat*) other.fmt->clone(); michael@0: } michael@0: michael@0: CurrencyFormat::~CurrencyFormat() { michael@0: delete fmt; michael@0: } michael@0: michael@0: UBool CurrencyFormat::operator==(const Format& other) const { michael@0: if (this == &other) { michael@0: return TRUE; michael@0: } michael@0: if (typeid(*this) != typeid(other)) { michael@0: return FALSE; michael@0: } michael@0: const CurrencyFormat* c = (const CurrencyFormat*) &other; michael@0: return *fmt == *c->fmt; michael@0: } michael@0: michael@0: Format* CurrencyFormat::clone() const { michael@0: return new CurrencyFormat(*this); michael@0: } michael@0: michael@0: UnicodeString& CurrencyFormat::format(const Formattable& obj, michael@0: UnicodeString& appendTo, michael@0: FieldPosition& pos, michael@0: UErrorCode& ec) const michael@0: { michael@0: return fmt->format(obj, appendTo, pos, ec); michael@0: } michael@0: michael@0: void CurrencyFormat::parseObject(const UnicodeString& source, michael@0: Formattable& result, michael@0: ParsePosition& pos) const michael@0: { michael@0: CurrencyAmount* currAmt = fmt->parseCurrency(source, pos); michael@0: if (currAmt != NULL) { michael@0: result.adoptObject(currAmt); michael@0: } michael@0: } michael@0: michael@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat) michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */