ICU 64.2  64.2
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 !UCONFIG_NO_FORMATTING
19 
20 #include "unicode/format.h"
21 #include "unicode/udat.h"
22 
37 
38  // Wide, short, and narrow must be first and in this order.
44 
50 
56 
63 
64 #ifndef U_HIDE_DEPRECATED_API
65 
70 #endif // U_HIDE_DEPRECATED_API
71 };
74 
76 
77 class Measure;
78 class MeasureUnit;
79 class NumberFormat;
80 class PluralRules;
81 class MeasureFormatCacheData;
82 class SharedNumberFormat;
83 class SharedPluralRules;
84 class QuantityFormatter;
85 class SimpleFormatter;
86 class ListFormatter;
87 class DateFormat;
88 
99  public:
100  using Format::parseObject;
101  using Format::format;
102 
111  const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
112 
121  const Locale &locale,
122  UMeasureFormatWidth width,
123  NumberFormat *nfToAdopt,
124  UErrorCode &status);
125 
130  MeasureFormat(const MeasureFormat &other);
131 
137 
142  virtual ~MeasureFormat();
143 
148  virtual UBool operator==(const Format &other) const;
149 
154  virtual Format *clone() const;
155 
160  virtual UnicodeString &format(
161  const Formattable &obj,
162  UnicodeString &appendTo,
163  FieldPosition &pos,
164  UErrorCode &status) const;
165 
172  virtual void parseObject(
173  const UnicodeString &source,
174  Formattable &reslt,
175  ParsePosition &pos) const;
176 
193  UnicodeString &formatMeasures(
194  const Measure *measures,
195  int32_t measureCount,
196  UnicodeString &appendTo,
197  FieldPosition &pos,
198  UErrorCode &status) const;
199 
213  UnicodeString &formatMeasurePerUnit(
214  const Measure &measure,
215  const MeasureUnit &perUnit,
216  UnicodeString &appendTo,
217  FieldPosition &pos,
218  UErrorCode &status) const;
219 
231  UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const;
232 
233 
245  static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
246  UErrorCode& ec);
247 
258  static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
259 
271  static UClassID U_EXPORT2 getStaticClassID(void);
272 
284  virtual UClassID getDynamicClassID(void) const;
285 
286  protected:
291  MeasureFormat();
292 
293 #ifndef U_HIDE_INTERNAL_API
294 
300  void initMeasureFormat(
301  const Locale &locale,
302  UMeasureFormatWidth width,
303  NumberFormat *nfToAdopt,
304  UErrorCode &status);
312  UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
313 
319  void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
320 
325  const NumberFormat &getNumberFormatInternal() const;
326 
332  const NumberFormat& getCurrencyFormatInternal() const;
333 
338  const PluralRules &getPluralRules() const;
339 
344  Locale getLocale(UErrorCode &status) const;
345 
350  const char *getLocaleID(UErrorCode &status) const;
351 
352 #endif /* U_HIDE_INTERNAL_API */
353 
354  private:
355  const MeasureFormatCacheData *cache;
356  const SharedNumberFormat *numberFormat;
357  const SharedPluralRules *pluralRules;
358  UMeasureFormatWidth fWidth;
359 
360  // Declared outside of MeasureFormatSharedData because ListFormatter
361  // objects are relatively cheap to copy; therefore, they don't need to be
362  // shared across instances.
363  ListFormatter *listFormatter;
364 
365  UnicodeString &formatMeasure(
366  const Measure &measure,
367  const NumberFormat &nf,
368  UnicodeString &appendTo,
369  FieldPosition &pos,
370  UErrorCode &status) const;
371 
372  UnicodeString &formatMeasuresSlowTrack(
373  const Measure *measures,
374  int32_t measureCount,
375  UnicodeString& appendTo,
376  FieldPosition& pos,
377  UErrorCode& status) const;
378 
379  UnicodeString &formatNumeric(
380  const Formattable *hms, // always length 3: [0] is hour; [1] is
381  // minute; [2] is second.
382  int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
383  UnicodeString &appendTo,
384  UErrorCode &status) const;
385 
386  UnicodeString &formatNumeric(
387  UDate date,
388  const DateFormat &dateFmt,
389  UDateFormatField smallestField,
390  const Formattable &smallestAmount,
391  UnicodeString &appendTo,
392  UErrorCode &status) const;
393 };
394 
396 
397 #endif // #if !UCONFIG_NO_FORMATTING
398 #endif // #ifndef MEASUREFORMAT_H
Base class for all formats.
Definition: format.h:96
const char * getLocaleID(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
UMeasureFormatWidth
Constants for various widths.
Definition: measfmt.h:36
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:38
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
One more than the highest normal UMeasureFormatWidth value.
Definition: measfmt.h:69
An amount of a specified unit, consisting of a number and a Unit.
Definition: measure.h:43
Use symbols for measure units when possible.
Definition: measfmt.h:55
double UDate
Date and Time data type.
Definition: utypes.h:203
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:93
virtual Format * clone() const =0
Clone this object polymorphically.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:198
C++ API: Base class for all formats.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
Spell out measure units.
Definition: measfmt.h:43
Abbreviate measure units.
Definition: measfmt.h:49
An immutable class for formatting a list, using data from CLDR (or supplied separately).
C API: DateFormat.
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
Completely omit measure units when possible.
Definition: measfmt.h:62
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:511
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:154
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Basic definitions for ICU, for both C and C++ APIs.
Format & operator=(const Format &)
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192