|
|
|||
File indexing completed on 2026-03-30 08:32:22
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ********************************************************************** 0005 * Copyright (c) 2004-2015, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ********************************************************************** 0008 * Author: Alan Liu 0009 * Created: April 26, 2004 0010 * Since: ICU 3.0 0011 ********************************************************************** 0012 */ 0013 #ifndef __MEASURE_H__ 0014 #define __MEASURE_H__ 0015 0016 #include "unicode/utypes.h" 0017 0018 #if U_SHOW_CPLUSPLUS_API 0019 0020 /** 0021 * \file 0022 * \brief C++ API: MeasureUnit object. 0023 */ 0024 0025 #if !UCONFIG_NO_FORMATTING 0026 0027 #include "unicode/fmtable.h" 0028 0029 U_NAMESPACE_BEGIN 0030 0031 class MeasureUnit; 0032 0033 /** 0034 * An amount of a specified unit, consisting of a number and a Unit. 0035 * For example, a length measure consists of a number and a length 0036 * unit, such as feet or meters. 0037 * 0038 * <p>Measure objects are formatted by MeasureFormat. 0039 * 0040 * <p>Measure objects are immutable. 0041 * 0042 * @author Alan Liu 0043 * @stable ICU 3.0 0044 */ 0045 class U_I18N_API Measure: public UObject { 0046 public: 0047 /** 0048 * Construct an object with the given numeric amount and the given 0049 * unit. After this call, the caller must not delete the given 0050 * unit object. 0051 * @param number a numeric object; amount.isNumeric() must be true 0052 * @param adoptedUnit the unit object, which must not be nullptr 0053 * @param ec input-output error code. If the amount or the unit 0054 * is invalid, then this will be set to a failing value. 0055 * @stable ICU 3.0 0056 */ 0057 Measure(const Formattable& number, MeasureUnit* adoptedUnit, 0058 UErrorCode& ec); 0059 0060 /** 0061 * Copy constructor 0062 * @stable ICU 3.0 0063 */ 0064 Measure(const Measure& other); 0065 0066 /** 0067 * Assignment operator 0068 * @stable ICU 3.0 0069 */ 0070 Measure& operator=(const Measure& other); 0071 0072 /** 0073 * Return a polymorphic clone of this object. The result will 0074 * have the same class as returned by getDynamicClassID(). 0075 * @stable ICU 3.0 0076 */ 0077 virtual Measure* clone() const; 0078 0079 /** 0080 * Destructor 0081 * @stable ICU 3.0 0082 */ 0083 virtual ~Measure(); 0084 0085 /** 0086 * Equality operator. Return true if this object is equal 0087 * to the given object. 0088 * @stable ICU 3.0 0089 */ 0090 bool operator==(const UObject& other) const; 0091 0092 /** 0093 * Inequality operator. Returns true if this object is not equal to the other object. 0094 * @param other the object to compare with 0095 * @return true if the objects are not equal 0096 * @stable ICU 74 0097 */ 0098 inline bool operator!=(const UObject& other) const { return !operator==(other); } 0099 0100 /** 0101 * Return a reference to the numeric value of this object. The 0102 * numeric value may be of any numeric type supported by 0103 * Formattable. 0104 * @stable ICU 3.0 0105 */ 0106 inline const Formattable& getNumber() const; 0107 0108 /** 0109 * Return a reference to the unit of this object. 0110 * @stable ICU 3.0 0111 */ 0112 inline const MeasureUnit& getUnit() const; 0113 0114 /** 0115 * Return the class ID for this class. This is useful only for comparing to 0116 * a return value from getDynamicClassID(). For example: 0117 * <pre> 0118 * . Base* polymorphic_pointer = createPolymorphicObject(); 0119 * . if (polymorphic_pointer->getDynamicClassID() == 0120 * . erived::getStaticClassID()) ... 0121 * </pre> 0122 * @return The class ID for all objects of this class. 0123 * @stable ICU 53 0124 */ 0125 static UClassID U_EXPORT2 getStaticClassID(); 0126 0127 /** 0128 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This 0129 * method is to implement a simple version of RTTI, since not all C++ 0130 * compilers support genuine RTTI. Polymorphic operator==() and clone() 0131 * methods call this method. 0132 * 0133 * @return The class ID for this object. All objects of a 0134 * given class have the same class ID. Objects of 0135 * other classes have different class IDs. 0136 * @stable ICU 53 0137 */ 0138 virtual UClassID getDynamicClassID() const override; 0139 0140 protected: 0141 /** 0142 * Default constructor. 0143 * @stable ICU 3.0 0144 */ 0145 Measure(); 0146 0147 private: 0148 /** 0149 * The numeric value of this object, e.g. 2.54 or 100. 0150 */ 0151 Formattable number; 0152 0153 /** 0154 * The unit of this object, e.g., "millimeter" or "JPY". This is 0155 * owned by this object. 0156 */ 0157 MeasureUnit* unit; 0158 }; 0159 0160 inline const Formattable& Measure::getNumber() const { 0161 return number; 0162 } 0163 0164 inline const MeasureUnit& Measure::getUnit() const { 0165 return *unit; 0166 } 0167 0168 U_NAMESPACE_END 0169 0170 #endif // !UCONFIG_NO_FORMATTING 0171 0172 #endif /* U_SHOW_CPLUSPLUS_API */ 0173 0174 #endif // __MEASURE_H__
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|