Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/measure.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 #ifndef U_HIDE_DRAFT_API
0093     /**
0094      * Inequality operator.  Returns true if this object is not equal to the other object.
0095      * @param other the object to compare with
0096      * @return true if the objects are not equal
0097      * @draft ICU 74
0098      */
0099     inline bool operator!=(const UObject& other) const { return !operator==(other); }
0100 #endif  // U_HIDE_DRAFT_API
0101 
0102     /**
0103      * Return a reference to the numeric value of this object.  The
0104      * numeric value may be of any numeric type supported by
0105      * Formattable.
0106      * @stable ICU 3.0
0107      */
0108     inline const Formattable& getNumber() const;
0109 
0110     /**
0111      * Return a reference to the unit of this object.
0112      * @stable ICU 3.0
0113      */
0114     inline const MeasureUnit& getUnit() const;
0115 
0116     /**
0117      * Return the class ID for this class. This is useful only for comparing to
0118      * a return value from getDynamicClassID(). For example:
0119      * <pre>
0120      * .   Base* polymorphic_pointer = createPolymorphicObject();
0121      * .   if (polymorphic_pointer->getDynamicClassID() ==
0122      * .       erived::getStaticClassID()) ...
0123      * </pre>
0124      * @return          The class ID for all objects of this class.
0125      * @stable ICU 53
0126      */
0127     static UClassID U_EXPORT2 getStaticClassID(void);
0128 
0129     /**
0130      * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
0131      * method is to implement a simple version of RTTI, since not all C++
0132      * compilers support genuine RTTI. Polymorphic operator==() and clone()
0133      * methods call this method.
0134      *
0135      * @return          The class ID for this object. All objects of a
0136      *                  given class have the same class ID.  Objects of
0137      *                  other classes have different class IDs.
0138      * @stable ICU 53
0139      */
0140     virtual UClassID getDynamicClassID(void) const override;
0141 
0142  protected:
0143     /**
0144      * Default constructor.
0145      * @stable ICU 3.0
0146      */
0147     Measure();
0148 
0149  private:
0150     /**
0151      * The numeric value of this object, e.g. 2.54 or 100.
0152      */
0153     Formattable number;
0154 
0155     /**
0156      * The unit of this object, e.g., "millimeter" or "JPY".  This is
0157      * owned by this object.
0158      */
0159     MeasureUnit* unit;
0160 };
0161 
0162 inline const Formattable& Measure::getNumber() const {
0163     return number;
0164 }
0165 
0166 inline const MeasureUnit& Measure::getUnit() const {
0167     return *unit;
0168 }
0169 
0170 U_NAMESPACE_END
0171 
0172 #endif // !UCONFIG_NO_FORMATTING
0173 
0174 #endif /* U_SHOW_CPLUSPLUS_API */
0175 
0176 #endif // __MEASURE_H__