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