tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

measure.h (4738B)


      1 // © 2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /*
      4 **********************************************************************
      5 * Copyright (c) 2004-2015, International Business Machines
      6 * Corporation and others.  All Rights Reserved.
      7 **********************************************************************
      8 * Author: Alan Liu
      9 * Created: April 26, 2004
     10 * Since: ICU 3.0
     11 **********************************************************************
     12 */
     13 #ifndef __MEASURE_H__
     14 #define __MEASURE_H__
     15 
     16 #include "unicode/utypes.h"
     17 
     18 #if U_SHOW_CPLUSPLUS_API
     19 
     20 /**
     21 * \file 
     22 * \brief C++ API: MeasureUnit object.
     23 */
     24 
     25 #if !UCONFIG_NO_FORMATTING
     26 
     27 #include "unicode/fmtable.h"
     28 
     29 U_NAMESPACE_BEGIN
     30 
     31 class MeasureUnit;
     32 
     33 /**
     34 * An amount of a specified unit, consisting of a number and a Unit.
     35 * For example, a length measure consists of a number and a length
     36 * unit, such as feet or meters.
     37 *
     38 * <p>Measure objects are formatted by MeasureFormat.
     39 *
     40 * <p>Measure objects are immutable.
     41 *
     42 * @author Alan Liu
     43 * @stable ICU 3.0
     44 */
     45 class U_I18N_API Measure: public UObject {
     46 public:
     47    /**
     48     * Construct an object with the given numeric amount and the given
     49     * unit.  After this call, the caller must not delete the given
     50     * unit object.
     51     * @param number a numeric object; amount.isNumeric() must be true
     52     * @param adoptedUnit the unit object, which must not be nullptr
     53     * @param ec input-output error code. If the amount or the unit
     54     * is invalid, then this will be set to a failing value.
     55     * @stable ICU 3.0
     56     */
     57    Measure(const Formattable& number, MeasureUnit* adoptedUnit,
     58            UErrorCode& ec);
     59 
     60    /**
     61     * Copy constructor
     62     * @stable ICU 3.0
     63     */
     64    Measure(const Measure& other);
     65 
     66    /**
     67     * Assignment operator
     68     * @stable ICU 3.0
     69     */
     70    Measure& operator=(const Measure& other);
     71 
     72    /**
     73     * Return a polymorphic clone of this object.  The result will
     74     * have the same class as returned by getDynamicClassID().
     75     * @stable ICU 3.0
     76     */
     77    virtual Measure* clone() const;
     78 
     79    /**
     80     * Destructor
     81     * @stable ICU 3.0
     82     */
     83    virtual ~Measure();
     84    
     85    /**
     86     * Equality operator.  Return true if this object is equal
     87     * to the given object.
     88     * @stable ICU 3.0
     89     */
     90    bool operator==(const UObject& other) const;
     91 
     92    /**
     93     * Inequality operator.  Returns true if this object is not equal to the other object.
     94     * @param other the object to compare with
     95     * @return true if the objects are not equal
     96     * @stable ICU 74
     97     */
     98    inline bool operator!=(const UObject& other) const { return !operator==(other); }
     99 
    100    /**
    101     * Return a reference to the numeric value of this object.  The
    102     * numeric value may be of any numeric type supported by
    103     * Formattable.
    104     * @stable ICU 3.0
    105     */
    106    inline const Formattable& getNumber() const;
    107 
    108    /**
    109     * Return a reference to the unit of this object.
    110     * @stable ICU 3.0
    111     */
    112    inline const MeasureUnit& getUnit() const;
    113 
    114    /**
    115     * Return the class ID for this class. This is useful only for comparing to
    116     * a return value from getDynamicClassID(). For example:
    117     * <pre>
    118     * .   Base* polymorphic_pointer = createPolymorphicObject();
    119     * .   if (polymorphic_pointer->getDynamicClassID() ==
    120     * .       erived::getStaticClassID()) ...
    121     * </pre>
    122     * @return          The class ID for all objects of this class.
    123     * @stable ICU 53
    124     */
    125    static UClassID U_EXPORT2 getStaticClassID();
    126 
    127    /**
    128     * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
    129     * method is to implement a simple version of RTTI, since not all C++
    130     * compilers support genuine RTTI. Polymorphic operator==() and clone()
    131     * methods call this method.
    132     *
    133     * @return          The class ID for this object. All objects of a
    134     *                  given class have the same class ID.  Objects of
    135     *                  other classes have different class IDs.
    136     * @stable ICU 53
    137     */
    138    virtual UClassID getDynamicClassID() const override;
    139 
    140 protected:
    141    /**
    142     * Default constructor.
    143     * @stable ICU 3.0
    144     */
    145    Measure();
    146 
    147 private:
    148    /**
    149     * The numeric value of this object, e.g. 2.54 or 100.
    150     */
    151    Formattable number;
    152 
    153    /**
    154     * The unit of this object, e.g., "millimeter" or "JPY".  This is
    155     * owned by this object.
    156     */
    157    MeasureUnit* unit;
    158 };
    159 
    160 inline const Formattable& Measure::getNumber() const {
    161    return number;
    162 }
    163 
    164 inline const MeasureUnit& Measure::getUnit() const {
    165    return *unit;
    166 }
    167 
    168 U_NAMESPACE_END
    169 
    170 #endif // !UCONFIG_NO_FORMATTING
    171 
    172 #endif /* U_SHOW_CPLUSPLUS_API */
    173 
    174 #endif // __MEASURE_H__