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