jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ********************************************************************** jpayne@69: * Copyright (c) 2004-2015, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ********************************************************************** jpayne@69: * Author: Alan Liu jpayne@69: * Created: April 26, 2004 jpayne@69: * Since: ICU 3.0 jpayne@69: ********************************************************************** jpayne@69: */ jpayne@69: #ifndef __MEASURE_H__ jpayne@69: #define __MEASURE_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: MeasureUnit object. jpayne@69: */ jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/fmtable.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class MeasureUnit; jpayne@69: jpayne@69: /** jpayne@69: * An amount of a specified unit, consisting of a number and a Unit. jpayne@69: * For example, a length measure consists of a number and a length jpayne@69: * unit, such as feet or meters. jpayne@69: * jpayne@69: *

Measure objects are formatted by MeasureFormat. jpayne@69: * jpayne@69: *

Measure objects are immutable. jpayne@69: * jpayne@69: * @author Alan Liu jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: class U_I18N_API Measure: public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * Construct an object with the given numeric amount and the given jpayne@69: * unit. After this call, the caller must not delete the given jpayne@69: * unit object. jpayne@69: * @param number a numeric object; amount.isNumeric() must be TRUE jpayne@69: * @param adoptedUnit the unit object, which must not be NULL jpayne@69: * @param ec input-output error code. If the amount or the unit jpayne@69: * is invalid, then this will be set to a failing value. jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: Measure(const Formattable& number, MeasureUnit* adoptedUnit, jpayne@69: UErrorCode& ec); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: Measure(const Measure& other); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: Measure& operator=(const Measure& other); jpayne@69: jpayne@69: /** jpayne@69: * Return a polymorphic clone of this object. The result will jpayne@69: * have the same class as returned by getDynamicClassID(). jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: virtual Measure* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Destructor jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: virtual ~Measure(); jpayne@69: jpayne@69: /** jpayne@69: * Equality operator. Return true if this object is equal jpayne@69: * to the given object. jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: UBool operator==(const UObject& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Return a reference to the numeric value of this object. The jpayne@69: * numeric value may be of any numeric type supported by jpayne@69: * Formattable. jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: inline const Formattable& getNumber() const; jpayne@69: jpayne@69: /** jpayne@69: * Return a reference to the unit of this object. jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: inline const MeasureUnit& getUnit() const; jpayne@69: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for comparing to jpayne@69: * a return value from getDynamicClassID(). For example: jpayne@69: *

jpayne@69:      * .   Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * .   if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      * .       erived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 53 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This jpayne@69: * method is to implement a simple version of RTTI, since not all C++ jpayne@69: * compilers support genuine RTTI. Polymorphic operator==() and clone() jpayne@69: * methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @stable ICU 53 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: jpayne@69: protected: jpayne@69: /** jpayne@69: * Default constructor. jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: Measure(); jpayne@69: jpayne@69: private: jpayne@69: /** jpayne@69: * The numeric value of this object, e.g. 2.54 or 100. jpayne@69: */ jpayne@69: Formattable number; jpayne@69: jpayne@69: /** jpayne@69: * The unit of this object, e.g., "millimeter" or "JPY". This is jpayne@69: * owned by this object. jpayne@69: */ jpayne@69: MeasureUnit* unit; jpayne@69: }; jpayne@69: jpayne@69: inline const Formattable& Measure::getNumber() const { jpayne@69: return number; jpayne@69: } jpayne@69: jpayne@69: inline const MeasureUnit& Measure::getUnit() const { jpayne@69: return *unit; jpayne@69: } jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif // !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // __MEASURE_H__