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/utypes.h"
21 #if U_SHOW_CPLUSPLUS_API
23 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/measure.h"
26 #include "unicode/tmunit.h"
32 * Express a duration as a time unit and number. Patterned after Currency.
37 class U_I18N_API TimeUnitAmount
: public Measure
{
40 * Construct TimeUnitAmount object with the given number and the
42 * @param number a numeric object; number.isNumeric() must be TRUE
43 * @param timeUnitField the time unit field of a time unit
44 * @param status the input-output error code.
45 * If the number is not numeric or the timeUnitField
47 * then this will be set to a failing value:
48 * U_ILLEGAL_ARGUMENT_ERROR.
51 TimeUnitAmount(const Formattable
& number
,
52 TimeUnit::UTimeUnitFields timeUnitField
,
56 * Construct TimeUnitAmount object with the given numeric amount and the
58 * @param amount a numeric amount.
59 * @param timeUnitField the time unit field on which a time unit amount
60 * object will be created.
61 * @param status the input-output error code.
62 * If the timeUnitField is not valid,
63 * then this will be set to a failing value:
64 * U_ILLEGAL_ARGUMENT_ERROR.
67 TimeUnitAmount(double amount
, TimeUnit::UTimeUnitFields timeUnitField
,
75 TimeUnitAmount(const TimeUnitAmount
& other
);
82 TimeUnitAmount
& operator=(const TimeUnitAmount
& other
);
87 * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID().
90 virtual TimeUnitAmount
* clone() const;
97 virtual ~TimeUnitAmount();
102 * @param other the object to compare to.
103 * @return true if this object is equal to the given object.
106 virtual UBool
operator==(const UObject
& other
) const;
110 * Not-equality operator.
111 * @param other the object to compare to.
112 * @return true if this object is not equal to the given object.
115 UBool
operator!=(const UObject
& other
) const;
119 * Return the class ID for this class. This is useful only for comparing to
120 * a return value from getDynamicClassID(). For example:
122 * . Base* polymorphic_pointer = createPolymorphicObject();
123 * . if (polymorphic_pointer->getDynamicClassID() ==
124 * . erived::getStaticClassID()) ...
126 * @return The class ID for all objects of this class.
129 static UClassID U_EXPORT2
getStaticClassID(void);
133 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
134 * method is to implement a simple version of RTTI, since not all C++
135 * compilers support genuine RTTI. Polymorphic operator==() and clone()
136 * methods call this method.
138 * @return The class ID for this object. All objects of a
139 * given class have the same class ID. Objects of
140 * other classes have different class IDs.
143 virtual UClassID
getDynamicClassID(void) const;
148 * @return time unit object.
151 const TimeUnit
& getTimeUnit() const;
154 * Get the time unit field value.
155 * @return time unit field value.
158 TimeUnit::UTimeUnitFields
getTimeUnitField() const;
164 TimeUnitAmount::operator!=(const UObject
& other
) const {
165 return !operator==(other
);
170 #endif /* #if !UCONFIG_NO_FORMATTING */
172 #endif /* U_SHOW_CPLUSPLUS_API */
174 #endif // __TMUTAMT_H__