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