ICU 73.2  73.2
measfmt.h
Go to the documentation of this file.
00001 // © 2016 and later: Unicode, Inc. and others.
00002 // License & terms of use: http://www.unicode.org/copyright.html
00003 /*
00004 **********************************************************************
00005 * Copyright (c) 2004-2016, International Business Machines
00006 * Corporation and others.  All Rights Reserved.
00007 **********************************************************************
00008 * Author: Alan Liu
00009 * Created: April 20, 2004
00010 * Since: ICU 3.0
00011 **********************************************************************
00012 */
00013 #ifndef MEASUREFORMAT_H
00014 #define MEASUREFORMAT_H
00015 
00016 #include "unicode/utypes.h"
00017 
00018 #if U_SHOW_CPLUSPLUS_API
00019 
00020 #if !UCONFIG_NO_FORMATTING
00021 
00022 #include "unicode/format.h"
00023 #include "unicode/udat.h"
00024 
00038 enum UMeasureFormatWidth {
00039 
00040     // Wide, short, and narrow must be first and in this order.
00045     UMEASFMT_WIDTH_WIDE,
00046  
00051     UMEASFMT_WIDTH_SHORT,
00052 
00057     UMEASFMT_WIDTH_NARROW,
00058 
00064     UMEASFMT_WIDTH_NUMERIC,
00065 
00066 #ifndef U_HIDE_DEPRECATED_API
00067 
00071     UMEASFMT_WIDTH_COUNT = 4
00072 #endif  // U_HIDE_DEPRECATED_API
00073 };
00075 typedef enum UMeasureFormatWidth UMeasureFormatWidth; 
00076 
00077 U_NAMESPACE_BEGIN
00078 
00079 class Measure;
00080 class MeasureUnit;
00081 class NumberFormat;
00082 class PluralRules;
00083 class MeasureFormatCacheData;
00084 class SharedNumberFormat;
00085 class SharedPluralRules;
00086 class QuantityFormatter;
00087 class SimpleFormatter;
00088 class ListFormatter;
00089 class DateFormat;
00090 
00101 class U_I18N_API MeasureFormat : public Format {
00102  public:
00103     using Format::parseObject;
00104     using Format::format;
00105 
00113     MeasureFormat(
00114             const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
00115 
00123     MeasureFormat(
00124             const Locale &locale,
00125             UMeasureFormatWidth width,
00126             NumberFormat *nfToAdopt,
00127             UErrorCode &status);
00128 
00133     MeasureFormat(const MeasureFormat &other);
00134 
00139     MeasureFormat &operator=(const MeasureFormat &rhs);
00140 
00145     virtual ~MeasureFormat();
00146 
00151     virtual bool operator==(const Format &other) const override;
00152 
00157     virtual MeasureFormat *clone() const override;
00158 
00163     virtual UnicodeString &format(
00164             const Formattable &obj,
00165             UnicodeString &appendTo,
00166             FieldPosition &pos,
00167             UErrorCode &status) const override;
00168 
00169 #ifndef U_FORCE_HIDE_DRAFT_API
00170 
00176     virtual void parseObject(
00177             const UnicodeString &source,
00178             Formattable &reslt,
00179             ParsePosition &pos) const override;
00180 #endif  // U_FORCE_HIDE_DRAFT_API
00181 
00198     UnicodeString &formatMeasures(
00199             const Measure *measures,
00200             int32_t measureCount,
00201             UnicodeString &appendTo,
00202             FieldPosition &pos,
00203             UErrorCode &status) const;
00204 
00218     UnicodeString &formatMeasurePerUnit(
00219             const Measure &measure,
00220             const MeasureUnit &perUnit,
00221             UnicodeString &appendTo,
00222             FieldPosition &pos,
00223             UErrorCode &status) const;
00224 
00236     UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const;
00237 
00238 
00250     static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
00251                                                UErrorCode& ec);
00252 
00263     static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
00264 
00276     static UClassID U_EXPORT2 getStaticClassID(void);
00277 
00289     virtual UClassID getDynamicClassID(void) const override;
00290 
00291  protected:
00296     MeasureFormat();
00297 
00298 #ifndef U_HIDE_INTERNAL_API 
00299 
00305     void initMeasureFormat(
00306             const Locale &locale,
00307             UMeasureFormatWidth width,
00308             NumberFormat *nfToAdopt,
00309             UErrorCode &status);
00317     UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
00318 
00324     void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
00325 
00330     const NumberFormat &getNumberFormatInternal() const;
00331 
00337     const NumberFormat& getCurrencyFormatInternal() const;
00338 
00343     const PluralRules &getPluralRules() const;
00344 
00349     Locale getLocale(UErrorCode &status) const;
00350 
00355     const char *getLocaleID(UErrorCode &status) const;
00356 
00357 #endif /* U_HIDE_INTERNAL_API */
00358 
00359  private:
00360     const MeasureFormatCacheData *cache;
00361     const SharedNumberFormat *numberFormat;
00362     const SharedPluralRules *pluralRules;
00363     UMeasureFormatWidth fWidth;    
00364 
00365     // Declared outside of MeasureFormatSharedData because ListFormatter
00366     // objects are relatively cheap to copy; therefore, they don't need to be
00367     // shared across instances.
00368     ListFormatter *listFormatter;
00369 
00370     UnicodeString &formatMeasure(
00371         const Measure &measure,
00372         const NumberFormat &nf,
00373         UnicodeString &appendTo,
00374         FieldPosition &pos,
00375         UErrorCode &status) const;
00376 
00377     UnicodeString &formatMeasuresSlowTrack(
00378         const Measure *measures,
00379         int32_t measureCount,
00380         UnicodeString& appendTo,
00381         FieldPosition& pos,
00382         UErrorCode& status) const;
00383 
00384     UnicodeString &formatNumeric(
00385         const Formattable *hms,  // always length 3: [0] is hour; [1] is
00386                                  // minute; [2] is second.
00387         int32_t bitMap,   // 1=hour set, 2=minute set, 4=second set
00388         UnicodeString &appendTo,
00389         UErrorCode &status) const;
00390 };
00391 
00392 U_NAMESPACE_END
00393 
00394 #endif // #if !UCONFIG_NO_FORMATTING
00395 
00396 #endif /* U_SHOW_CPLUSPLUS_API */
00397 
00398 #endif // #ifndef MEASUREFORMAT_H