jpayne@69
|
1 // © 2016 and later: Unicode, Inc. and others.
|
jpayne@69
|
2 // License & terms of use: http://www.unicode.org/copyright.html
|
jpayne@69
|
3 /*
|
jpayne@69
|
4 **********************************************************************
|
jpayne@69
|
5 * Copyright (c) 2004-2015, International Business Machines
|
jpayne@69
|
6 * Corporation and others. All Rights Reserved.
|
jpayne@69
|
7 **********************************************************************
|
jpayne@69
|
8 * Author: Alan Liu
|
jpayne@69
|
9 * Created: April 26, 2004
|
jpayne@69
|
10 * Since: ICU 3.0
|
jpayne@69
|
11 **********************************************************************
|
jpayne@69
|
12 */
|
jpayne@69
|
13 #ifndef __MEASURE_H__
|
jpayne@69
|
14 #define __MEASURE_H__
|
jpayne@69
|
15
|
jpayne@69
|
16 #include "unicode/utypes.h"
|
jpayne@69
|
17
|
jpayne@69
|
18 #if U_SHOW_CPLUSPLUS_API
|
jpayne@69
|
19
|
jpayne@69
|
20 /**
|
jpayne@69
|
21 * \file
|
jpayne@69
|
22 * \brief C++ API: MeasureUnit object.
|
jpayne@69
|
23 */
|
jpayne@69
|
24
|
jpayne@69
|
25 #if !UCONFIG_NO_FORMATTING
|
jpayne@69
|
26
|
jpayne@69
|
27 #include "unicode/fmtable.h"
|
jpayne@69
|
28
|
jpayne@69
|
29 U_NAMESPACE_BEGIN
|
jpayne@69
|
30
|
jpayne@69
|
31 class MeasureUnit;
|
jpayne@69
|
32
|
jpayne@69
|
33 /**
|
jpayne@69
|
34 * An amount of a specified unit, consisting of a number and a Unit.
|
jpayne@69
|
35 * For example, a length measure consists of a number and a length
|
jpayne@69
|
36 * unit, such as feet or meters.
|
jpayne@69
|
37 *
|
jpayne@69
|
38 * <p>Measure objects are formatted by MeasureFormat.
|
jpayne@69
|
39 *
|
jpayne@69
|
40 * <p>Measure objects are immutable.
|
jpayne@69
|
41 *
|
jpayne@69
|
42 * @author Alan Liu
|
jpayne@69
|
43 * @stable ICU 3.0
|
jpayne@69
|
44 */
|
jpayne@69
|
45 class U_I18N_API Measure: public UObject {
|
jpayne@69
|
46 public:
|
jpayne@69
|
47 /**
|
jpayne@69
|
48 * Construct an object with the given numeric amount and the given
|
jpayne@69
|
49 * unit. After this call, the caller must not delete the given
|
jpayne@69
|
50 * unit object.
|
jpayne@69
|
51 * @param number a numeric object; amount.isNumeric() must be TRUE
|
jpayne@69
|
52 * @param adoptedUnit the unit object, which must not be NULL
|
jpayne@69
|
53 * @param ec input-output error code. If the amount or the unit
|
jpayne@69
|
54 * is invalid, then this will be set to a failing value.
|
jpayne@69
|
55 * @stable ICU 3.0
|
jpayne@69
|
56 */
|
jpayne@69
|
57 Measure(const Formattable& number, MeasureUnit* adoptedUnit,
|
jpayne@69
|
58 UErrorCode& ec);
|
jpayne@69
|
59
|
jpayne@69
|
60 /**
|
jpayne@69
|
61 * Copy constructor
|
jpayne@69
|
62 * @stable ICU 3.0
|
jpayne@69
|
63 */
|
jpayne@69
|
64 Measure(const Measure& other);
|
jpayne@69
|
65
|
jpayne@69
|
66 /**
|
jpayne@69
|
67 * Assignment operator
|
jpayne@69
|
68 * @stable ICU 3.0
|
jpayne@69
|
69 */
|
jpayne@69
|
70 Measure& operator=(const Measure& other);
|
jpayne@69
|
71
|
jpayne@69
|
72 /**
|
jpayne@69
|
73 * Return a polymorphic clone of this object. The result will
|
jpayne@69
|
74 * have the same class as returned by getDynamicClassID().
|
jpayne@69
|
75 * @stable ICU 3.0
|
jpayne@69
|
76 */
|
jpayne@69
|
77 virtual Measure* clone() const;
|
jpayne@69
|
78
|
jpayne@69
|
79 /**
|
jpayne@69
|
80 * Destructor
|
jpayne@69
|
81 * @stable ICU 3.0
|
jpayne@69
|
82 */
|
jpayne@69
|
83 virtual ~Measure();
|
jpayne@69
|
84
|
jpayne@69
|
85 /**
|
jpayne@69
|
86 * Equality operator. Return true if this object is equal
|
jpayne@69
|
87 * to the given object.
|
jpayne@69
|
88 * @stable ICU 3.0
|
jpayne@69
|
89 */
|
jpayne@69
|
90 UBool operator==(const UObject& other) const;
|
jpayne@69
|
91
|
jpayne@69
|
92 /**
|
jpayne@69
|
93 * Return a reference to the numeric value of this object. The
|
jpayne@69
|
94 * numeric value may be of any numeric type supported by
|
jpayne@69
|
95 * Formattable.
|
jpayne@69
|
96 * @stable ICU 3.0
|
jpayne@69
|
97 */
|
jpayne@69
|
98 inline const Formattable& getNumber() const;
|
jpayne@69
|
99
|
jpayne@69
|
100 /**
|
jpayne@69
|
101 * Return a reference to the unit of this object.
|
jpayne@69
|
102 * @stable ICU 3.0
|
jpayne@69
|
103 */
|
jpayne@69
|
104 inline const MeasureUnit& getUnit() const;
|
jpayne@69
|
105
|
jpayne@69
|
106 /**
|
jpayne@69
|
107 * Return the class ID for this class. This is useful only for comparing to
|
jpayne@69
|
108 * a return value from getDynamicClassID(). For example:
|
jpayne@69
|
109 * <pre>
|
jpayne@69
|
110 * . Base* polymorphic_pointer = createPolymorphicObject();
|
jpayne@69
|
111 * . if (polymorphic_pointer->getDynamicClassID() ==
|
jpayne@69
|
112 * . erived::getStaticClassID()) ...
|
jpayne@69
|
113 * </pre>
|
jpayne@69
|
114 * @return The class ID for all objects of this class.
|
jpayne@69
|
115 * @stable ICU 53
|
jpayne@69
|
116 */
|
jpayne@69
|
117 static UClassID U_EXPORT2 getStaticClassID(void);
|
jpayne@69
|
118
|
jpayne@69
|
119 /**
|
jpayne@69
|
120 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
jpayne@69
|
121 * method is to implement a simple version of RTTI, since not all C++
|
jpayne@69
|
122 * compilers support genuine RTTI. Polymorphic operator==() and clone()
|
jpayne@69
|
123 * methods call this method.
|
jpayne@69
|
124 *
|
jpayne@69
|
125 * @return The class ID for this object. All objects of a
|
jpayne@69
|
126 * given class have the same class ID. Objects of
|
jpayne@69
|
127 * other classes have different class IDs.
|
jpayne@69
|
128 * @stable ICU 53
|
jpayne@69
|
129 */
|
jpayne@69
|
130 virtual UClassID getDynamicClassID(void) const;
|
jpayne@69
|
131
|
jpayne@69
|
132 protected:
|
jpayne@69
|
133 /**
|
jpayne@69
|
134 * Default constructor.
|
jpayne@69
|
135 * @stable ICU 3.0
|
jpayne@69
|
136 */
|
jpayne@69
|
137 Measure();
|
jpayne@69
|
138
|
jpayne@69
|
139 private:
|
jpayne@69
|
140 /**
|
jpayne@69
|
141 * The numeric value of this object, e.g. 2.54 or 100.
|
jpayne@69
|
142 */
|
jpayne@69
|
143 Formattable number;
|
jpayne@69
|
144
|
jpayne@69
|
145 /**
|
jpayne@69
|
146 * The unit of this object, e.g., "millimeter" or "JPY". This is
|
jpayne@69
|
147 * owned by this object.
|
jpayne@69
|
148 */
|
jpayne@69
|
149 MeasureUnit* unit;
|
jpayne@69
|
150 };
|
jpayne@69
|
151
|
jpayne@69
|
152 inline const Formattable& Measure::getNumber() const {
|
jpayne@69
|
153 return number;
|
jpayne@69
|
154 }
|
jpayne@69
|
155
|
jpayne@69
|
156 inline const MeasureUnit& Measure::getUnit() const {
|
jpayne@69
|
157 return *unit;
|
jpayne@69
|
158 }
|
jpayne@69
|
159
|
jpayne@69
|
160 U_NAMESPACE_END
|
jpayne@69
|
161
|
jpayne@69
|
162 #endif // !UCONFIG_NO_FORMATTING
|
jpayne@69
|
163
|
jpayne@69
|
164 #endif /* U_SHOW_CPLUSPLUS_API */
|
jpayne@69
|
165
|
jpayne@69
|
166 #endif // __MEASURE_H__
|