michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (c) 2004-2006, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Author: Alan Liu michael@0: * Created: April 26, 2004 michael@0: * Since: ICU 3.0 michael@0: ********************************************************************** michael@0: */ michael@0: #ifndef __MEASURE_H__ michael@0: #define __MEASURE_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: MeasureUnit object. michael@0: */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/fmtable.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class MeasureUnit; michael@0: michael@0: /** michael@0: * An amount of a specified unit, consisting of a number and a Unit. michael@0: * For example, a length measure consists of a number and a length michael@0: * unit, such as feet or meters. This is an abstract class. michael@0: * Subclasses specify a concrete Unit type. michael@0: * michael@0: *
Measure objects are parsed and formatted by subclasses of michael@0: * MeasureFormat. michael@0: * michael@0: *
Measure objects are immutable. michael@0: * michael@0: *
This is an abstract class. michael@0: * michael@0: * @author Alan Liu michael@0: * @stable ICU 3.0 michael@0: */ michael@0: class U_I18N_API Measure: public UObject { michael@0: public: michael@0: /** michael@0: * Construct an object with the given numeric amount and the given michael@0: * unit. After this call, the caller must not delete the given michael@0: * unit object. michael@0: * @param number a numeric object; amount.isNumeric() must be TRUE michael@0: * @param adoptedUnit the unit object, which must not be NULL michael@0: * @param ec input-output error code. If the amount or the unit michael@0: * is invalid, then this will be set to a failing value. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: Measure(const Formattable& number, MeasureUnit* adoptedUnit, michael@0: UErrorCode& ec); michael@0: michael@0: /** michael@0: * Copy constructor michael@0: * @stable ICU 3.0 michael@0: */ michael@0: Measure(const Measure& other); michael@0: michael@0: /** michael@0: * Assignment operator michael@0: * @stable ICU 3.0 michael@0: */ michael@0: Measure& operator=(const Measure& other); michael@0: michael@0: /** michael@0: * Return a polymorphic clone of this object. The result will michael@0: * have the same class as returned by getDynamicClassID(). michael@0: * @stable ICU 3.0 michael@0: */ michael@0: virtual UObject* clone() const = 0; michael@0: michael@0: /** michael@0: * Destructor michael@0: * @stable ICU 3.0 michael@0: */ michael@0: virtual ~Measure(); michael@0: michael@0: /** michael@0: * Equality operator. Return true if this object is equal michael@0: * to the given object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UBool operator==(const UObject& other) const; michael@0: michael@0: /** michael@0: * Return a reference to the numeric value of this object. The michael@0: * numeric value may be of any numeric type supported by michael@0: * Formattable. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: inline const Formattable& getNumber() const; michael@0: michael@0: /** michael@0: * Return a reference to the unit of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: inline const MeasureUnit& getUnit() const; michael@0: michael@0: protected: michael@0: /** michael@0: * Default constructor. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: Measure(); michael@0: michael@0: private: michael@0: /** michael@0: * The numeric value of this object, e.g. 2.54 or 100. michael@0: */ michael@0: Formattable number; michael@0: michael@0: /** michael@0: * The unit of this object, e.g., "millimeter" or "JPY". This is michael@0: * owned by this object. michael@0: */ michael@0: MeasureUnit* unit; michael@0: }; michael@0: michael@0: inline const Formattable& Measure::getNumber() const { michael@0: return number; michael@0: } michael@0: michael@0: inline const MeasureUnit& Measure::getUnit() const { michael@0: return *unit; michael@0: } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif // !UCONFIG_NO_FORMATTING michael@0: #endif // __MEASURE_H__