]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/measure.h
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / measure.h
CommitLineData
374ca955
A
1/*
2**********************************************************************
3* Copyright (c) 2004, International Business Machines
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
16#if !UCONFIG_NO_FORMATTING
17
18#include "unicode/fmtable.h"
19
20U_NAMESPACE_BEGIN
21
22class MeasureUnit;
23
24/**
25 * An amount of a specified unit, consisting of a number and a Unit.
26 * For example, a length measure consists of a number and a length
27 * unit, such as feet or meters. This is an abstract class.
28 * Subclasses specify a concrete Unit type.
29 *
30 * <p>Measure objects are parsed and formatted by subclasses of
31 * MeasureFormat.
32 *
33 * <p>Measure objects are immutable.
34 *
35 * <p>This is an abstract class.
36 *
37 * @author Alan Liu
38 * @draft ICU 3.0
39 */
40class U_I18N_API Measure: public UObject {
41 public:
42 /**
43 * Construct an object with the given numeric amount and the given
44 * unit. After this call, the caller must not delete the given
45 * unit object.
46 * @param number a numeric object; amount.isNumeric() must be TRUE
47 * @param adoptedUnit the unit object, which must not be NULL
48 * @param ec input-output error code. If the amount or the unit
49 * is invalid, then this will be set to a failing value.
50 * @draft ICU 3.0
51 */
52 Measure(const Formattable& number, MeasureUnit* adoptedUnit,
53 UErrorCode& ec);
54
55 /**
56 * Copy constructor
57 * @draft ICU 3.0
58 */
59 Measure(const Measure& other);
60
61 /**
62 * Assignment operator
63 * @draft ICU 3.0
64 */
65 Measure& operator=(const Measure& other);
66
67 /**
68 * Return a polymorphic clone of this object. The result will
69 * have the same class as returned by getDynamicClassID().
70 * @draft ICU 3.0
71 */
72 virtual UObject* clone() const = 0;
73
74 /**
75 * Destructor
76 * @draft ICU 3.0
77 */
78 virtual ~Measure();
79
80 /**
81 * Equality operator. Return true if this object is equal
82 * to the given object.
83 * @draft ICU 3.0
84 */
85 UBool operator==(const UObject& other) const;
86
87 /**
88 * Return a reference to the numeric value of this object. The
89 * numeric value may be of any numeric type supported by
90 * Formattable.
91 * @draft ICU 3.0
92 */
93 inline const Formattable& getNumber() const;
94
95 /**
96 * Return a reference to the unit of this object.
97 * @draft ICU 3.0
98 */
99 inline const MeasureUnit& getUnit() const;
100
101 protected:
102 /**
103 * Default constructor.
104 * @draft ICU 3.0
105 */
106 Measure();
107
108 private:
109 /**
110 * The numeric value of this object, e.g. 2.54 or 100.
111 */
112 Formattable number;
113
114 /**
115 * The unit of this object, e.g., "millimeter" or "JPY". This is
116 * owned by this object.
117 */
118 MeasureUnit* unit;
119};
120
121inline const Formattable& Measure::getNumber() const {
122 return number;
123}
124
125inline const MeasureUnit& Measure::getUnit() const {
126 return *unit;
127}
128
129U_NAMESPACE_END
130
131#endif // !UCONFIG_NO_FORMATTING
132#endif // __MEASURE_H__