tmutamt.h 4.9 KB

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