1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2009-2010, Google, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
16 * \brief C++ API: time unit amount object.
19 #include "unicode/measure.h"
20 #include "unicode/tmunit.h"
22 #if !UCONFIG_NO_FORMATTING
24 #if U_SHOW_CPLUSPLUS_API
29 * Express a duration as a time unit and number. Patterned after Currency.
34 class U_I18N_API TimeUnitAmount
: public Measure
{
37 * Construct TimeUnitAmount object with the given number and the
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
44 * then this will be set to a failing value:
45 * U_ILLEGAL_ARGUMENT_ERROR.
48 TimeUnitAmount(const Formattable
& number
,
49 TimeUnit::UTimeUnitFields timeUnitField
,
53 * Construct TimeUnitAmount object with the given numeric amount and the
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.
64 TimeUnitAmount(double amount
, TimeUnit::UTimeUnitFields timeUnitField
,
72 TimeUnitAmount(const TimeUnitAmount
& other
);
79 TimeUnitAmount
& operator=(const TimeUnitAmount
& other
);
84 * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID().
87 virtual UObject
* clone() const;
94 virtual ~TimeUnitAmount();
99 * @param other the object to compare to.
100 * @return true if this object is equal to the given object.
103 virtual UBool
operator==(const UObject
& other
) const;
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.
112 UBool
operator!=(const UObject
& other
) const;
116 * Return the class ID for this class. This is useful only for comparing to
117 * a return value from getDynamicClassID(). For example:
119 * . Base* polymorphic_pointer = createPolymorphicObject();
120 * . if (polymorphic_pointer->getDynamicClassID() ==
121 * . erived::getStaticClassID()) ...
123 * @return The class ID for all objects of this class.
126 static UClassID U_EXPORT2
getStaticClassID(void);
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.
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.
140 virtual UClassID
getDynamicClassID(void) const;
145 * @return time unit object.
148 const TimeUnit
& getTimeUnit() const;
151 * Get the time unit field value.
152 * @return time unit field value.
155 TimeUnit::UTimeUnitFields
getTimeUnitField() const;
161 TimeUnitAmount::operator!=(const UObject
& other
) const {
162 return !operator==(other
);
166 #endif // U_SHOW_CPLUSPLUS_API
168 #endif /* #if !UCONFIG_NO_FORMATTING */
170 #endif // __TMUTAMT_H__