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