2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2004-04-27 21:47:09 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 2004-2014, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2004-04-27 21:47:09 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Author: Alan Liu
|
|
|
|
* Created: April 26, 2004
|
|
|
|
* Since: ICU 3.0
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
2012-06-28 23:28:00 +00:00
|
|
|
#include "utypeinfo.h" // for 'typeid' to work
|
2010-05-19 17:29:33 +00:00
|
|
|
|
2004-04-27 21:47:09 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include "unicode/measure.h"
|
|
|
|
#include "unicode/measunit.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2014-03-11 17:40:23 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
|
|
|
|
|
2004-04-28 00:12:33 +00:00
|
|
|
Measure::Measure() {}
|
|
|
|
|
2004-04-27 21:47:09 +00:00
|
|
|
Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
|
|
|
|
UErrorCode& ec) :
|
|
|
|
number(_number), unit(adoptedUnit) {
|
|
|
|
if (U_SUCCESS(ec) &&
|
|
|
|
(!number.isNumeric() || adoptedUnit == 0)) {
|
|
|
|
ec = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Measure::Measure(const Measure& other) :
|
2004-04-28 18:12:14 +00:00
|
|
|
UObject(other), unit(0) {
|
2004-04-27 21:47:09 +00:00
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
Measure& Measure::operator=(const Measure& other) {
|
|
|
|
if (this != &other) {
|
|
|
|
delete unit;
|
|
|
|
number = other.number;
|
|
|
|
unit = (MeasureUnit*) other.unit->clone();
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-02-04 00:29:17 +00:00
|
|
|
UObject *Measure::clone() const {
|
|
|
|
return new Measure(*this);
|
|
|
|
}
|
|
|
|
|
2004-04-27 21:47:09 +00:00
|
|
|
Measure::~Measure() {
|
|
|
|
delete unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool Measure::operator==(const UObject& other) const {
|
2014-03-11 17:40:23 +00:00
|
|
|
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);
|
2004-04-27 21:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif // !UCONFIG_NO_FORMATTING
|