1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (c) 2004-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
9 * Created: April 26, 2004
11 **********************************************************************
13 #include "utypeinfo.h" // for 'typeid' to work
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/measure.h"
20 #include "unicode/measunit.h"
24 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
28 Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
30 number(_number), unit(adoptedUnit) {
32 (!number.isNumeric() || adoptedUnit == 0)) {
33 ec = U_ILLEGAL_ARGUMENT_ERROR;
37 Measure::Measure(const Measure& other) :
38 UObject(other), unit(0) {
42 Measure& Measure::operator=(const Measure& other) {
45 number = other.number;
46 unit = (MeasureUnit*) other.unit->clone();
51 UObject *Measure::clone() const {
52 return new Measure(*this);
59 UBool Measure::operator==(const UObject& other) const {
60 if (this == &other) { // Same object, equal
63 if (typeid(*this) != typeid(other)) { // Different types, not equal
66 const Measure &m = static_cast<const Measure&>(other);
67 return number == m.number &&
68 ((unit == NULL) == (m.unit == NULL)) &&
69 (unit == NULL || *unit == *m.unit);
74 #endif // !UCONFIG_NO_FORMATTING