ICU 53.1  53.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include "unicode/measure.h"
16 
17 #if !UCONFIG_NO_FORMATTING
18 
19 #include "unicode/format.h"
20 #include "unicode/udat.h"
21 
27 #ifndef U_HIDE_DRAFT_API
28 
36 
37  // Wide, short, and narrow must be first and in this order.
43 
49 
55 
62 
68 };
71 #endif /* U_HIDE_DRAFT_API */
72 
74 
75 class NumberFormat;
76 class PluralRules;
77 class MeasureFormatCacheData;
78 class SharedNumberFormat;
79 class SharedPluralRules;
80 class QuantityFormatter;
81 class ListFormatter;
82 class DateFormat;
83 
93  public:
94  using Format::parseObject;
95  using Format::format;
96 
97 #ifndef U_HIDE_DRAFT_API
98 
103  const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
104 
110  const Locale &locale,
111  UMeasureFormatWidth width,
112  NumberFormat *nfToAdopt,
113  UErrorCode &status);
114 #endif /* U_HIDE_DRAFT_API */
115 
120  MeasureFormat(const MeasureFormat &other);
121 
127 
132  virtual ~MeasureFormat();
133 
138  virtual UBool operator==(const Format &other) const;
139 
144  virtual Format *clone() const;
145 
150  virtual UnicodeString &format(
151  const Formattable &obj,
152  UnicodeString &appendTo,
153  FieldPosition &pos,
154  UErrorCode &status) const;
155 
162  virtual void parseObject(
163  const UnicodeString &source,
164  Formattable &reslt,
165  ParsePosition &pos) const;
166 
167 #ifndef U_HIDE_DRAFT_API
168 
184  UnicodeString &formatMeasures(
185  const Measure *measures,
186  int32_t measureCount,
187  UnicodeString &appendTo,
188  FieldPosition &pos,
189  UErrorCode &status) const;
190 #endif /* U_HIDE_DRAFT_API */
191 
192 
201  static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
202  UErrorCode& ec);
203 
211  static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
212 
224  static UClassID U_EXPORT2 getStaticClassID(void);
225 
237  virtual UClassID getDynamicClassID(void) const;
238 
239  protected:
244  MeasureFormat();
245 
246 #ifndef U_HIDE_INTERNAL_API
247 
248 #ifndef U_HIDE_DRAFT_API
249 
254  void initMeasureFormat(
255  const Locale &locale,
256  UMeasureFormatWidth width,
257  NumberFormat *nfToAdopt,
258  UErrorCode &status);
259 #endif
260 
267  UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
268 
274  void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
275 
280  const NumberFormat &getNumberFormat() const;
281 
286  const PluralRules &getPluralRules() const;
287 
292  Locale getLocale(UErrorCode &status) const;
293 
298  const char *getLocaleID(UErrorCode &status) const;
299 
300 #endif /* U_HIDE_INTERNAL_API */
301 
302  private:
303  const MeasureFormatCacheData *cache;
304  const SharedNumberFormat *numberFormat;
305  const SharedPluralRules *pluralRules;
306 #ifndef U_HIDE_DRAFT_API
307  UMeasureFormatWidth width;
308 #endif
309 
310  // Declared outside of MeasureFormatSharedData because ListFormatter
311  // objects are relatively cheap to copy; therefore, they don't need to be
312  // shared across instances.
313  ListFormatter *listFormatter;
314 
315  const QuantityFormatter *getQuantityFormatter(
316  int32_t index,
317  int32_t widthIndex,
318  UErrorCode &status) const;
319 
320  UnicodeString &formatMeasure(
321  const Measure &measure,
322  const NumberFormat &nf,
323  UnicodeString &appendTo,
324  FieldPosition &pos,
325  UErrorCode &status) const;
326 
327  UnicodeString &formatMeasuresSlowTrack(
328  const Measure *measures,
329  int32_t measureCount,
330  UnicodeString& appendTo,
331  FieldPosition& pos,
332  UErrorCode& status) const;
333 
334  UnicodeString &formatNumeric(
335  const Formattable *hms, // always length 3: [0] is hour; [1] is
336  // minute; [2] is second.
337  int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
338  UnicodeString &appendTo,
339  UErrorCode &status) const;
340 
341  UnicodeString &formatNumeric(
342  UDate date,
343  const DateFormat &dateFmt,
344  UDateFormatField smallestField,
345  const Formattable &smallestAmount,
346  UnicodeString &appendTo,
347  UErrorCode &status) const;
348 };
349 
351 
352 #endif // #if !UCONFIG_NO_FORMATTING
353 #endif // #ifndef MEASUREFORMAT_H
Base class for all formats.
Definition: format.h:94
UMeasureFormatWidth
Constants for various widths.
Definition: measfmt.h:35
Count of values in this enum.
Definition: measfmt.h:67
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:92
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: MeasureUnit object.
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:200
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185