1/*
2**********************************************************************
3* Copyright (c) 2004-2008, 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 "unicode/utypes.h"
12
13#if !UCONFIG_NO_FORMATTING
14
15#include "currfmt.h"
16#include "unicode/numfmt.h"
17
18U_NAMESPACE_BEGIN
19
20CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
21    fmt(NULL)
22{
23    fmt = NumberFormat::createCurrencyInstance(locale, ec);
24}
25
26CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
27    MeasureFormat(other), fmt(NULL)
28{
29    fmt = (NumberFormat*) other.fmt->clone();
30}
31
32CurrencyFormat::~CurrencyFormat() {
33    delete fmt;
34}
35
36UBool CurrencyFormat::operator==(const Format& other) const {
37    if (this == &other) {
38        return TRUE;
39    }
40    if (other.getDynamicClassID() != CurrencyFormat::getStaticClassID()) {
41        return FALSE;
42    }
43    const CurrencyFormat* c = (const CurrencyFormat*) &other;
44    return *fmt == *c->fmt;
45}
46
47Format* CurrencyFormat::clone() const {
48    return new CurrencyFormat(*this);
49}
50
51UnicodeString& CurrencyFormat::format(const Formattable& obj,
52                                      UnicodeString& appendTo,
53                                      FieldPosition& pos,
54                                      UErrorCode& ec) const
55{
56    return fmt->format(obj, appendTo, pos, ec);
57}
58
59void CurrencyFormat::parseObject(const UnicodeString& source,
60                                 Formattable& result,
61                                 ParsePosition& pos) const
62{
63    fmt->parseCurrency(source, result, pos);
64}
65
66UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)
67
68U_NAMESPACE_END
69
70#endif /* #if !UCONFIG_NO_FORMATTING */
71