intl/icu/source/i18n/measure.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/measure.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +* Copyright (c) 2004-2012, International Business Machines
     1.7 +* Corporation and others.  All Rights Reserved.
     1.8 +**********************************************************************
     1.9 +* Author: Alan Liu
    1.10 +* Created: April 26, 2004
    1.11 +* Since: ICU 3.0
    1.12 +**********************************************************************
    1.13 +*/
    1.14 +#include "utypeinfo.h"  // for 'typeid' to work
    1.15 +
    1.16 +#include "unicode/utypes.h"
    1.17 +
    1.18 +#if !UCONFIG_NO_FORMATTING
    1.19 +
    1.20 +#include "unicode/measure.h"
    1.21 +#include "unicode/measunit.h"
    1.22 +
    1.23 +U_NAMESPACE_BEGIN
    1.24 +
    1.25 +Measure::Measure() {}
    1.26 +
    1.27 +Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
    1.28 +                 UErrorCode& ec) :
    1.29 +    number(_number), unit(adoptedUnit) {
    1.30 +    if (U_SUCCESS(ec) &&
    1.31 +        (!number.isNumeric() || adoptedUnit == 0)) {
    1.32 +        ec = U_ILLEGAL_ARGUMENT_ERROR;
    1.33 +    }
    1.34 +}
    1.35 +
    1.36 +Measure::Measure(const Measure& other) :
    1.37 +    UObject(other), unit(0) {
    1.38 +    *this = other;
    1.39 +}
    1.40 +
    1.41 +Measure& Measure::operator=(const Measure& other) {
    1.42 +    if (this != &other) {
    1.43 +        delete unit;
    1.44 +        number = other.number;
    1.45 +        unit = (MeasureUnit*) other.unit->clone();
    1.46 +    }
    1.47 +    return *this;
    1.48 +}
    1.49 +
    1.50 +Measure::~Measure() {
    1.51 +    delete unit;
    1.52 +}
    1.53 +
    1.54 +UBool Measure::operator==(const UObject& other) const {
    1.55 +    const Measure* m = (const Measure*) &other;
    1.56 +    return typeid(*this) == typeid(other) &&
    1.57 +        number == m->getNumber() && 
    1.58 +        (unit != NULL && *unit == m->getUnit());
    1.59 +}
    1.60 +
    1.61 +//----------------------------------------------------------------------
    1.62 +// MeasureUnit implementation
    1.63 +
    1.64 +MeasureUnit:: MeasureUnit() {}
    1.65 +
    1.66 +MeasureUnit::~MeasureUnit() {}
    1.67 +
    1.68 +U_NAMESPACE_END
    1.69 +
    1.70 +#endif // !UCONFIG_NO_FORMATTING

mercurial