/work/obj-fuzz/dist/include/unicode/measure.h
Line | Count | Source (jump to first uncovered line) |
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 | | U_NAMESPACE_BEGIN |
28 | | |
29 | | class MeasureUnit; |
30 | | |
31 | | /** |
32 | | * An amount of a specified unit, consisting of a number and a Unit. |
33 | | * For example, a length measure consists of a number and a length |
34 | | * unit, such as feet or meters. |
35 | | * |
36 | | * <p>Measure objects are formatted by MeasureFormat. |
37 | | * |
38 | | * <p>Measure objects are immutable. |
39 | | * |
40 | | * @author Alan Liu |
41 | | * @stable ICU 3.0 |
42 | | */ |
43 | | class U_I18N_API Measure: public UObject { |
44 | | public: |
45 | | /** |
46 | | * Construct an object with the given numeric amount and the given |
47 | | * unit. After this call, the caller must not delete the given |
48 | | * unit object. |
49 | | * @param number a numeric object; amount.isNumeric() must be TRUE |
50 | | * @param adoptedUnit the unit object, which must not be NULL |
51 | | * @param ec input-output error code. If the amount or the unit |
52 | | * is invalid, then this will be set to a failing value. |
53 | | * @stable ICU 3.0 |
54 | | */ |
55 | | Measure(const Formattable& number, MeasureUnit* adoptedUnit, |
56 | | UErrorCode& ec); |
57 | | |
58 | | /** |
59 | | * Copy constructor |
60 | | * @stable ICU 3.0 |
61 | | */ |
62 | | Measure(const Measure& other); |
63 | | |
64 | | /** |
65 | | * Assignment operator |
66 | | * @stable ICU 3.0 |
67 | | */ |
68 | | Measure& operator=(const Measure& other); |
69 | | |
70 | | /** |
71 | | * Return a polymorphic clone of this object. The result will |
72 | | * have the same class as returned by getDynamicClassID(). |
73 | | * @stable ICU 3.0 |
74 | | */ |
75 | | virtual UObject* clone() const; |
76 | | |
77 | | /** |
78 | | * Destructor |
79 | | * @stable ICU 3.0 |
80 | | */ |
81 | | virtual ~Measure(); |
82 | | |
83 | | /** |
84 | | * Equality operator. Return true if this object is equal |
85 | | * to the given object. |
86 | | * @stable ICU 3.0 |
87 | | */ |
88 | | UBool operator==(const UObject& other) const; |
89 | | |
90 | | /** |
91 | | * Return a reference to the numeric value of this object. The |
92 | | * numeric value may be of any numeric type supported by |
93 | | * Formattable. |
94 | | * @stable ICU 3.0 |
95 | | */ |
96 | | inline const Formattable& getNumber() const; |
97 | | |
98 | | /** |
99 | | * Return a reference to the unit of this object. |
100 | | * @stable ICU 3.0 |
101 | | */ |
102 | | inline const MeasureUnit& getUnit() const; |
103 | | |
104 | | /** |
105 | | * Return the class ID for this class. This is useful only for comparing to |
106 | | * a return value from getDynamicClassID(). For example: |
107 | | * <pre> |
108 | | * . Base* polymorphic_pointer = createPolymorphicObject(); |
109 | | * . if (polymorphic_pointer->getDynamicClassID() == |
110 | | * . erived::getStaticClassID()) ... |
111 | | * </pre> |
112 | | * @return The class ID for all objects of this class. |
113 | | * @stable ICU 53 |
114 | | */ |
115 | | static UClassID U_EXPORT2 getStaticClassID(void); |
116 | | |
117 | | /** |
118 | | * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This |
119 | | * method is to implement a simple version of RTTI, since not all C++ |
120 | | * compilers support genuine RTTI. Polymorphic operator==() and clone() |
121 | | * methods call this method. |
122 | | * |
123 | | * @return The class ID for this object. All objects of a |
124 | | * given class have the same class ID. Objects of |
125 | | * other classes have different class IDs. |
126 | | * @stable ICU 53 |
127 | | */ |
128 | | virtual UClassID getDynamicClassID(void) const; |
129 | | |
130 | | protected: |
131 | | /** |
132 | | * Default constructor. |
133 | | * @stable ICU 3.0 |
134 | | */ |
135 | | Measure(); |
136 | | |
137 | | private: |
138 | | /** |
139 | | * The numeric value of this object, e.g. 2.54 or 100. |
140 | | */ |
141 | | Formattable number; |
142 | | |
143 | | /** |
144 | | * The unit of this object, e.g., "millimeter" or "JPY". This is |
145 | | * owned by this object. |
146 | | */ |
147 | | MeasureUnit* unit; |
148 | | }; |
149 | | |
150 | 0 | inline const Formattable& Measure::getNumber() const { |
151 | 0 | return number; |
152 | 0 | } |
153 | | |
154 | 0 | inline const MeasureUnit& Measure::getUnit() const { |
155 | 0 | return *unit; |
156 | 0 | } |
157 | | |
158 | | U_NAMESPACE_END |
159 | | |
160 | | #endif // !UCONFIG_NO_FORMATTING |
161 | | #endif // __MEASURE_H__ |