ICU 54.1  54.1
measfmt.h
Go to the documentation of this file.
1 /*
2 **********************************************************************
3 * Copyright (c) 2004-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Author: Alan Liu
7 * Created: April 20, 2004
8 * Since: ICU 3.0
9 **********************************************************************
10 */
11 #ifndef MEASUREFORMAT_H
12 #define MEASUREFORMAT_H
13 
14 #include "unicode/utypes.h"
15 
16 #if !UCONFIG_NO_FORMATTING
17 
18 #include "unicode/format.h"
19 #include "unicode/udat.h"
20 
35 
36 #ifndef U_HIDE_DRAFT_API
37  // Wide, short, and narrow must be first and in this order.
43 
49 
55 
62 #endif /* U_HIDE_DRAFT_API */
63 
69 };
72 
74 
75 class Measure;
76 class MeasureUnit;
77 class NumberFormat;
78 class PluralRules;
79 class MeasureFormatCacheData;
80 class SharedNumberFormat;
81 class SharedPluralRules;
82 class QuantityFormatter;
83 class SimplePatternFormatter;
84 class ListFormatter;
85 class DateFormat;
86 
96  public:
97  using Format::parseObject;
98  using Format::format;
99 
100 #ifndef U_HIDE_DRAFT_API
101 
106  const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
107 
113  const Locale &locale,
114  UMeasureFormatWidth width,
115  NumberFormat *nfToAdopt,
116  UErrorCode &status);
117 #endif /* U_HIDE_DRAFT_API */
118 
123  MeasureFormat(const MeasureFormat &other);
124 
130 
135  virtual ~MeasureFormat();
136 
141  virtual UBool operator==(const Format &other) const;
142 
147  virtual Format *clone() const;
148 
153  virtual UnicodeString &format(
154  const Formattable &obj,
155  UnicodeString &appendTo,
156  FieldPosition &pos,
157  UErrorCode &status) const;
158 
165  virtual void parseObject(
166  const UnicodeString &source,
167  Formattable &reslt,
168  ParsePosition &pos) const;
169 
170 #ifndef U_HIDE_DRAFT_API
171 
187  UnicodeString &formatMeasures(
188  const Measure *measures,
189  int32_t measureCount,
190  UnicodeString &appendTo,
191  FieldPosition &pos,
192  UErrorCode &status) const;
193 #endif /* U_HIDE_DRAFT_API */
194 
195 #ifndef U_HIDE_INTERNAL_API
196 
210  UnicodeString &formatMeasuresPer(
211  const Measure *measures,
212  int32_t measureCount,
213  const MeasureUnit &perUnit,
214  UnicodeString &appendTo,
215  FieldPosition &pos,
216  UErrorCode &status) const;
217 #endif /* U_HIDE_INTERNAL_API */
218 
227  static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
228  UErrorCode& ec);
229 
237  static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
238 
250  static UClassID U_EXPORT2 getStaticClassID(void);
251 
263  virtual UClassID getDynamicClassID(void) const;
264 
265  protected:
270  MeasureFormat();
271 
272 #ifndef U_HIDE_INTERNAL_API
273 
279  void initMeasureFormat(
280  const Locale &locale,
281  UMeasureFormatWidth width,
282  NumberFormat *nfToAdopt,
283  UErrorCode &status);
291  UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
292 
298  void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
299 
304  const NumberFormat &getNumberFormat() const;
305 
310  const PluralRules &getPluralRules() const;
311 
316  Locale getLocale(UErrorCode &status) const;
317 
322  const char *getLocaleID(UErrorCode &status) const;
323 
324 #endif /* U_HIDE_INTERNAL_API */
325 
326  private:
327  const MeasureFormatCacheData *cache;
328  const SharedNumberFormat *numberFormat;
329  const SharedPluralRules *pluralRules;
330  UMeasureFormatWidth width;
331 
332  // Declared outside of MeasureFormatSharedData because ListFormatter
333  // objects are relatively cheap to copy; therefore, they don't need to be
334  // shared across instances.
335  ListFormatter *listFormatter;
336 
337  const QuantityFormatter *getQuantityFormatter(
338  int32_t index,
339  int32_t widthIndex,
340  UErrorCode &status) const;
341 
342  const SimplePatternFormatter *getPerUnitFormatter(
343  int32_t index,
344  int32_t widthIndex) const;
345 
346  const SimplePatternFormatter *getPerFormatter(
347  int32_t widthIndex,
348  UErrorCode &status) const;
349 
350  int32_t withPerUnit(
351  const UnicodeString &formatted,
352  const MeasureUnit &perUnit,
353  UnicodeString &appendTo,
354  UErrorCode &status) const;
355 
356  UnicodeString &formatMeasure(
357  const Measure &measure,
358  const NumberFormat &nf,
359  UnicodeString &appendTo,
360  FieldPosition &pos,
361  UErrorCode &status) const;
362 
363  UnicodeString &formatMeasuresSlowTrack(
364  const Measure *measures,
365  int32_t measureCount,
366  UnicodeString& appendTo,
367  FieldPosition& pos,
368  UErrorCode& status) const;
369 
370  UnicodeString &formatNumeric(
371  const Formattable *hms, // always length 3: [0] is hour; [1] is
372  // minute; [2] is second.
373  int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
374  UnicodeString &appendTo,
375  UErrorCode &status) const;
376 
377  UnicodeString &formatNumeric(
378  UDate date,
379  const DateFormat &dateFmt,
380  UDateFormatField smallestField,
381  const Formattable &smallestAmount,
382  UnicodeString &appendTo,
383  UErrorCode &status) const;
384 };
385 
387 
388 #endif // #if !UCONFIG_NO_FORMATTING
389 #endif // #ifndef MEASUREFORMAT_H
Base class for all formats.
Definition: format.h:94
UMeasureFormatWidth
Constants for various widths.
Definition: measfmt.h:34
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:36
Count of values in this enum.
Definition: measfmt.h:68
An amount of a specified unit, consisting of a number and a Unit.
Definition: measure.h:41
A formatter for measure objects.
Definition: measfmt.h:95
Use symbols for measure units when possible.
Definition: measfmt.h:54
Abstract base class for all number formats.
Definition: numfmt.h:172
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
double UDate
Date and Time data type.
Definition: utypes.h:201
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
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:191
C++ API: Base class for all formats.
const char * getLocaleID(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
Spell out measure units.
Definition: measfmt.h:42
Abbreviate measure units.
Definition: measfmt.h:48
An immutable class for formatting a list, using data from CLDR (or supplied separately).
Definition: listformatter.h:62
C API: DateFormat.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Completely omit measure units when possible.
Definition: measfmt.h:61
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:487
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:147
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:245
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185