tmutamt.h 4.8 KB

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