2 *******************************************************************************
3 * Copyright (C) 2009-2010, Google, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
14 * \brief C++ API: time unit amount object.
17 #include "unicode/measure.h"
18 #include "unicode/tmunit.h"
20 #if !UCONFIG_NO_FORMATTING
26 * Express a duration as a time unit and number. Patterned after Currency.
31 class U_I18N_API TimeUnitAmount
: public Measure
{
34 * Construct TimeUnitAmount object with the given number and the
36 * @param number a numeric object; number.isNumeric() must be TRUE
37 * @param timeUnitField the time unit field of a time unit
38 * @param status the input-output error code.
39 * If the number is not numeric or the timeUnitField
41 * then this will be set to a failing value:
42 * U_ILLEGAL_ARGUMENT_ERROR.
45 TimeUnitAmount(const Formattable
& number
,
46 TimeUnit::UTimeUnitFields timeUnitField
,
50 * Construct TimeUnitAmount object with the given numeric amount and the
52 * @param amount a numeric amount.
53 * @param timeUnitField the time unit field on which a time unit amount
54 * object will be created.
55 * @param status the input-output error code.
56 * If the timeUnitField is not valid,
57 * then this will be set to a failing value:
58 * U_ILLEGAL_ARGUMENT_ERROR.
61 TimeUnitAmount(double amount
, TimeUnit::UTimeUnitFields timeUnitField
,
69 TimeUnitAmount(const TimeUnitAmount
& other
);
76 TimeUnitAmount
& operator=(const TimeUnitAmount
& other
);
81 * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID().
84 virtual UObject
* clone() const;
91 virtual ~TimeUnitAmount();
96 * @param other the object to compare to.
97 * @return true if this object is equal to the given object.
100 virtual UBool
operator==(const UObject
& other
) const;
104 * Not-equality operator.
105 * @param other the object to compare to.
106 * @return true if this object is not equal to the given object.
109 UBool
operator!=(const UObject
& other
) const;
113 * Return the class ID for this class. This is useful only for comparing to
114 * a return value from getDynamicClassID(). For example:
116 * . Base* polymorphic_pointer = createPolymorphicObject();
117 * . if (polymorphic_pointer->getDynamicClassID() ==
118 * . erived::getStaticClassID()) ...
120 * @return The class ID for all objects of this class.
123 static UClassID U_EXPORT2
getStaticClassID(void);
127 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
128 * method is to implement a simple version of RTTI, since not all C++
129 * compilers support genuine RTTI. Polymorphic operator==() and clone()
130 * methods call this method.
132 * @return The class ID for this object. All objects of a
133 * given class have the same class ID. Objects of
134 * other classes have different class IDs.
137 virtual UClassID
getDynamicClassID(void) const;
142 * @return time unit object.
145 const TimeUnit
& getTimeUnit() const;
148 * Get the time unit field value.
149 * @return time unit field value.
152 TimeUnit::UTimeUnitFields
getTimeUnitField() const;
158 TimeUnitAmount::operator!=(const UObject
& other
) const {
159 return !operator==(other
);
164 #endif /* #if !UCONFIG_NO_FORMATTING */
166 #endif // __TMUTAMT_H__