• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **********************************************************************
3 * Copyright (c) 2004-2014, 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 "utypeinfo.h"  // for 'typeid' to work
12 
13 #include "unicode/utypes.h"
14 
15 #if !UCONFIG_NO_FORMATTING
16 
17 #include "unicode/measure.h"
18 #include "unicode/measunit.h"
19 
20 U_NAMESPACE_BEGIN
21 
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)22 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
23 
24 Measure::Measure() {}
25 
Measure(const Formattable & _number,MeasureUnit * adoptedUnit,UErrorCode & ec)26 Measure::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 
Measure(const Measure & other)35 Measure::Measure(const Measure& other) :
36     UObject(other), unit(0) {
37     *this = other;
38 }
39 
operator =(const Measure & other)40 Measure& 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 
clone() const49 UObject *Measure::clone() const {
50     return new Measure(*this);
51 }
52 
~Measure()53 Measure::~Measure() {
54     delete unit;
55 }
56 
operator ==(const UObject & other) const57 UBool Measure::operator==(const UObject& other) const {
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);
68 }
69 
70 U_NAMESPACE_END
71 
72 #endif // !UCONFIG_NO_FORMATTING
73