]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/measure.h
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / measure.h
CommitLineData
374ca955
A
1/*
2**********************************************************************
b331163b 3* Copyright (c) 2004-2015, International Business Machines
374ca955
A
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6* Author: Alan Liu
7* Created: April 26, 2004
8* Since: ICU 3.0
9**********************************************************************
10*/
11#ifndef __MEASURE_H__
12#define __MEASURE_H__
13
14#include "unicode/utypes.h"
15
73c04bcf
A
16/**
17 * \file
18 * \brief C++ API: MeasureUnit object.
19 */
20
374ca955
A
21#if !UCONFIG_NO_FORMATTING
22
23#include "unicode/fmtable.h"
24
25U_NAMESPACE_BEGIN
26
27class MeasureUnit;
28
29/**
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
57a6839d 32 * unit, such as feet or meters.
374ca955 33 *
57a6839d 34 * <p>Measure objects are formatted by MeasureFormat.
374ca955
A
35 *
36 * <p>Measure objects are immutable.
37 *
374ca955 38 * @author Alan Liu
73c04bcf 39 * @stable ICU 3.0
374ca955
A
40 */
41class U_I18N_API Measure: public UObject {
42 public:
43 /**
44 * Construct an object with the given numeric amount and the given
45 * unit. After this call, the caller must not delete the given
46 * unit object.
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.
73c04bcf 51 * @stable ICU 3.0
374ca955
A
52 */
53 Measure(const Formattable& number, MeasureUnit* adoptedUnit,
54 UErrorCode& ec);
55
56 /**
57 * Copy constructor
73c04bcf 58 * @stable ICU 3.0
374ca955
A
59 */
60 Measure(const Measure& other);
61
62 /**
63 * Assignment operator
73c04bcf 64 * @stable ICU 3.0
374ca955
A
65 */
66 Measure& operator=(const Measure& other);
67
68 /**
69 * Return a polymorphic clone of this object. The result will
70 * have the same class as returned by getDynamicClassID().
73c04bcf 71 * @stable ICU 3.0
374ca955 72 */
57a6839d 73 virtual UObject* clone() const;
374ca955
A
74
75 /**
76 * Destructor
73c04bcf 77 * @stable ICU 3.0
374ca955
A
78 */
79 virtual ~Measure();
80
81 /**
82 * Equality operator. Return true if this object is equal
83 * to the given object.
73c04bcf 84 * @stable ICU 3.0
374ca955
A
85 */
86 UBool operator==(const UObject& other) const;
87
88 /**
89 * Return a reference to the numeric value of this object. The
90 * numeric value may be of any numeric type supported by
91 * Formattable.
73c04bcf 92 * @stable ICU 3.0
374ca955
A
93 */
94 inline const Formattable& getNumber() const;
95
96 /**
97 * Return a reference to the unit of this object.
73c04bcf 98 * @stable ICU 3.0
374ca955
A
99 */
100 inline const MeasureUnit& getUnit() const;
101
57a6839d
A
102 /**
103 * Return the class ID for this class. This is useful only for comparing to
104 * a return value from getDynamicClassID(). For example:
105 * <pre>
106 * . Base* polymorphic_pointer = createPolymorphicObject();
107 * . if (polymorphic_pointer->getDynamicClassID() ==
108 * . erived::getStaticClassID()) ...
109 * </pre>
110 * @return The class ID for all objects of this class.
b331163b 111 * @stable ICU 53
57a6839d
A
112 */
113 static UClassID U_EXPORT2 getStaticClassID(void);
114
115 /**
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.
120 *
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.
b331163b 124 * @stable ICU 53
57a6839d
A
125 */
126 virtual UClassID getDynamicClassID(void) const;
127
374ca955
A
128 protected:
129 /**
130 * Default constructor.
73c04bcf 131 * @stable ICU 3.0
374ca955
A
132 */
133 Measure();
134
135 private:
136 /**
137 * The numeric value of this object, e.g. 2.54 or 100.
138 */
139 Formattable number;
140
141 /**
142 * The unit of this object, e.g., "millimeter" or "JPY". This is
143 * owned by this object.
144 */
145 MeasureUnit* unit;
146};
147
148inline const Formattable& Measure::getNumber() const {
149 return number;
150}
151
152inline const MeasureUnit& Measure::getUnit() const {
153 return *unit;
154}
155
156U_NAMESPACE_END
157
158#endif // !UCONFIG_NO_FORMATTING
159#endif // __MEASURE_H__