+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* Copyright (c) 2004, International Business Machines
+* Copyright (c) 2004-2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
* Since: ICU 3.0
**********************************************************************
*/
+#include "utypeinfo.h" // for 'typeid' to work
+
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
U_NAMESPACE_BEGIN
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
+
Measure::Measure() {}
Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
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 == 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<const Measure&>(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