]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/measure.cpp
ICU-511.35.tar.gz
[apple/icu.git] / icuSources / i18n / measure.cpp
CommitLineData
374ca955
A
1/*
2**********************************************************************
51004dcb 3* Copyright (c) 2004-2012, International Business Machines
374ca955
A
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6* Author: Alan Liu
7* Created: April 26, 2004
8* Since: ICU 3.0
9**********************************************************************
10*/
51004dcb 11#include "utypeinfo.h" // for 'typeid' to work
729e4ab9 12
374ca955
A
13#include "unicode/utypes.h"
14
15#if !UCONFIG_NO_FORMATTING
16
17#include "unicode/measure.h"
18#include "unicode/measunit.h"
19
20U_NAMESPACE_BEGIN
21
22Measure::Measure() {}
23
24Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
25 UErrorCode& ec) :
26 number(_number), unit(adoptedUnit) {
27 if (U_SUCCESS(ec) &&
28 (!number.isNumeric() || adoptedUnit == 0)) {
29 ec = U_ILLEGAL_ARGUMENT_ERROR;
30 }
31}
32
33Measure::Measure(const Measure& other) :
34 UObject(other), unit(0) {
35 *this = other;
36}
37
38Measure& Measure::operator=(const Measure& other) {
39 if (this != &other) {
40 delete unit;
41 number = other.number;
42 unit = (MeasureUnit*) other.unit->clone();
43 }
44 return *this;
45}
46
47Measure::~Measure() {
48 delete unit;
49}
50
51UBool Measure::operator==(const UObject& other) const {
52 const Measure* m = (const Measure*) &other;
729e4ab9 53 return typeid(*this) == typeid(other) &&
46f4442e
A
54 number == m->getNumber() &&
55 (unit != NULL && *unit == m->getUnit());
374ca955
A
56}
57
58//----------------------------------------------------------------------
59// MeasureUnit implementation
60
61MeasureUnit:: MeasureUnit() {}
62
63MeasureUnit::~MeasureUnit() {}
64
65U_NAMESPACE_END
66
67#endif // !UCONFIG_NO_FORMATTING