ICU 58.2 58.2

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

- File List
- Globals

measfmt.h
Go to the documentation of this file.
1 // Copyright (C) 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
213 #ifndef U_HIDE_DRAFT_API
214
225 UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const;
226 #endif /* U_HIDE_DRAFT_API */
227
228
237 static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
238 UErrorCode& ec);
239
247 static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
248
260 static UClassID U_EXPORT2 getStaticClassID(void);
261
273 virtual UClassID getDynamicClassID(void) const;
274
275 protected:
280 MeasureFormat();
281
282 #ifndef U_HIDE_INTERNAL_API
283
289 void initMeasureFormat(
290 const Locale &locale,
291 UMeasureFormatWidth width,
292 NumberFormat *nfToAdopt,
293 UErrorCode &status);
301 UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
302
308 void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
309
314 const NumberFormat &getNumberFormat() const;
315
320 const PluralRules &getPluralRules() const;
321
326 Locale getLocale(UErrorCode &status) const;
327
332 const char *getLocaleID(UErrorCode &status) const;
333
334 #endif /* U_HIDE_INTERNAL_API */
335
336 private:
337 const MeasureFormatCacheData *cache;
338 const SharedNumberFormat *numberFormat;
339 const SharedPluralRules *pluralRules;
340 UMeasureFormatWidth width;
341
342 // Declared outside of MeasureFormatSharedData because ListFormatter
343 // objects are relatively cheap to copy; therefore, they don't need to be
344 // shared across instances.
345 ListFormatter *listFormatter;
346
347 const SimpleFormatter *getFormatterOrNull(
348 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const;
349
350 const SimpleFormatter *getFormatter(
351 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
352 UErrorCode &errorCode) const;
353
354 const SimpleFormatter *getPluralFormatter(
355 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
356 UErrorCode &errorCode) const;
357
358 const SimpleFormatter *getPerFormatter(
359 UMeasureFormatWidth width,
360 UErrorCode &status) const;
361
362 int32_t withPerUnitAndAppend(
363 const UnicodeString &formatted,
364 const MeasureUnit &perUnit,
365 UnicodeString &appendTo,
366 UErrorCode &status) const;
367
368 UnicodeString &formatMeasure(
369 const Measure &measure,
370 const NumberFormat &nf,
371 UnicodeString &appendTo,
372 FieldPosition &pos,
373 UErrorCode &status) const;
374
375 UnicodeString &formatMeasuresSlowTrack(
376 const Measure *measures,
377 int32_t measureCount,
378 UnicodeString& appendTo,
379 FieldPosition& pos,
380 UErrorCode& status) const;
381
382 UnicodeString &formatNumeric(
383 const Formattable *hms, // always length 3: [0] is hour; [1] is
384 // minute; [2] is second.
385 int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
386 UnicodeString &appendTo,
387 UErrorCode &status) const;
388
389 UnicodeString &formatNumeric(
390 UDate date,
391 const DateFormat &dateFmt,
392 UDateFormatField smallestField,
393 const Formattable &smallestAmount,
394 UnicodeString &appendTo,
395 UErrorCode &status) const;
396 };
397
398 U_NAMESPACE_END
399
400 #endif // #if !UCONFIG_NO_FORMATTING
401 #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:169
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:194
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:54
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:295
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:259
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187