Home | History | Annotate | Download | only in i18n
      1 /*
      2 **********************************************************************
      3 * Copyright (c) 2004-2008, International Business Machines
      4 * Corporation and others.  All Rights Reserved.
      5 **********************************************************************
      6 * Author: Alan Liu
      7 * Created: April 26, 2004
      8 * Since: ICU 3.0
      9 **********************************************************************
     10 */
     11 #include "unicode/utypes.h"
     12 
     13 #if !UCONFIG_NO_FORMATTING
     14 
     15 #include "unicode/measure.h"
     16 #include "unicode/measunit.h"
     17 
     18 U_NAMESPACE_BEGIN
     19 
     20 Measure::Measure() {}
     21 
     22 Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
     23                  UErrorCode& ec) :
     24     number(_number), unit(adoptedUnit) {
     25     if (U_SUCCESS(ec) &&
     26         (!number.isNumeric() || adoptedUnit == 0)) {
     27         ec = U_ILLEGAL_ARGUMENT_ERROR;
     28     }
     29 }
     30 
     31 Measure::Measure(const Measure& other) :
     32     UObject(other), unit(0) {
     33     *this = other;
     34 }
     35 
     36 Measure& Measure::operator=(const Measure& other) {
     37     if (this != &other) {
     38         delete unit;
     39         number = other.number;
     40         unit = (MeasureUnit*) other.unit->clone();
     41     }
     42     return *this;
     43 }
     44 
     45 Measure::~Measure() {
     46     delete unit;
     47 }
     48 
     49 UBool Measure::operator==(const UObject& other) const {
     50     const Measure* m = (const Measure*) &other;
     51     return getDynamicClassID() == other.getDynamicClassID() &&
     52         number == m->getNumber() &&
     53         (unit != NULL && *unit == m->getUnit());
     54 }
     55 
     56 //----------------------------------------------------------------------
     57 // MeasureUnit implementation
     58 
     59 MeasureUnit:: MeasureUnit() {}
     60 
     61 MeasureUnit::~MeasureUnit() {}
     62 
     63 U_NAMESPACE_END
     64 
     65 #endif // !UCONFIG_NO_FORMATTING
     66