michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (c) 2004-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Author: Alan Liu michael@0: * Created: April 26, 2004 michael@0: * Since: ICU 3.0 michael@0: ********************************************************************** michael@0: */ michael@0: #include "utypeinfo.h" // for 'typeid' to work michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/measure.h" michael@0: #include "unicode/measunit.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: Measure::Measure() {} michael@0: michael@0: Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit, michael@0: UErrorCode& ec) : michael@0: number(_number), unit(adoptedUnit) { michael@0: if (U_SUCCESS(ec) && michael@0: (!number.isNumeric() || adoptedUnit == 0)) { michael@0: ec = U_ILLEGAL_ARGUMENT_ERROR; michael@0: } michael@0: } michael@0: michael@0: Measure::Measure(const Measure& other) : michael@0: UObject(other), unit(0) { michael@0: *this = other; michael@0: } michael@0: michael@0: Measure& Measure::operator=(const Measure& other) { michael@0: if (this != &other) { michael@0: delete unit; michael@0: number = other.number; michael@0: unit = (MeasureUnit*) other.unit->clone(); michael@0: } michael@0: return *this; michael@0: } michael@0: michael@0: Measure::~Measure() { michael@0: delete unit; michael@0: } michael@0: michael@0: UBool Measure::operator==(const UObject& other) const { michael@0: const Measure* m = (const Measure*) &other; michael@0: return typeid(*this) == typeid(other) && michael@0: number == m->getNumber() && michael@0: (unit != NULL && *unit == m->getUnit()); michael@0: } michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // MeasureUnit implementation michael@0: michael@0: MeasureUnit:: MeasureUnit() {} michael@0: michael@0: MeasureUnit::~MeasureUnit() {} michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif // !UCONFIG_NO_FORMATTING