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 20U_NAMESPACE_BEGIN 21 22CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) : 23 fmt(NULL) 24{ 25 fmt = NumberFormat::createCurrencyInstance(locale, ec); 26} 27 28CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) : 29 MeasureFormat(other), fmt(NULL) 30{ 31 fmt = (NumberFormat*) other.fmt->clone(); 32} 33 34CurrencyFormat::~CurrencyFormat() { 35 delete fmt; 36} 37 38UBool 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 49Format* CurrencyFormat::clone() const { 50 return new CurrencyFormat(*this); 51} 52 53UnicodeString& 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 61void CurrencyFormat::parseObject(const UnicodeString& source, 62 Formattable& result, 63 ParsePosition& pos) const 64{ 65 fmt->parseCurrency(source, result, pos); 66} 67 68UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat) 69 70U_NAMESPACE_END 71 72#endif /* #if !UCONFIG_NO_FORMATTING */ 73