ICU 57.1 57.1
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
73class Measure;
74class MeasureUnit;
75class NumberFormat;
76class PluralRules;
81class SimpleFormatter;
82class ListFormatter;
83class DateFormat;
84
94 public:
96 using Format::format;
97
103 const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
104
110 const Locale &locale,
114
120
126
131 virtual ~MeasureFormat();
132
137 virtual UBool operator==(const Format &other) const;
138
143 virtual Format *clone() const;
144
150 const Formattable &obj,
152 FieldPosition &pos,
153 UErrorCode &status) const;
154
161 virtual void parseObject(
162 const UnicodeString &source,
164 ParsePosition &pos) const;
165
183 const Measure *measures,
186 FieldPosition &pos,
187 UErrorCode &status) const;
188
203 const Measure &measure,
204 const MeasureUnit &perUnit,
206 FieldPosition &pos,
207 UErrorCode &status) const;
208
209
219 UErrorCode& ec);
220
229
242
254 virtual UClassID getDynamicClassID(void) const;
255
256 protected:
262
263#ifndef U_HIDE_INTERNAL_API
264
271 const Locale &locale,
283
290
296
302
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(
341 UErrorCode &status) const;
342
343 int32_t withPerUnitAndAppend(
345 const MeasureUnit &perUnit,
347 UErrorCode &status) const;
348
349 UnicodeString &formatMeasure(
350 const Measure &measure,
351 const NumberFormat &nf,
353 FieldPosition &pos,
354 UErrorCode &status) const;
355
356 UnicodeString &formatMeasuresSlowTrack(
357 const Measure *measures,
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
368 UErrorCode &status) const;
369
370 UnicodeString &formatNumeric(
371 UDate date,
372 const DateFormat &dateFmt,
376 UErrorCode &status) const;
377};
378
380
381#endif // #if !UCONFIG_NO_FORMATTING
382#endif // #ifndef MEASUREFORMAT_H
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:147
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
Base class for all formats.
Definition format.h:94
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:66
An immutable class for formatting a list, using data from CLDR (or supplied separately).
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:185
A formatter for measure objects.
Definition measfmt.h:93
void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
Locale getLocale(UErrorCode &status) const
ICU use only.
const PluralRules & getPluralRules() const
ICU use only.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
const char * getLocaleID(UErrorCode &status) const
ICU use only.
MeasureFormat(const MeasureFormat &other)
Copy constructor.
virtual ~MeasureFormat()
Destructor.
UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status)
ICU use only.
virtual Format * clone() const
Clones this object polymorphically.
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
Constructor.
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, UErrorCode &status)
Constructor.
MeasureFormat()
Default constructor.
const NumberFormat & getNumberFormat() const
ICU use only.
virtual UBool operator==(const Format &other) const
Return true if given Format objects are semantically equal.
UnicodeString & formatMeasurePerUnit(const Measure &measure, const MeasureUnit &perUnit, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a single measure per unit.
MeasureFormat & operator=(const MeasureFormat &rhs)
Assignment operator.
void initMeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
UnicodeString & formatMeasures(const Measure *measures, int32_t measureCount, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats measure objects to produce a string.
static MeasureFormat * createCurrencyFormat(UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the default locale.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats object to produce a string.
static UClassID getStaticClassID(void)
Return the class ID for this class.
virtual void parseObject(const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const
Parse a string to produce an object.
static MeasureFormat * createCurrencyFormat(const Locale &locale, UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the given locale.
A unit such as length, mass, volume, currency, etc.
Definition measunit.h:36
An amount of a specified unit, consisting of a number and a Unit.
Definition measure.h:41
Abstract base class for all number formats.
Definition numfmt.h:167
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition plurrule.h:192
Formats simple patterns like "{1} was born in {0}".
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
C++ API: Base class for all formats.
UMeasureFormatWidth
Constants for various widths.
Definition measfmt.h:34
@ UMEASFMT_WIDTH_NARROW
Use symbols for measure units when possible.
Definition measfmt.h:53
@ UMEASFMT_WIDTH_WIDE
Spell out measure units.
Definition measfmt.h:41
@ UMEASFMT_WIDTH_COUNT
Count of values in this enum.
Definition measfmt.h:66
@ UMEASFMT_WIDTH_NUMERIC
Completely omit measure units when possible.
Definition measfmt.h:60
@ UMEASFMT_WIDTH_SHORT
Abbreviate measure units.
Definition measfmt.h:47
C API: DateFormat.
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition udat.h:488
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#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_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129