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/utypes.h" 20 21 #if U_SHOW_CPLUSPLUS_API 22 23 #if !UCONFIG_NO_FORMATTING 24 25 #include "unicode/measure.h" 26 #include "unicode/tmunit.h" 27 28 U_NAMESPACE_BEGIN 29 30 31 /** 32 * Express a duration as a time unit and number. Patterned after Currency. 33 * @see TimeUnitAmount 34 * @see TimeUnitFormat 35 * @stable ICU 4.2 36 */ 37 class U_I18N_API TimeUnitAmount: public Measure { 38 public: 39 /** 40 * Construct TimeUnitAmount object with the given number and the 41 * given time unit. 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 46 * is not valid, 47 * then this will be set to a failing value: 48 * U_ILLEGAL_ARGUMENT_ERROR. 49 * @stable ICU 4.2 50 */ 51 TimeUnitAmount(const Formattable& number, 52 TimeUnit::UTimeUnitFields timeUnitField, 53 UErrorCode& status); 54 55 /** 56 * Construct TimeUnitAmount object with the given numeric amount and the 57 * given time unit. 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. 65 * @stable ICU 4.2 66 */ 67 TimeUnitAmount(double amount, TimeUnit::UTimeUnitFields timeUnitField, 68 UErrorCode& status); 69 70 71 /** 72 * Copy constructor 73 * @stable ICU 4.2 74 */ 75 TimeUnitAmount(const TimeUnitAmount& other); 76 77 78 /** 79 * Assignment operator 80 * @stable ICU 4.2 81 */ 82 TimeUnitAmount& operator=(const TimeUnitAmount& other); 83 84 85 /** 86 * Clone. 87 * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID(). 88 * @stable ICU 4.2 89 */ 90 virtual TimeUnitAmount* clone() const override; 91 92 93 /** 94 * Destructor 95 * @stable ICU 4.2 96 */ 97 virtual ~TimeUnitAmount(); 98 99 100 /** 101 * Equality operator. 102 * @param other the object to compare to. 103 * @return true if this object is equal to the given object. 104 * @stable ICU 4.2 105 */ 106 virtual bool operator==(const UObject& other) const; 107 108 109 /** 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. 113 * @stable ICU 4.2 114 */ 115 bool operator!=(const UObject& other) const; 116 117 118 /** 119 * Return the class ID for this class. This is useful only for comparing to 120 * a return value from getDynamicClassID(). For example: 121 * <pre> 122 * . Base* polymorphic_pointer = createPolymorphicObject(); 123 * . if (polymorphic_pointer->getDynamicClassID() == 124 * . erived::getStaticClassID()) ... 125 * </pre> 126 * @return The class ID for all objects of this class. 127 * @stable ICU 4.2 128 */ 129 static UClassID U_EXPORT2 getStaticClassID(void); 130 131 132 /** 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. 137 * 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. 141 * @stable ICU 4.2 142 */ 143 virtual UClassID getDynamicClassID(void) const override; 144 145 146 /** 147 * Get the time unit. 148 * @return time unit object. 149 * @stable ICU 4.2 150 */ 151 const TimeUnit& getTimeUnit() const; 152 153 /** 154 * Get the time unit field value. 155 * @return time unit field value. 156 * @stable ICU 4.2 157 */ 158 TimeUnit::UTimeUnitFields getTimeUnitField() const; 159 }; 160 161 162 163 inline bool 164 TimeUnitAmount::operator!=(const UObject& other) const { 165 return !operator==(other); 166 } 167 168 U_NAMESPACE_END 169 170 #endif /* #if !UCONFIG_NO_FORMATTING */ 171 172 #endif /* U_SHOW_CPLUSPLUS_API */ 173 174 #endif // __TMUTAMT_H__ 175 //eof 176 // 177