X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..0f5d89e82340278ed3d7d50029f37cab2c41a57e:/icuSources/i18n/measure.cpp diff --git a/icuSources/i18n/measure.cpp b/icuSources/i18n/measure.cpp index 361c1fac..d9084f87 100644 --- a/icuSources/i18n/measure.cpp +++ b/icuSources/i18n/measure.cpp @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** -* Copyright (c) 2004-2008, International Business Machines +* Copyright (c) 2004-2014, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Alan Liu @@ -8,6 +10,8 @@ * Since: ICU 3.0 ********************************************************************** */ +#include "utypeinfo.h" // for 'typeid' to work + #include "unicode/utypes.h" #if !UCONFIG_NO_FORMATTING @@ -17,6 +21,8 @@ U_NAMESPACE_BEGIN +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure) + Measure::Measure() {} Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit, @@ -42,24 +48,27 @@ Measure& Measure::operator=(const Measure& other) { return *this; } +UObject *Measure::clone() const { + return new Measure(*this); +} + Measure::~Measure() { delete unit; } UBool Measure::operator==(const UObject& other) const { - const Measure* m = (const Measure*) &other; - return getDynamicClassID() == other.getDynamicClassID() && - number == m->getNumber() && - (unit != NULL && *unit == m->getUnit()); + if (this == &other) { // Same object, equal + return TRUE; + } + if (typeid(*this) != typeid(other)) { // Different types, not equal + return FALSE; + } + const Measure &m = static_cast(other); + return number == m.number && + ((unit == NULL) == (m.unit == NULL)) && + (unit == NULL || *unit == *m.unit); } -//---------------------------------------------------------------------- -// MeasureUnit implementation - -MeasureUnit:: MeasureUnit() {} - -MeasureUnit::~MeasureUnit() {} - U_NAMESPACE_END #endif // !UCONFIG_NO_FORMATTING