tmutamt.h 4.7 KB

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