ICU 65.1  65.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 
132  MeasureFormat(const MeasureFormat &other);
133 
139 
144  virtual ~MeasureFormat();
145 
150  virtual UBool operator==(const Format &other) const;
151 
156  virtual MeasureFormat *clone() const;
157 
162  virtual UnicodeString &format(
163  const Formattable &obj,
164  UnicodeString &appendTo,
165  FieldPosition &pos,
166  UErrorCode &status) const;
167 
174  virtual void parseObject(
175  const UnicodeString &source,
176  Formattable &reslt,
177  ParsePosition &pos) const;
178 
195  UnicodeString &formatMeasures(
196  const Measure *measures,
197  int32_t measureCount,
198  UnicodeString &appendTo,
199  FieldPosition &pos,
200  UErrorCode &status) const;
201 
215  UnicodeString &formatMeasurePerUnit(
216  const Measure &measure,
217  const MeasureUnit &perUnit,
218  UnicodeString &appendTo,
219  FieldPosition &pos,
220  UErrorCode &status) const;
221 
233  UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const;
234 
235 
247  static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
248  UErrorCode& ec);
249 
260  static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
261 
273  static UClassID U_EXPORT2 getStaticClassID(void);
274 
286  virtual UClassID getDynamicClassID(void) const;
287 
288  protected:
293  MeasureFormat();
294 
295 #ifndef U_HIDE_INTERNAL_API
296 
302  void initMeasureFormat(
303  const Locale &locale,
304  UMeasureFormatWidth width,
305  NumberFormat *nfToAdopt,
306  UErrorCode &status);
314  UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
315 
321  void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
322 
327  const NumberFormat &getNumberFormatInternal() const;
328 
334  const NumberFormat& getCurrencyFormatInternal() const;
335 
340  const PluralRules &getPluralRules() const;
341 
346  Locale getLocale(UErrorCode &status) const;
347 
352  const char *getLocaleID(UErrorCode &status) const;
353 
354 #endif /* U_HIDE_INTERNAL_API */
355 
356  private:
357  const MeasureFormatCacheData *cache;
358  const SharedNumberFormat *numberFormat;
359  const SharedPluralRules *pluralRules;
360  UMeasureFormatWidth fWidth;
361 
362  // Declared outside of MeasureFormatSharedData because ListFormatter
363  // objects are relatively cheap to copy; therefore, they don't need to be
364  // shared across instances.
365  ListFormatter *listFormatter;
366 
367  UnicodeString &formatMeasure(
368  const Measure &measure,
369  const NumberFormat &nf,
370  UnicodeString &appendTo,
371  FieldPosition &pos,
372  UErrorCode &status) const;
373 
374  UnicodeString &formatMeasuresSlowTrack(
375  const Measure *measures,
376  int32_t measureCount,
377  UnicodeString& appendTo,
378  FieldPosition& pos,
379  UErrorCode& status) const;
380 
381  UnicodeString &formatNumeric(
382  const Formattable *hms, // always length 3: [0] is hour; [1] is
383  // minute; [2] is second.
384  int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
385  UnicodeString &appendTo,
386  UErrorCode &status) const;
387 };
388 
389 U_NAMESPACE_END
390 
391 #endif // #if !UCONFIG_NO_FORMATTING
392 
393 #endif /* U_SHOW_CPLUSPLUS_API */
394 
395 #endif // #ifndef MEASUREFORMAT_H
Base class for all formats.
Definition: format.h:98
const char * getLocaleID(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
UMeasureFormatWidth
Constants for various widths.
Definition: measfmt.h:38
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:40
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:71
An amount of a specified unit, consisting of a number and a Unit.
Definition: measure.h:45
Use symbols for measure units when possible.
Definition: measfmt.h:57
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
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:200
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
Spell out measure units.
Definition: measfmt.h:45
Abbreviate measure units.
Definition: measfmt.h:51
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:64
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
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:294
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:260
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195