ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
36 enum UMeasureFormatWidth {
37
38 // Wide, short, and narrow must be first and in this order.
43 UMEASFMT_WIDTH_WIDE,
44
49 UMEASFMT_WIDTH_SHORT,
50
55 UMEASFMT_WIDTH_NARROW,
56
62 UMEASFMT_WIDTH_NUMERIC,
63
64 #ifndef U_HIDE_DEPRECATED_API
65
69 UMEASFMT_WIDTH_COUNT = 4
70 #endif // U_HIDE_DEPRECATED_API
71 };
73 typedef enum UMeasureFormatWidth UMeasureFormatWidth;
74
75 U_NAMESPACE_BEGIN
76
77 class Measure;
78 class MeasureUnit;
79 class NumberFormat;
80 class PluralRules;
81 class MeasureFormatCacheData;
82 class SharedNumberFormat;
83 class SharedPluralRules;
84 class QuantityFormatter;
85 class SimpleFormatter;
86 class ListFormatter;
87 class DateFormat;
88
97 class U_I18N_API MeasureFormat : public Format {
98 public:
99 using Format::parseObject;
100 using Format::format;
101
106 MeasureFormat(
107 const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
108
113 MeasureFormat(
114 const Locale &locale,
115 UMeasureFormatWidth width,
116 NumberFormat *nfToAdopt,
117 UErrorCode &status);
118
123 MeasureFormat(const MeasureFormat &other);
124
129 MeasureFormat &operator=(const MeasureFormat &rhs);
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
186 UnicodeString &formatMeasures(
187 const Measure *measures,
188 int32_t measureCount,
189 UnicodeString &appendTo,
190 FieldPosition &pos,
191 UErrorCode &status) const;
192
206 UnicodeString &formatMeasurePerUnit(
207 const Measure &measure,
208 const MeasureUnit &perUnit,
209 UnicodeString &appendTo,
210 FieldPosition &pos,
211 UErrorCode &status) const;
212
224 UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const;
225
226
235 static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
236 UErrorCode& ec);
237
245 static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
246
258 static UClassID U_EXPORT2 getStaticClassID(void);
259
271 virtual UClassID getDynamicClassID(void) const;
272
273 protected:
278 MeasureFormat();
279
280 #ifndef U_HIDE_INTERNAL_API
281
287 void initMeasureFormat(
288 const Locale &locale,
289 UMeasureFormatWidth width,
290 NumberFormat *nfToAdopt,
291 UErrorCode &status);
299 UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
300
306 void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
307
312 const NumberFormat &getNumberFormat() const;
313
318 const PluralRules &getPluralRules() const;
319
324 Locale getLocale(UErrorCode &status) const;
325
330 const char *getLocaleID(UErrorCode &status) const;
331
332 #endif /* U_HIDE_INTERNAL_API */
333
334 private:
335 const MeasureFormatCacheData *cache;
336 const SharedNumberFormat *numberFormat;
337 const SharedPluralRules *pluralRules;
338 UMeasureFormatWidth width;
339
340 // Declared outside of MeasureFormatSharedData because ListFormatter
341 // objects are relatively cheap to copy; therefore, they don't need to be
342 // shared across instances.
343 ListFormatter *listFormatter;
344
345 const SimpleFormatter *getFormatterOrNull(
346 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const;
347
348 const SimpleFormatter *getFormatter(
349 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
350 UErrorCode &errorCode) const;
351
352 const SimpleFormatter *getPluralFormatter(
353 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
354 UErrorCode &errorCode) const;
355
356 const SimpleFormatter *getPerFormatter(
357 UMeasureFormatWidth width,
358 UErrorCode &status) const;
359
360 int32_t withPerUnitAndAppend(
361 const UnicodeString &formatted,
362 const MeasureUnit &perUnit,
363 UnicodeString &appendTo,
364 UErrorCode &status) const;
365
366 UnicodeString &formatMeasure(
367 const Measure &measure,
368 const NumberFormat &nf,
369 UnicodeString &appendTo,
370 FieldPosition &pos,
371 UErrorCode &status) const;
372
373 UnicodeString &formatMeasuresSlowTrack(
374 const Measure *measures,
375 int32_t measureCount,
376 UnicodeString& appendTo,
377 FieldPosition& pos,
378 UErrorCode& status) const;
379
380 UnicodeString &formatNumeric(
381 const Formattable *hms, // always length 3: [0] is hour; [1] is
382 // minute; [2] is second.
383 int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
384 UnicodeString &appendTo,
385 UErrorCode &status) const;
386
387 UnicodeString &formatNumeric(
388 UDate date,
389 const DateFormat &dateFmt,
390 UDateFormatField smallestField,
391 const Formattable &smallestAmount,
392 UnicodeString &appendTo,
393 UErrorCode &status) const;
394 };
395
396 U_NAMESPACE_END
397
398 #endif // #if !UCONFIG_NO_FORMATTING
399 #endif // #ifndef MEASUREFORMAT_H
icu::Format
Base class for all formats.
Definition: format.h:96
UMeasureFormatWidth
UMeasureFormatWidth
Constants for various widths.
Definition: measfmt.h:36
icu::MeasureUnit
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:38
UMEASFMT_WIDTH_COUNT
One more than the highest normal UMeasureFormatWidth value.
Definition: measfmt.h:69
icu::Measure
An amount of a specified unit, consisting of a number and a Unit.
Definition: measure.h:43
icu::MeasureFormat
A formatter for measure objects.
Definition: measfmt.h:97
UMEASFMT_WIDTH_NARROW
Use symbols for measure units when possible.
Definition: measfmt.h:55
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:174
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
icu::Format::getLocale
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:197
format.h
C++ API: Base class for all formats.
icu::Format::getLocaleID
const char * getLocaleID(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
icu::SimpleFormatter
Formats simple patterns like "{1} was born in {0}".
Definition: simpleformatter.h:59
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
UMEASFMT_WIDTH_WIDE
Spell out measure units.
Definition: measfmt.h:43
UMEASFMT_WIDTH_SHORT
Abbreviate measure units.
Definition: measfmt.h:49
icu::ListFormatter
An immutable class for formatting a list, using data from CLDR (or supplied separately).
Definition: listformatter.h:64
udat.h
C API: DateFormat.
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
UMEASFMT_WIDTH_NUMERIC
Completely omit measure units when possible.
Definition: measfmt.h:62
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UDateFormatField
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:490
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:149
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Format::operator=
Format & operator=(const Format &)
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188