ICU 67.1  67.1
measfmt.h
Go to the documentation of this file.
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-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 * Author: Alan Liu
9 * Created: April 20, 2004
10 * Since: ICU 3.0
11 **********************************************************************
12 */
13 #ifndef MEASUREFORMAT_H
14 #define MEASUREFORMAT_H
15 
16 #include "unicode/utypes.h"
17 
18 #if U_SHOW_CPLUSPLUS_API
19 
20 #if !UCONFIG_NO_FORMATTING
21 
22 #include "unicode/format.h"
23 #include "unicode/udat.h"
24 
39 
40  // Wide, short, and narrow must be first and in this order.
46 
52 
58 
65 
66 #ifndef U_HIDE_DEPRECATED_API
67 
72 #endif // U_HIDE_DEPRECATED_API
73 };
76 
77 U_NAMESPACE_BEGIN
78 
79 class Measure;
80 class MeasureUnit;
81 class NumberFormat;
82 class PluralRules;
83 class MeasureFormatCacheData;
84 class SharedNumberFormat;
85 class SharedPluralRules;
86 class QuantityFormatter;
87 class SimpleFormatter;
88 class ListFormatter;
89 class DateFormat;
90 
101  public:
102  using Format::parseObject;
103  using Format::format;
104 
113  const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
114 
123  const Locale &locale,
124  UMeasureFormatWidth width,
125  NumberFormat *nfToAdopt,
126  UErrorCode &status);
127 
133 
139 
144  virtual ~MeasureFormat();
145 
150  virtual UBool operator==(const Format &other) const;
151 
156  virtual MeasureFormat *clone() const;
157 
163  const Formattable &obj,
164  UnicodeString &appendTo,
165  FieldPosition &pos,
166  UErrorCode &status) const;
167 
168 #ifndef U_FORCE_HIDE_DRAFT_API
169 
175  virtual void parseObject(
176  const UnicodeString &source,
177  Formattable &reslt,
178  ParsePosition &pos) const;
179 #endif // U_FORCE_HIDE_DRAFT_API
180 
198  const Measure *measures,
199  int32_t measureCount,
200  UnicodeString &appendTo,
201  FieldPosition &pos,
202  UErrorCode &status) const;
203 
218  const Measure &measure,
219  const MeasureUnit &perUnit,
220  UnicodeString &appendTo,
221  FieldPosition &pos,
222  UErrorCode &status) const;
223 
236 
237 
249  static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
250  UErrorCode& ec);
251 
263 
275  static UClassID U_EXPORT2 getStaticClassID(void);
276 
288  virtual UClassID getDynamicClassID(void) const;
289 
290  protected:
296 
297 #ifndef U_HIDE_INTERNAL_API
298 
305  const Locale &locale,
306  UMeasureFormatWidth width,
307  NumberFormat *nfToAdopt,
308  UErrorCode &status);
317 
323  void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
324 
330 
337 
342  const PluralRules &getPluralRules() const;
343 
348  Locale getLocale(UErrorCode &status) const;
349 
354  const char *getLocaleID(UErrorCode &status) const;
355 
356 #endif /* U_HIDE_INTERNAL_API */
357 
358  private:
359  const MeasureFormatCacheData *cache;
360  const SharedNumberFormat *numberFormat;
361  const SharedPluralRules *pluralRules;
362  UMeasureFormatWidth fWidth;
363 
364  // Declared outside of MeasureFormatSharedData because ListFormatter
365  // objects are relatively cheap to copy; therefore, they don't need to be
366  // shared across instances.
367  ListFormatter *listFormatter;
368 
369  UnicodeString &formatMeasure(
370  const Measure &measure,
371  const NumberFormat &nf,
372  UnicodeString &appendTo,
373  FieldPosition &pos,
374  UErrorCode &status) const;
375 
376  UnicodeString &formatMeasuresSlowTrack(
377  const Measure *measures,
378  int32_t measureCount,
379  UnicodeString& appendTo,
380  FieldPosition& pos,
381  UErrorCode& status) const;
382 
383  UnicodeString &formatNumeric(
384  const Formattable *hms, // always length 3: [0] is hour; [1] is
385  // minute; [2] is second.
386  int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
387  UnicodeString &appendTo,
388  UErrorCode &status) const;
389 };
390 
391 U_NAMESPACE_END
392 
393 #endif // #if !UCONFIG_NO_FORMATTING
394 
395 #endif /* U_SHOW_CPLUSPLUS_API */
396 
397 #endif // #ifndef MEASUREFORMAT_H
icu::MeasureFormat::MeasureFormat
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, UErrorCode &status)
Constructor.
icu::MeasureFormat::MeasureFormat
MeasureFormat(const MeasureFormat &other)
Copy constructor.
icu::MeasureFormat::operator==
virtual UBool operator==(const Format &other) const
Return true if given Format objects are semantically equal.
icu::MeasureUnit
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:237
UMeasureFormatWidth
UMeasureFormatWidth
Constants for various widths.
Definition: measfmt.h:38
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
icu::MeasureFormat::MeasureFormat
MeasureFormat()
Default constructor.
icu::MeasureFormat::MeasureFormat
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
Constructor.
icu::MeasureFormat::getPluralRules
const PluralRules & getPluralRules() const
ICU use only.
icu::NumberFormat
Definition: numfmt.h:175
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UMEASFMT_WIDTH_NUMERIC
@ UMEASFMT_WIDTH_NUMERIC
Completely omit measure units when possible.
Definition: measfmt.h:64
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
icu::MeasureFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
icu::MeasureFormat::adoptNumberFormat
void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
format.h
C++ API: Base class for all formats.
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:200
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::MeasureFormat::getStaticClassID
static UClassID getStaticClassID(void)
Return the class ID for this class.
icu::Format
Base class for all formats.
Definition: format.h:98
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::MeasureFormat::getCurrencyFormatInternal
const NumberFormat & getCurrencyFormatInternal() const
ICU use only.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
UMEASFMT_WIDTH_COUNT
@ UMEASFMT_WIDTH_COUNT
One more than the highest normal UMeasureFormatWidth value.
Definition: measfmt.h:71
UMEASFMT_WIDTH_NARROW
@ UMEASFMT_WIDTH_NARROW
Use symbols for measure units when possible.
Definition: measfmt.h:57
icu::MeasureFormat::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const
Parse a string to produce an object.
icu::MeasureFormat::getLocaleID
const char * getLocaleID(UErrorCode &status) const
ICU use only.
icu::MeasureFormat::createCurrencyFormat
static MeasureFormat * createCurrencyFormat(const Locale &locale, UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the given locale.
icu::Measure
An amount of a specified unit, consisting of a number and a Unit.
Definition: measure.h:45
UMEASFMT_WIDTH_WIDE
@ UMEASFMT_WIDTH_WIDE
Spell out measure units.
Definition: measfmt.h:45
icu::MeasureFormat::createCurrencyFormat
static MeasureFormat * createCurrencyFormat(UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the default locale.
icu::MeasureFormat::format
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats object to produce a string.
icu::MeasureFormat
Definition: measfmt.h:100
icu::MeasureFormat::setMeasureFormatLocale
UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status)
ICU use only.
icu::MeasureFormat::~MeasureFormat
virtual ~MeasureFormat()
Destructor.
icu::MeasureFormat::getUnitDisplayName
UnicodeString getUnitDisplayName(const MeasureUnit &unit, UErrorCode &status) const
Gets the display name of the specified MeasureUnit corresponding to the current locale and format wid...
UMEASFMT_WIDTH_SHORT
@ UMEASFMT_WIDTH_SHORT
Abbreviate measure units.
Definition: measfmt.h:51
icu::MeasureFormat::initMeasureFormat
void initMeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
icu::MeasureFormat::operator=
MeasureFormat & operator=(const MeasureFormat &rhs)
Assignment operator.
icu::ListFormatter
An immutable class for formatting a list, using data from CLDR (or supplied separately).
Definition: listformatter.h:151
icu::MeasureFormat::clone
virtual MeasureFormat * clone() const
Clones this object polymorphically.
icu::MeasureFormat::getLocale
Locale getLocale(UErrorCode &status) const
ICU use only.
icu::MeasureFormat::getNumberFormatInternal
const NumberFormat & getNumberFormatInternal() const
ICU use only.
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
udat.h
C API: DateFormat.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::MeasureFormat::formatMeasurePerUnit
UnicodeString & formatMeasurePerUnit(const Measure &measure, const MeasureUnit &perUnit, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a single measure per unit.
icu::MeasureFormat::formatMeasures
UnicodeString & formatMeasures(const Measure *measures, int32_t measureCount, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats measure objects to produce a string.