]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/measure.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (c) 2004-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
9 * Created: April 26, 2004
11 **********************************************************************
16 #include "unicode/utypes.h"
20 * \brief C++ API: MeasureUnit object.
23 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/fmtable.h"
27 #if U_SHOW_CPLUSPLUS_API
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.
37 * <p>Measure objects are formatted by MeasureFormat.
39 * <p>Measure objects are immutable.
44 class U_I18N_API Measure
: public UObject
{
47 * Construct an object with the given numeric amount and the given
48 * unit. After this call, the caller must not delete the given
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.
56 Measure(const Formattable
& number
, MeasureUnit
* adoptedUnit
,
63 Measure(const Measure
& other
);
69 Measure
& operator=(const Measure
& other
);
72 * Return a polymorphic clone of this object. The result will
73 * have the same class as returned by getDynamicClassID().
76 virtual UObject
* clone() const;
85 * Equality operator. Return true if this object is equal
86 * to the given object.
89 UBool
operator==(const UObject
& other
) const;
92 * Return a reference to the numeric value of this object. The
93 * numeric value may be of any numeric type supported by
97 inline const Formattable
& getNumber() const;
100 * Return a reference to the unit of this object.
103 inline const MeasureUnit
& getUnit() const;
106 * Return the class ID for this class. This is useful only for comparing to
107 * a return value from getDynamicClassID(). For example:
109 * . Base* polymorphic_pointer = createPolymorphicObject();
110 * . if (polymorphic_pointer->getDynamicClassID() ==
111 * . erived::getStaticClassID()) ...
113 * @return The class ID for all objects of this class.
116 static UClassID U_EXPORT2
getStaticClassID(void);
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.
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.
129 virtual UClassID
getDynamicClassID(void) const;
133 * Default constructor.
140 * The numeric value of this object, e.g. 2.54 or 100.
145 * The unit of this object, e.g., "millimeter" or "JPY". This is
146 * owned by this object.
151 inline const Formattable
& Measure::getNumber() const {
155 inline const MeasureUnit
& Measure::getUnit() const {
160 #endif // U_SHOW_CPLUSPLUS_API
162 #endif // !UCONFIG_NO_FORMATTING
163 #endif // __MEASURE_H__