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