2 **********************************************************************
3 * Copyright (c) 2004-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * Created: April 26, 2004
9 **********************************************************************
14 #include "unicode/utypes.h"
18 * \brief C++ API: MeasureUnit object.
21 #if !UCONFIG_NO_FORMATTING
23 #include "unicode/fmtable.h"
30 * An amount of a specified unit, consisting of a number and a Unit.
31 * For example, a length measure consists of a number and a length
32 * unit, such as feet or meters.
34 * <p>Measure objects are formatted by MeasureFormat.
36 * <p>Measure objects are immutable.
41 class U_I18N_API Measure: public UObject {
44 * Construct an object with the given numeric amount and the given
45 * unit. After this call, the caller must not delete the given
47 * @param number a numeric object; amount.isNumeric() must be TRUE
48 * @param adoptedUnit the unit object, which must not be NULL
49 * @param ec input-output error code. If the amount or the unit
50 * is invalid, then this will be set to a failing value.
53 Measure(const Formattable& number, MeasureUnit* adoptedUnit,
60 Measure(const Measure& other);
66 Measure& operator=(const Measure& other);
69 * Return a polymorphic clone of this object. The result will
70 * have the same class as returned by getDynamicClassID().
73 virtual UObject* clone() const;
82 * Equality operator. Return true if this object is equal
83 * to the given object.
86 UBool operator==(const UObject& other) const;
89 * Return a reference to the numeric value of this object. The
90 * numeric value may be of any numeric type supported by
94 inline const Formattable& getNumber() const;
97 * Return a reference to the unit of this object.
100 inline const MeasureUnit& getUnit() const;
103 * Return the class ID for this class. This is useful only for comparing to
104 * a return value from getDynamicClassID(). For example:
106 * . Base* polymorphic_pointer = createPolymorphicObject();
107 * . if (polymorphic_pointer->getDynamicClassID() ==
108 * . erived::getStaticClassID()) ...
110 * @return The class ID for all objects of this class.
113 static UClassID U_EXPORT2 getStaticClassID(void);
116 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
117 * method is to implement a simple version of RTTI, since not all C++
118 * compilers support genuine RTTI. Polymorphic operator==() and clone()
119 * methods call this method.
121 * @return The class ID for this object. All objects of a
122 * given class have the same class ID. Objects of
123 * other classes have different class IDs.
126 virtual UClassID getDynamicClassID(void) const;
130 * Default constructor.
137 * The numeric value of this object, e.g. 2.54 or 100.
142 * The unit of this object, e.g., "millimeter" or "JPY". This is
143 * owned by this object.
148 inline const Formattable& Measure::getNumber() const {
152 inline const MeasureUnit& Measure::getUnit() const {
158 #endif // !UCONFIG_NO_FORMATTING
159 #endif // __MEASURE_H__