/src/mozilla-central/intl/icu/source/i18n/unicode/tmutamt.h
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) 2009-2010, Google, International Business Machines Corporation and * |
6 | | * others. All Rights Reserved. * |
7 | | ******************************************************************************* |
8 | | */ |
9 | | |
10 | | #ifndef __TMUTAMT_H__ |
11 | | #define __TMUTAMT_H__ |
12 | | |
13 | | |
14 | | /** |
15 | | * \file |
16 | | * \brief C++ API: time unit amount object. |
17 | | */ |
18 | | |
19 | | #include "unicode/measure.h" |
20 | | #include "unicode/tmunit.h" |
21 | | |
22 | | #if !UCONFIG_NO_FORMATTING |
23 | | |
24 | | U_NAMESPACE_BEGIN |
25 | | |
26 | | |
27 | | /** |
28 | | * Express a duration as a time unit and number. Patterned after Currency. |
29 | | * @see TimeUnitAmount |
30 | | * @see TimeUnitFormat |
31 | | * @stable ICU 4.2 |
32 | | */ |
33 | | class U_I18N_API TimeUnitAmount: public Measure { |
34 | | public: |
35 | | /** |
36 | | * Construct TimeUnitAmount object with the given number and the |
37 | | * given time unit. |
38 | | * @param number a numeric object; number.isNumeric() must be TRUE |
39 | | * @param timeUnitField the time unit field of a time unit |
40 | | * @param status the input-output error code. |
41 | | * If the number is not numeric or the timeUnitField |
42 | | * is not valid, |
43 | | * then this will be set to a failing value: |
44 | | * U_ILLEGAL_ARGUMENT_ERROR. |
45 | | * @stable ICU 4.2 |
46 | | */ |
47 | | TimeUnitAmount(const Formattable& number, |
48 | | TimeUnit::UTimeUnitFields timeUnitField, |
49 | | UErrorCode& status); |
50 | | |
51 | | /** |
52 | | * Construct TimeUnitAmount object with the given numeric amount and the |
53 | | * given time unit. |
54 | | * @param amount a numeric amount. |
55 | | * @param timeUnitField the time unit field on which a time unit amount |
56 | | * object will be created. |
57 | | * @param status the input-output error code. |
58 | | * If the timeUnitField is not valid, |
59 | | * then this will be set to a failing value: |
60 | | * U_ILLEGAL_ARGUMENT_ERROR. |
61 | | * @stable ICU 4.2 |
62 | | */ |
63 | | TimeUnitAmount(double amount, TimeUnit::UTimeUnitFields timeUnitField, |
64 | | UErrorCode& status); |
65 | | |
66 | | |
67 | | /** |
68 | | * Copy constructor |
69 | | * @stable ICU 4.2 |
70 | | */ |
71 | | TimeUnitAmount(const TimeUnitAmount& other); |
72 | | |
73 | | |
74 | | /** |
75 | | * Assignment operator |
76 | | * @stable ICU 4.2 |
77 | | */ |
78 | | TimeUnitAmount& operator=(const TimeUnitAmount& other); |
79 | | |
80 | | |
81 | | /** |
82 | | * Clone. |
83 | | * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID(). |
84 | | * @stable ICU 4.2 |
85 | | */ |
86 | | virtual UObject* clone() const; |
87 | | |
88 | | |
89 | | /** |
90 | | * Destructor |
91 | | * @stable ICU 4.2 |
92 | | */ |
93 | | virtual ~TimeUnitAmount(); |
94 | | |
95 | | |
96 | | /** |
97 | | * Equality operator. |
98 | | * @param other the object to compare to. |
99 | | * @return true if this object is equal to the given object. |
100 | | * @stable ICU 4.2 |
101 | | */ |
102 | | virtual UBool operator==(const UObject& other) const; |
103 | | |
104 | | |
105 | | /** |
106 | | * Not-equality operator. |
107 | | * @param other the object to compare to. |
108 | | * @return true if this object is not equal to the given object. |
109 | | * @stable ICU 4.2 |
110 | | */ |
111 | | UBool operator!=(const UObject& other) const; |
112 | | |
113 | | |
114 | | /** |
115 | | * Return the class ID for this class. This is useful only for comparing to |
116 | | * a return value from getDynamicClassID(). For example: |
117 | | * <pre> |
118 | | * . Base* polymorphic_pointer = createPolymorphicObject(); |
119 | | * . if (polymorphic_pointer->getDynamicClassID() == |
120 | | * . erived::getStaticClassID()) ... |
121 | | * </pre> |
122 | | * @return The class ID for all objects of this class. |
123 | | * @stable ICU 4.2 |
124 | | */ |
125 | | static UClassID U_EXPORT2 getStaticClassID(void); |
126 | | |
127 | | |
128 | | /** |
129 | | * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This |
130 | | * method is to implement a simple version of RTTI, since not all C++ |
131 | | * compilers support genuine RTTI. Polymorphic operator==() and clone() |
132 | | * methods call this method. |
133 | | * |
134 | | * @return The class ID for this object. All objects of a |
135 | | * given class have the same class ID. Objects of |
136 | | * other classes have different class IDs. |
137 | | * @stable ICU 4.2 |
138 | | */ |
139 | | virtual UClassID getDynamicClassID(void) const; |
140 | | |
141 | | |
142 | | /** |
143 | | * Get the time unit. |
144 | | * @return time unit object. |
145 | | * @stable ICU 4.2 |
146 | | */ |
147 | | const TimeUnit& getTimeUnit() const; |
148 | | |
149 | | /** |
150 | | * Get the time unit field value. |
151 | | * @return time unit field value. |
152 | | * @stable ICU 4.2 |
153 | | */ |
154 | | TimeUnit::UTimeUnitFields getTimeUnitField() const; |
155 | | }; |
156 | | |
157 | | |
158 | | |
159 | | inline UBool |
160 | 0 | TimeUnitAmount::operator!=(const UObject& other) const { |
161 | 0 | return !operator==(other); |
162 | 0 | } |
163 | | |
164 | | U_NAMESPACE_END |
165 | | |
166 | | #endif /* #if !UCONFIG_NO_FORMATTING */ |
167 | | |
168 | | #endif // __TMUTAMT_H__ |
169 | | //eof |
170 | | // |