ICU 57.1  57.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-2016, 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  // Wide, short, and narrow must be first and in this order.
42 
48 
54 
61 
67 };
70 
72 
73 class Measure;
74 class MeasureUnit;
75 class NumberFormat;
76 class PluralRules;
77 class MeasureFormatCacheData;
78 class SharedNumberFormat;
79 class SharedPluralRules;
80 class QuantityFormatter;
81 class SimpleFormatter;
82 class ListFormatter;
83 class DateFormat;
84 
94  public:
95  using Format::parseObject;
96  using Format::format;
97 
103  const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
104 
110  const Locale &locale,
111  UMeasureFormatWidth width,
112  NumberFormat *nfToAdopt,
113  UErrorCode &status);
114 
119  MeasureFormat(const MeasureFormat &other);
120 
126 
131  virtual ~MeasureFormat();
132 
137  virtual UBool operator==(const Format &other) const;
138 
143  virtual Format *clone() const;
144 
149  virtual UnicodeString &format(
150  const Formattable &obj,
151  UnicodeString &appendTo,
152  FieldPosition &pos,
153  UErrorCode &status) const;
154 
161  virtual void parseObject(
162  const UnicodeString &source,
163  Formattable &reslt,
164  ParsePosition &pos) const;
165 
182  UnicodeString &formatMeasures(
183  const Measure *measures,
184  int32_t measureCount,
185  UnicodeString &appendTo,
186  FieldPosition &pos,
187  UErrorCode &status) const;
188 
202  UnicodeString &formatMeasurePerUnit(
203  const Measure &measure,
204  const MeasureUnit &perUnit,
205  UnicodeString &appendTo,
206  FieldPosition &pos,
207  UErrorCode &status) const;
208 
209 
218  static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
219  UErrorCode& ec);
220 
228  static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
229 
241  static UClassID U_EXPORT2 getStaticClassID(void);
242 
254  virtual UClassID getDynamicClassID(void) const;
255 
256  protected:
261  MeasureFormat();
262 
263 #ifndef U_HIDE_INTERNAL_API
264 
270  void initMeasureFormat(
271  const Locale &locale,
272  UMeasureFormatWidth width,
273  NumberFormat *nfToAdopt,
274  UErrorCode &status);
282  UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
283 
289  void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
290 
295  const NumberFormat &getNumberFormat() const;
296 
301  const PluralRules &getPluralRules() const;
302 
307  Locale getLocale(UErrorCode &status) const;
308 
313  const char *getLocaleID(UErrorCode &status) const;
314 
315 #endif /* U_HIDE_INTERNAL_API */
316 
317  private:
318  const MeasureFormatCacheData *cache;
319  const SharedNumberFormat *numberFormat;
320  const SharedPluralRules *pluralRules;
321  UMeasureFormatWidth width;
322 
323  // Declared outside of MeasureFormatSharedData because ListFormatter
324  // objects are relatively cheap to copy; therefore, they don't need to be
325  // shared across instances.
326  ListFormatter *listFormatter;
327 
328  const SimpleFormatter *getFormatterOrNull(
329  const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const;
330 
331  const SimpleFormatter *getFormatter(
332  const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
333  UErrorCode &errorCode) const;
334 
335  const SimpleFormatter *getPluralFormatter(
336  const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
337  UErrorCode &errorCode) const;
338 
339  const SimpleFormatter *getPerFormatter(
340  UMeasureFormatWidth width,
341  UErrorCode &status) const;
342 
343  int32_t withPerUnitAndAppend(
344  const UnicodeString &formatted,
345  const MeasureUnit &perUnit,
346  UnicodeString &appendTo,
347  UErrorCode &status) const;
348 
349  UnicodeString &formatMeasure(
350  const Measure &measure,
351  const NumberFormat &nf,
352  UnicodeString &appendTo,
353  FieldPosition &pos,
354  UErrorCode &status) const;
355 
356  UnicodeString &formatMeasuresSlowTrack(
357  const Measure *measures,
358  int32_t measureCount,
359  UnicodeString& appendTo,
360  FieldPosition& pos,
361  UErrorCode& status) const;
362 
363  UnicodeString &formatNumeric(
364  const Formattable *hms, // always length 3: [0] is hour; [1] is
365  // minute; [2] is second.
366  int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
367  UnicodeString &appendTo,
368  UErrorCode &status) const;
369 
370  UnicodeString &formatNumeric(
371  UDate date,
372  const DateFormat &dateFmt,
373  UDateFormatField smallestField,
374  const Formattable &smallestAmount,
375  UnicodeString &appendTo,
376  UErrorCode &status) const;
377 };
378 
380 
381 #endif // #if !UCONFIG_NO_FORMATTING
382 #endif // #ifndef MEASUREFORMAT_H