]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | /* |
2 | ********************************************************************** | |
57a6839d | 3 | * Copyright (c) 2004-2014, International Business Machines |
374ca955 A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
6 | * Author: Alan Liu | |
7 | * Created: April 26, 2004 | |
8 | * Since: ICU 3.0 | |
9 | ********************************************************************** | |
10 | */ | |
51004dcb | 11 | #include "utypeinfo.h" // for 'typeid' to work |
729e4ab9 | 12 | |
374ca955 A |
13 | #include "unicode/utypes.h" |
14 | ||
15 | #if !UCONFIG_NO_FORMATTING | |
16 | ||
17 | #include "unicode/measure.h" | |
18 | #include "unicode/measunit.h" | |
19 | ||
20 | U_NAMESPACE_BEGIN | |
21 | ||
57a6839d A |
22 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure) |
23 | ||
374ca955 A |
24 | Measure::Measure() {} |
25 | ||
26 | Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit, | |
27 | UErrorCode& ec) : | |
28 | number(_number), unit(adoptedUnit) { | |
29 | if (U_SUCCESS(ec) && | |
30 | (!number.isNumeric() || adoptedUnit == 0)) { | |
31 | ec = U_ILLEGAL_ARGUMENT_ERROR; | |
32 | } | |
33 | } | |
34 | ||
35 | Measure::Measure(const Measure& other) : | |
36 | UObject(other), unit(0) { | |
37 | *this = other; | |
38 | } | |
39 | ||
40 | Measure& Measure::operator=(const Measure& other) { | |
41 | if (this != &other) { | |
42 | delete unit; | |
43 | number = other.number; | |
44 | unit = (MeasureUnit*) other.unit->clone(); | |
45 | } | |
46 | return *this; | |
47 | } | |
48 | ||
57a6839d A |
49 | UObject *Measure::clone() const { |
50 | return new Measure(*this); | |
51 | } | |
52 | ||
374ca955 A |
53 | Measure::~Measure() { |
54 | delete unit; | |
55 | } | |
56 | ||
57 | UBool Measure::operator==(const UObject& other) const { | |
57a6839d A |
58 | if (this == &other) { // Same object, equal |
59 | return TRUE; | |
60 | } | |
61 | if (typeid(*this) != typeid(other)) { // Different types, not equal | |
62 | return FALSE; | |
63 | } | |
64 | const Measure &m = static_cast<const Measure&>(other); | |
65 | return number == m.number && | |
66 | ((unit == NULL) == (m.unit == NULL)) && | |
67 | (unit == NULL || *unit == *m.unit); | |
374ca955 A |
68 | } |
69 | ||
374ca955 A |
70 | U_NAMESPACE_END |
71 | ||
72 | #endif // !UCONFIG_NO_FORMATTING |