|
1 /* |
|
2 ********************************************************************** |
|
3 * Copyright (c) 2004-2012, International Business Machines |
|
4 * Corporation and others. All Rights Reserved. |
|
5 ********************************************************************** |
|
6 * Author: Alan Liu |
|
7 * Created: April 26, 2004 |
|
8 * Since: ICU 3.0 |
|
9 ********************************************************************** |
|
10 */ |
|
11 #include "utypeinfo.h" // for 'typeid' to work |
|
12 |
|
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 |
|
22 Measure::Measure() {} |
|
23 |
|
24 Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit, |
|
25 UErrorCode& ec) : |
|
26 number(_number), unit(adoptedUnit) { |
|
27 if (U_SUCCESS(ec) && |
|
28 (!number.isNumeric() || adoptedUnit == 0)) { |
|
29 ec = U_ILLEGAL_ARGUMENT_ERROR; |
|
30 } |
|
31 } |
|
32 |
|
33 Measure::Measure(const Measure& other) : |
|
34 UObject(other), unit(0) { |
|
35 *this = other; |
|
36 } |
|
37 |
|
38 Measure& Measure::operator=(const Measure& other) { |
|
39 if (this != &other) { |
|
40 delete unit; |
|
41 number = other.number; |
|
42 unit = (MeasureUnit*) other.unit->clone(); |
|
43 } |
|
44 return *this; |
|
45 } |
|
46 |
|
47 Measure::~Measure() { |
|
48 delete unit; |
|
49 } |
|
50 |
|
51 UBool Measure::operator==(const UObject& other) const { |
|
52 const Measure* m = (const Measure*) &other; |
|
53 return typeid(*this) == typeid(other) && |
|
54 number == m->getNumber() && |
|
55 (unit != NULL && *unit == m->getUnit()); |
|
56 } |
|
57 |
|
58 //---------------------------------------------------------------------- |
|
59 // MeasureUnit implementation |
|
60 |
|
61 MeasureUnit:: MeasureUnit() {} |
|
62 |
|
63 MeasureUnit::~MeasureUnit() {} |
|
64 |
|
65 U_NAMESPACE_END |
|
66 |
|
67 #endif // !UCONFIG_NO_FORMATTING |