]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/measure.cpp
ICU-64243.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / measure.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
374ca955
A
3/*
4**********************************************************************
57a6839d 5* Copyright (c) 2004-2014, International Business Machines
374ca955
A
6* Corporation and others. All Rights Reserved.
7**********************************************************************
8* Author: Alan Liu
9* Created: April 26, 2004
10* Since: ICU 3.0
11**********************************************************************
12*/
51004dcb 13#include "utypeinfo.h" // for 'typeid' to work
729e4ab9 14
374ca955
A
15#include "unicode/utypes.h"
16
17#if !UCONFIG_NO_FORMATTING
18
19#include "unicode/measure.h"
20#include "unicode/measunit.h"
21
22U_NAMESPACE_BEGIN
23
57a6839d
A
24UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
25
374ca955
A
26Measure::Measure() {}
27
28Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
29 UErrorCode& ec) :
30 number(_number), unit(adoptedUnit) {
31 if (U_SUCCESS(ec) &&
32 (!number.isNumeric() || adoptedUnit == 0)) {
33 ec = U_ILLEGAL_ARGUMENT_ERROR;
34 }
35}
36
37Measure::Measure(const Measure& other) :
38 UObject(other), unit(0) {
39 *this = other;
40}
41
42Measure& Measure::operator=(const Measure& other) {
43 if (this != &other) {
44 delete unit;
45 number = other.number;
46 unit = (MeasureUnit*) other.unit->clone();
47 }
48 return *this;
49}
50
57a6839d
A
51UObject *Measure::clone() const {
52 return new Measure(*this);
53}
54
374ca955
A
55Measure::~Measure() {
56 delete unit;
57}
58
59UBool Measure::operator==(const UObject& other) const {
57a6839d
A
60 if (this == &other) { // Same object, equal
61 return TRUE;
62 }
63 if (typeid(*this) != typeid(other)) { // Different types, not equal
64 return FALSE;
65 }
66 const Measure &m = static_cast<const Measure&>(other);
67 return number == m.number &&
68 ((unit == NULL) == (m.unit == NULL)) &&
69 (unit == NULL || *unit == *m.unit);
374ca955
A
70}
71
374ca955
A
72U_NAMESPACE_END
73
74#endif // !UCONFIG_NO_FORMATTING