]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/measure.cpp
ICU-551.51.4.tar.gz
[apple/icu.git] / icuSources / i18n / measure.cpp
CommitLineData
374ca955
A
1/*
2**********************************************************************
57a6839d 3* Copyright (c) 2004-2014, 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
57a6839d
A
22UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
23
374ca955
A
24Measure::Measure() {}
25
26Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
27 UErrorCode& ec) :
28 number(_number), unit(adoptedUnit) {
29 if (U_SUCCESS(ec) &&
30 (!number.isNumeric() || adoptedUnit == 0)) {
31 ec = U_ILLEGAL_ARGUMENT_ERROR;
32 }
33}
34
35Measure::Measure(const Measure& other) :
36 UObject(other), unit(0) {
37 *this = other;
38}
39
40Measure& Measure::operator=(const Measure& other) {
41 if (this != &other) {
42 delete unit;
43 number = other.number;
44 unit = (MeasureUnit*) other.unit->clone();
45 }
46 return *this;
47}
48
57a6839d
A
49UObject *Measure::clone() const {
50 return new Measure(*this);
51}
52
374ca955
A
53Measure::~Measure() {
54 delete unit;
55}
56
57UBool Measure::operator==(const UObject& other) const {
57a6839d
A
58 if (this == &other) { // Same object, equal
59 return TRUE;
60 }
61 if (typeid(*this) != typeid(other)) { // Different types, not equal
62 return FALSE;
63 }
64 const Measure &m = static_cast<const Measure&>(other);
65 return number == m.number &&
66 ((unit == NULL) == (m.unit == NULL)) &&
67 (unit == NULL || *unit == *m.unit);
374ca955
A
68}
69
374ca955
A
70U_NAMESPACE_END
71
72#endif // !UCONFIG_NO_FORMATTING