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