Coverage Report

Created: 2025-06-24 06:54

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