michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2009-2010, Google, International Business Machines Corporation and * michael@0: * others. All Rights Reserved. * michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef __TMUTAMT_H__ michael@0: #define __TMUTAMT_H__ michael@0: michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: time unit amount object. michael@0: */ michael@0: michael@0: #include "unicode/measure.h" michael@0: #include "unicode/tmunit.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: michael@0: /** michael@0: * Express a duration as a time unit and number. Patterned after Currency. michael@0: * @see TimeUnitAmount michael@0: * @see TimeUnitFormat michael@0: * @stable ICU 4.2 michael@0: */ michael@0: class U_I18N_API TimeUnitAmount: public Measure { michael@0: public: michael@0: /** michael@0: * Construct TimeUnitAmount object with the given number and the michael@0: * given time unit. michael@0: * @param number a numeric object; number.isNumeric() must be TRUE michael@0: * @param timeUnitField the time unit field of a time unit michael@0: * @param status the input-output error code. michael@0: * If the number is not numeric or the timeUnitField michael@0: * is not valid, michael@0: * then this will be set to a failing value: michael@0: * U_ILLEGAL_ARGUMENT_ERROR. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: TimeUnitAmount(const Formattable& number, michael@0: TimeUnit::UTimeUnitFields timeUnitField, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Construct TimeUnitAmount object with the given numeric amount and the michael@0: * given time unit. michael@0: * @param amount a numeric amount. michael@0: * @param timeUnitField the time unit field on which a time unit amount michael@0: * object will be created. michael@0: * @param status the input-output error code. michael@0: * If the timeUnitField is not valid, michael@0: * then this will be set to a failing value: michael@0: * U_ILLEGAL_ARGUMENT_ERROR. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: TimeUnitAmount(double amount, TimeUnit::UTimeUnitFields timeUnitField, michael@0: UErrorCode& status); michael@0: michael@0: michael@0: /** michael@0: * Copy constructor michael@0: * @stable ICU 4.2 michael@0: */ michael@0: TimeUnitAmount(const TimeUnitAmount& other); michael@0: michael@0: michael@0: /** michael@0: * Assignment operator michael@0: * @stable ICU 4.2 michael@0: */ michael@0: TimeUnitAmount& operator=(const TimeUnitAmount& other); michael@0: michael@0: michael@0: /** michael@0: * Clone. michael@0: * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID(). michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual UObject* clone() const; michael@0: michael@0: michael@0: /** michael@0: * Destructor michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual ~TimeUnitAmount(); michael@0: michael@0: michael@0: /** michael@0: * Equality operator. michael@0: * @param other the object to compare to. michael@0: * @return true if this object is equal to the given object. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual UBool operator==(const UObject& other) const; michael@0: michael@0: michael@0: /** michael@0: * Not-equality operator. michael@0: * @param other the object to compare to. michael@0: * @return true if this object is not equal to the given object. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: UBool operator!=(const UObject& other) const; michael@0: michael@0: michael@0: /** michael@0: * Return the class ID for this class. This is useful only for comparing to michael@0: * a return value from getDynamicClassID(). For example: michael@0: *
michael@0:      * .   Base* polymorphic_pointer = createPolymorphicObject();
michael@0:      * .   if (polymorphic_pointer->getDynamicClassID() ==
michael@0:      * .       erived::getStaticClassID()) ...
michael@0:      * 
michael@0: * @return The class ID for all objects of this class. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: michael@0: /** michael@0: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This michael@0: * method is to implement a simple version of RTTI, since not all C++ michael@0: * compilers support genuine RTTI. Polymorphic operator==() and clone() michael@0: * methods call this method. michael@0: * michael@0: * @return The class ID for this object. All objects of a michael@0: * given class have the same class ID. Objects of michael@0: * other classes have different class IDs. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const; michael@0: michael@0: michael@0: /** michael@0: * Get the time unit. michael@0: * @return time unit object. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: const TimeUnit& getTimeUnit() const; michael@0: michael@0: /** michael@0: * Get the time unit field value. michael@0: * @return time unit field value. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: TimeUnit::UTimeUnitFields getTimeUnitField() const; michael@0: }; michael@0: michael@0: michael@0: michael@0: inline UBool michael@0: TimeUnitAmount::operator!=(const UObject& other) const { michael@0: return !operator==(other); michael@0: } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // __TMUTAMT_H__ michael@0: //eof michael@0: //