ICU 62.1 62.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 !UCONFIG_NO_FORMATTING
19
20#include "unicode/format.h"
21#include "unicode/udat.h"
22
37
38 // Wide, short, and narrow must be first and in this order.
44
50
56
63
64#ifndef U_HIDE_DEPRECATED_API
70#endif // U_HIDE_DEPRECATED_API
71};
74
76
77class Measure;
78class MeasureUnit;
79class NumberFormat;
80class PluralRules;
81class MeasureFormatCacheData;
82class SharedNumberFormat;
83class SharedPluralRules;
84class QuantityFormatter;
85class SimpleFormatter;
86class ListFormatter;
87class DateFormat;
88
99 public:
100 using Format::parseObject;
101 using Format::format;
102
111 const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
112
121 const Locale &locale,
125
131
137
142 virtual ~MeasureFormat();
143
148 virtual UBool operator==(const Format &other) const;
149
154 virtual Format *clone() const;
155
161 const Formattable &obj,
162 UnicodeString &appendTo,
163 FieldPosition &pos,
164 UErrorCode &status) const;
165
172 virtual void parseObject(
173 const UnicodeString &source,
175 ParsePosition &pos) const;
176
194 const Measure *measures,
195 int32_t measureCount,
196 UnicodeString &appendTo,
197 FieldPosition &pos,
198 UErrorCode &status) const;
199
214 const Measure &measure,
215 const MeasureUnit &perUnit,
216 UnicodeString &appendTo,
217 FieldPosition &pos,
218 UErrorCode &status) const;
219
232
233
246 UErrorCode& ec);
247
259
272
284 virtual UClassID getDynamicClassID(void) const;
285
286 protected:
292
293#ifndef U_HIDE_INTERNAL_API
294
301 const Locale &locale,
313
320
326
332
338
343 const char *getLocaleID(UErrorCode &status) const;
344
345#endif /* U_HIDE_INTERNAL_API */
346
347 private:
348 const MeasureFormatCacheData *cache;
349 const SharedNumberFormat *numberFormat;
350 const SharedPluralRules *pluralRules;
351 UMeasureFormatWidth width;
352
353 // Declared outside of MeasureFormatSharedData because ListFormatter
354 // objects are relatively cheap to copy; therefore, they don't need to be
355 // shared across instances.
356 ListFormatter *listFormatter;
357
358 const SimpleFormatter *getFormatterOrNull(
359 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const;
360
361 const SimpleFormatter *getFormatter(
362 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
363 UErrorCode &errorCode) const;
364
365 const SimpleFormatter *getPluralFormatter(
366 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
367 UErrorCode &errorCode) const;
368
369 const SimpleFormatter *getPerFormatter(
371 UErrorCode &status) const;
372
373 int32_t withPerUnitAndAppend(
375 const MeasureUnit &perUnit,
376 UnicodeString &appendTo,
377 UErrorCode &status) const;
378
379 UnicodeString &formatMeasure(
380 const Measure &measure,
381 const NumberFormat &nf,
382 UnicodeString &appendTo,
383 FieldPosition &pos,
384 UErrorCode &status) const;
385
386 UnicodeString &formatMeasuresSlowTrack(
387 const Measure *measures,
388 int32_t measureCount,
389 UnicodeString& appendTo,
390 FieldPosition& pos,
391 UErrorCode& status) const;
392
393 UnicodeString &formatNumeric(
394 const Formattable *hms, // always length 3: [0] is hour; [1] is
395 // minute; [2] is second.
396 int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
397 UnicodeString &appendTo,
398 UErrorCode &status) const;
399
400 UnicodeString &formatNumeric(
401 UDate date,
402 const DateFormat &dateFmt,
405 UnicodeString &appendTo,
406 UErrorCode &status) const;
407};
408
410
411#endif // #if !UCONFIG_NO_FORMATTING
412#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:150
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:108
Base class for all formats.
Definition format.h:96
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
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:188
static UClassID getStaticClassID(void)
Return the class ID for this class.
static MeasureFormat * createCurrencyFormat(const Locale &locale, UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the given locale.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats object to produce a string.
virtual UBool operator==(const Format &other) const
Return true if given Format objects are semantically equal.
const NumberFormat & getNumberFormat() const
ICU use only.
virtual void parseObject(const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const
Parse a string to produce an object.
UnicodeString & formatMeasures(const Measure *measures, int32_t measureCount, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats measure objects to produce a string.
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, UErrorCode &status)
Constructor.
virtual Format * clone() const
Clones this object polymorphically.
void initMeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
MeasureFormat(const MeasureFormat &other)
Copy constructor.
const char * getLocaleID(UErrorCode &status) const
ICU use only.
virtual ~MeasureFormat()
Destructor.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
UnicodeString getUnitDisplayName(const MeasureUnit &unit, UErrorCode &status) const
Gets the display name of the specified MeasureUnit corresponding to the current locale and format wid...
const PluralRules & getPluralRules() const
ICU use only.
UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status)
ICU use only.
MeasureFormat()
Default constructor.
void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
UnicodeString & formatMeasurePerUnit(const Measure &measure, const MeasureUnit &perUnit, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a single measure per unit.
static MeasureFormat * createCurrencyFormat(UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the default locale.
Locale getLocale(UErrorCode &status) const
ICU use only.
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
Constructor.
MeasureFormat & operator=(const MeasureFormat &rhs)
Assignment operator.
A unit such as length, mass, volume, currency, etc.
Definition measunit.h:38
An amount of a specified unit, consisting of a number and a Unit.
Definition measure.h:43
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:49
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition plurrule.h:196
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:287
C++ API: Base class for all formats.
UMeasureFormatWidth
Constants for various widths.
Definition measfmt.h:36
@ UMEASFMT_WIDTH_NARROW
Use symbols for measure units when possible.
Definition measfmt.h:55
@ UMEASFMT_WIDTH_WIDE
Spell out measure units.
Definition measfmt.h:43
@ UMEASFMT_WIDTH_COUNT
One more than the highest normal UMeasureFormatWidth value.
Definition measfmt.h:69
@ UMEASFMT_WIDTH_NUMERIC
Completely omit measure units when possible.
Definition measfmt.h:62
@ UMEASFMT_WIDTH_SHORT
Abbreviate measure units.
Definition measfmt.h:49
C API: DateFormat.
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition udat.h:490
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
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:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
double UDate
Date and Time data type.
Definition utypes.h:203
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137