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