1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2009-2010, Google, International Business Machines Corporation and * 6*0e209d39SAndroid Build Coastguard Worker * others. All Rights Reserved. * 7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 8*0e209d39SAndroid Build Coastguard Worker */ 9*0e209d39SAndroid Build Coastguard Worker 10*0e209d39SAndroid Build Coastguard Worker #ifndef __TMUTAMT_H__ 11*0e209d39SAndroid Build Coastguard Worker #define __TMUTAMT_H__ 12*0e209d39SAndroid Build Coastguard Worker 13*0e209d39SAndroid Build Coastguard Worker 14*0e209d39SAndroid Build Coastguard Worker /** 15*0e209d39SAndroid Build Coastguard Worker * \file 16*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: time unit amount object. 17*0e209d39SAndroid Build Coastguard Worker */ 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 20*0e209d39SAndroid Build Coastguard Worker 21*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 22*0e209d39SAndroid Build Coastguard Worker 23*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING 24*0e209d39SAndroid Build Coastguard Worker 25*0e209d39SAndroid Build Coastguard Worker #include "unicode/measure.h" 26*0e209d39SAndroid Build Coastguard Worker #include "unicode/tmunit.h" 27*0e209d39SAndroid Build Coastguard Worker 28*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 29*0e209d39SAndroid Build Coastguard Worker 30*0e209d39SAndroid Build Coastguard Worker 31*0e209d39SAndroid Build Coastguard Worker /** 32*0e209d39SAndroid Build Coastguard Worker * Express a duration as a time unit and number. Patterned after Currency. 33*0e209d39SAndroid Build Coastguard Worker * @see TimeUnitAmount 34*0e209d39SAndroid Build Coastguard Worker * @see TimeUnitFormat 35*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 36*0e209d39SAndroid Build Coastguard Worker */ 37*0e209d39SAndroid Build Coastguard Worker class U_I18N_API TimeUnitAmount: public Measure { 38*0e209d39SAndroid Build Coastguard Worker public: 39*0e209d39SAndroid Build Coastguard Worker /** 40*0e209d39SAndroid Build Coastguard Worker * Construct TimeUnitAmount object with the given number and the 41*0e209d39SAndroid Build Coastguard Worker * given time unit. 42*0e209d39SAndroid Build Coastguard Worker * @param number a numeric object; number.isNumeric() must be true 43*0e209d39SAndroid Build Coastguard Worker * @param timeUnitField the time unit field of a time unit 44*0e209d39SAndroid Build Coastguard Worker * @param status the input-output error code. 45*0e209d39SAndroid Build Coastguard Worker * If the number is not numeric or the timeUnitField 46*0e209d39SAndroid Build Coastguard Worker * is not valid, 47*0e209d39SAndroid Build Coastguard Worker * then this will be set to a failing value: 48*0e209d39SAndroid Build Coastguard Worker * U_ILLEGAL_ARGUMENT_ERROR. 49*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 50*0e209d39SAndroid Build Coastguard Worker */ 51*0e209d39SAndroid Build Coastguard Worker TimeUnitAmount(const Formattable& number, 52*0e209d39SAndroid Build Coastguard Worker TimeUnit::UTimeUnitFields timeUnitField, 53*0e209d39SAndroid Build Coastguard Worker UErrorCode& status); 54*0e209d39SAndroid Build Coastguard Worker 55*0e209d39SAndroid Build Coastguard Worker /** 56*0e209d39SAndroid Build Coastguard Worker * Construct TimeUnitAmount object with the given numeric amount and the 57*0e209d39SAndroid Build Coastguard Worker * given time unit. 58*0e209d39SAndroid Build Coastguard Worker * @param amount a numeric amount. 59*0e209d39SAndroid Build Coastguard Worker * @param timeUnitField the time unit field on which a time unit amount 60*0e209d39SAndroid Build Coastguard Worker * object will be created. 61*0e209d39SAndroid Build Coastguard Worker * @param status the input-output error code. 62*0e209d39SAndroid Build Coastguard Worker * If the timeUnitField is not valid, 63*0e209d39SAndroid Build Coastguard Worker * then this will be set to a failing value: 64*0e209d39SAndroid Build Coastguard Worker * U_ILLEGAL_ARGUMENT_ERROR. 65*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 66*0e209d39SAndroid Build Coastguard Worker */ 67*0e209d39SAndroid Build Coastguard Worker TimeUnitAmount(double amount, TimeUnit::UTimeUnitFields timeUnitField, 68*0e209d39SAndroid Build Coastguard Worker UErrorCode& status); 69*0e209d39SAndroid Build Coastguard Worker 70*0e209d39SAndroid Build Coastguard Worker 71*0e209d39SAndroid Build Coastguard Worker /** 72*0e209d39SAndroid Build Coastguard Worker * Copy constructor 73*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 74*0e209d39SAndroid Build Coastguard Worker */ 75*0e209d39SAndroid Build Coastguard Worker TimeUnitAmount(const TimeUnitAmount& other); 76*0e209d39SAndroid Build Coastguard Worker 77*0e209d39SAndroid Build Coastguard Worker 78*0e209d39SAndroid Build Coastguard Worker /** 79*0e209d39SAndroid Build Coastguard Worker * Assignment operator 80*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 81*0e209d39SAndroid Build Coastguard Worker */ 82*0e209d39SAndroid Build Coastguard Worker TimeUnitAmount& operator=(const TimeUnitAmount& other); 83*0e209d39SAndroid Build Coastguard Worker 84*0e209d39SAndroid Build Coastguard Worker 85*0e209d39SAndroid Build Coastguard Worker /** 86*0e209d39SAndroid Build Coastguard Worker * Clone. 87*0e209d39SAndroid Build Coastguard Worker * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID(). 88*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 89*0e209d39SAndroid Build Coastguard Worker */ 90*0e209d39SAndroid Build Coastguard Worker virtual TimeUnitAmount* clone() const override; 91*0e209d39SAndroid Build Coastguard Worker 92*0e209d39SAndroid Build Coastguard Worker 93*0e209d39SAndroid Build Coastguard Worker /** 94*0e209d39SAndroid Build Coastguard Worker * Destructor 95*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 96*0e209d39SAndroid Build Coastguard Worker */ 97*0e209d39SAndroid Build Coastguard Worker virtual ~TimeUnitAmount(); 98*0e209d39SAndroid Build Coastguard Worker 99*0e209d39SAndroid Build Coastguard Worker 100*0e209d39SAndroid Build Coastguard Worker /** 101*0e209d39SAndroid Build Coastguard Worker * Equality operator. 102*0e209d39SAndroid Build Coastguard Worker * @param other the object to compare to. 103*0e209d39SAndroid Build Coastguard Worker * @return true if this object is equal to the given object. 104*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 105*0e209d39SAndroid Build Coastguard Worker */ 106*0e209d39SAndroid Build Coastguard Worker virtual bool operator==(const UObject& other) const; 107*0e209d39SAndroid Build Coastguard Worker 108*0e209d39SAndroid Build Coastguard Worker 109*0e209d39SAndroid Build Coastguard Worker /** 110*0e209d39SAndroid Build Coastguard Worker * Not-equality operator. 111*0e209d39SAndroid Build Coastguard Worker * @param other the object to compare to. 112*0e209d39SAndroid Build Coastguard Worker * @return true if this object is not equal to the given object. 113*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 114*0e209d39SAndroid Build Coastguard Worker */ 115*0e209d39SAndroid Build Coastguard Worker bool operator!=(const UObject& other) const; 116*0e209d39SAndroid Build Coastguard Worker 117*0e209d39SAndroid Build Coastguard Worker 118*0e209d39SAndroid Build Coastguard Worker /** 119*0e209d39SAndroid Build Coastguard Worker * Return the class ID for this class. This is useful only for comparing to 120*0e209d39SAndroid Build Coastguard Worker * a return value from getDynamicClassID(). For example: 121*0e209d39SAndroid Build Coastguard Worker * <pre> 122*0e209d39SAndroid Build Coastguard Worker * . Base* polymorphic_pointer = createPolymorphicObject(); 123*0e209d39SAndroid Build Coastguard Worker * . if (polymorphic_pointer->getDynamicClassID() == 124*0e209d39SAndroid Build Coastguard Worker * . erived::getStaticClassID()) ... 125*0e209d39SAndroid Build Coastguard Worker * </pre> 126*0e209d39SAndroid Build Coastguard Worker * @return The class ID for all objects of this class. 127*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 128*0e209d39SAndroid Build Coastguard Worker */ 129*0e209d39SAndroid Build Coastguard Worker static UClassID U_EXPORT2 getStaticClassID(); 130*0e209d39SAndroid Build Coastguard Worker 131*0e209d39SAndroid Build Coastguard Worker /** 132*0e209d39SAndroid Build Coastguard Worker * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This 133*0e209d39SAndroid Build Coastguard Worker * method is to implement a simple version of RTTI, since not all C++ 134*0e209d39SAndroid Build Coastguard Worker * compilers support genuine RTTI. Polymorphic operator==() and clone() 135*0e209d39SAndroid Build Coastguard Worker * methods call this method. 136*0e209d39SAndroid Build Coastguard Worker * 137*0e209d39SAndroid Build Coastguard Worker * @return The class ID for this object. All objects of a 138*0e209d39SAndroid Build Coastguard Worker * given class have the same class ID. Objects of 139*0e209d39SAndroid Build Coastguard Worker * other classes have different class IDs. 140*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 141*0e209d39SAndroid Build Coastguard Worker */ 142*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override; 143*0e209d39SAndroid Build Coastguard Worker 144*0e209d39SAndroid Build Coastguard Worker /** 145*0e209d39SAndroid Build Coastguard Worker * Get the time unit. 146*0e209d39SAndroid Build Coastguard Worker * @return time unit object. 147*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 148*0e209d39SAndroid Build Coastguard Worker */ 149*0e209d39SAndroid Build Coastguard Worker const TimeUnit& getTimeUnit() const; 150*0e209d39SAndroid Build Coastguard Worker 151*0e209d39SAndroid Build Coastguard Worker /** 152*0e209d39SAndroid Build Coastguard Worker * Get the time unit field value. 153*0e209d39SAndroid Build Coastguard Worker * @return time unit field value. 154*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2 155*0e209d39SAndroid Build Coastguard Worker */ 156*0e209d39SAndroid Build Coastguard Worker TimeUnit::UTimeUnitFields getTimeUnitField() const; 157*0e209d39SAndroid Build Coastguard Worker }; 158*0e209d39SAndroid Build Coastguard Worker 159*0e209d39SAndroid Build Coastguard Worker 160*0e209d39SAndroid Build Coastguard Worker 161*0e209d39SAndroid Build Coastguard Worker inline bool 162*0e209d39SAndroid Build Coastguard Worker TimeUnitAmount::operator!=(const UObject& other) const { 163*0e209d39SAndroid Build Coastguard Worker return !operator==(other); 164*0e209d39SAndroid Build Coastguard Worker } 165*0e209d39SAndroid Build Coastguard Worker 166*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 167*0e209d39SAndroid Build Coastguard Worker 168*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */ 169*0e209d39SAndroid Build Coastguard Worker 170*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */ 171*0e209d39SAndroid Build Coastguard Worker 172*0e209d39SAndroid Build Coastguard Worker #endif // __TMUTAMT_H__ 173*0e209d39SAndroid Build Coastguard Worker //eof 174*0e209d39SAndroid Build Coastguard Worker // 175