measfmt.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (c) 2004-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
* Created: April 20, 2004
* Since: ICU 3.0
**********************************************************************
*/
#ifndef MEASUREFORMAT_H
#define MEASUREFORMAT_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/format.h"
#include "unicode/udat.h"
enum UMeasureFormatWidth {
// Wide, short, and narrow must be first and in this order.
UMEASFMT_WIDTH_WIDE,
UMEASFMT_WIDTH_SHORT,
UMEASFMT_WIDTH_NARROW,
UMEASFMT_WIDTH_NUMERIC,
#ifndef U_HIDE_DEPRECATED_API
UMEASFMT_WIDTH_COUNT = 4
#endif // U_HIDE_DEPRECATED_API
};
typedef enum UMeasureFormatWidth UMeasureFormatWidth;
U_NAMESPACE_BEGIN
class Measure;
class MeasureUnit;
class NumberFormat;
class PluralRules;
class MeasureFormatCacheData;
class SharedNumberFormat;
class SharedPluralRules;
class QuantityFormatter;
class SimpleFormatter;
class ListFormatter;
class DateFormat;
class U_I18N_API MeasureFormat : public Format {
public:
using Format::parseObject;
using Format::format;
MeasureFormat(
const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
MeasureFormat(
const Locale &locale,
UMeasureFormatWidth width,
NumberFormat *nfToAdopt,
UErrorCode &status);
MeasureFormat(const MeasureFormat &other);
MeasureFormat &operator=(const MeasureFormat &rhs);
virtual ~MeasureFormat();
virtual bool operator==(const Format &other) const override;
virtual MeasureFormat *clone() const override;
virtual UnicodeString &format(
const Formattable &obj,
UnicodeString &appendTo,
FieldPosition &pos,
UErrorCode &status) const override;
#ifndef U_FORCE_HIDE_DRAFT_API
virtual void parseObject(
const UnicodeString &source,
Formattable &reslt,
ParsePosition &pos) const override;
#endif // U_FORCE_HIDE_DRAFT_API
UnicodeString &formatMeasures(
const Measure *measures,
int32_t measureCount,
UnicodeString &appendTo,
FieldPosition &pos,
UErrorCode &status) const;
UnicodeString &formatMeasurePerUnit(
const Measure &measure,
const MeasureUnit &perUnit,
UnicodeString &appendTo,
FieldPosition &pos,
UErrorCode &status) const;
UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const;
static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
UErrorCode& ec);
static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
static UClassID U_EXPORT2 getStaticClassID();
virtual UClassID getDynamicClassID() const override;
protected:
MeasureFormat();
#ifndef U_HIDE_INTERNAL_API
void initMeasureFormat(
const Locale &locale,
UMeasureFormatWidth width,
NumberFormat *nfToAdopt,
UErrorCode &status);
UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
const NumberFormat &getNumberFormatInternal() const;
const NumberFormat& getCurrencyFormatInternal() const;
const PluralRules &getPluralRules() const;
Locale getLocale(UErrorCode &status) const;
const char *getLocaleID(UErrorCode &status) const;
#endif /* U_HIDE_INTERNAL_API */
private:
const MeasureFormatCacheData *cache;
const SharedNumberFormat *numberFormat;
const SharedPluralRules *pluralRules;
UMeasureFormatWidth fWidth;
// Declared outside of MeasureFormatSharedData because ListFormatter
// objects are relatively cheap to copy; therefore, they don't need to be
// shared across instances.
ListFormatter *listFormatter;
UnicodeString &formatMeasure(
const Measure &measure,
const NumberFormat &nf,
UnicodeString &appendTo,
FieldPosition &pos,
UErrorCode &status) const;
UnicodeString &formatMeasuresSlowTrack(
const Measure *measures,
int32_t measureCount,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const;
UnicodeString &formatNumeric(
const Formattable *hms, // always length 3: [0] is hour; [1] is
// minute; [2] is second.
int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
UnicodeString &appendTo,
UErrorCode &status) const;
};
U_NAMESPACE_END
#endif // #if !UCONFIG_NO_FORMATTING
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // #ifndef MEASUREFORMAT_H
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:110
icu::Format
Base class for all formats.
Definition format.h:98
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:63
icu::ListFormatter
An immutable class for formatting a list, using data from CLDR (or supplied separately).
Definition listformatter.h:151
icu::LocalPointerBase
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Definition localpointer.h:68
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
icu::MeasureFormat
Definition measfmt.h:101
icu::MeasureFormat::createCurrencyFormat
static MeasureFormat * createCurrencyFormat(const Locale &locale, UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the given locale.
icu::MeasureFormat::getCurrencyFormatInternal
const NumberFormat & getCurrencyFormatInternal() const
ICU use only.
icu::MeasureFormat::getNumberFormatInternal
const NumberFormat & getNumberFormatInternal() const
ICU use only.
icu::MeasureFormat::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const override
Parse a string to produce an object.
icu::MeasureFormat::formatMeasures
UnicodeString & formatMeasures(const Measure *measures, int32_t measureCount, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats measure objects to produce a string.
icu::MeasureFormat::MeasureFormat
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, UErrorCode &status)
Constructor.
icu::MeasureFormat::initMeasureFormat
void initMeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
icu::MeasureFormat::MeasureFormat
MeasureFormat(const MeasureFormat &other)
Copy constructor.
icu::MeasureFormat::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::MeasureFormat::getLocaleID
const char * getLocaleID(UErrorCode &status) const
ICU use only.
icu::MeasureFormat::~MeasureFormat
virtual ~MeasureFormat()
Destructor.
icu::MeasureFormat::getUnitDisplayName
UnicodeString getUnitDisplayName(const MeasureUnit &unit, UErrorCode &status) const
Gets the display name of the specified MeasureUnit corresponding to the current locale and format wid...
icu::MeasureFormat::getPluralRules
const PluralRules & getPluralRules() const
ICU use only.
icu::MeasureFormat::clone
virtual MeasureFormat * clone() const override
Clones this object polymorphically.
icu::MeasureFormat::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::MeasureFormat::setMeasureFormatLocale
UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status)
ICU use only.
icu::MeasureFormat::MeasureFormat
MeasureFormat()
Default constructor.
icu::MeasureFormat::format
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Formats object to produce a string.
icu::MeasureFormat::operator==
virtual bool operator==(const Format &other) const override
Return true if given Format objects are semantically equal.
icu::MeasureFormat::adoptNumberFormat
void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status)
ICU use only.
icu::MeasureFormat::formatMeasurePerUnit
UnicodeString & formatMeasurePerUnit(const Measure &measure, const MeasureUnit &perUnit, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a single measure per unit.
icu::MeasureFormat::createCurrencyFormat
static MeasureFormat * createCurrencyFormat(UErrorCode &ec)
Return a formatter for CurrencyAmount objects in the default locale.
icu::MeasureFormat::getLocale
Locale getLocale(UErrorCode &status) const
ICU use only.
icu::MeasureFormat::MeasureFormat
MeasureFormat(const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
Constructor.
icu::MeasureFormat::operator=
MeasureFormat & operator=(const MeasureFormat &rhs)
Assignment operator.
icu::MeasureUnit
A unit such as length, mass, volume, currency, etc.
Definition measunit.h:409
icu::Measure
An amount of a specified unit, consisting of a number and a Unit.
Definition measure.h:45
icu::NumberFormat
Definition numfmt.h:175
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:52
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition plurrule.h:212
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
format.h
C++ API: Base class for all formats.
UMeasureFormatWidth
UMeasureFormatWidth
Constants for various widths.
Definition measfmt.h:38
UMEASFMT_WIDTH_NARROW
@ UMEASFMT_WIDTH_NARROW
Use symbols for measure units when possible.
Definition measfmt.h:57
UMEASFMT_WIDTH_WIDE
@ UMEASFMT_WIDTH_WIDE
Spell out measure units.
Definition measfmt.h:45
UMEASFMT_WIDTH_COUNT
@ UMEASFMT_WIDTH_COUNT
One more than the highest normal UMeasureFormatWidth value.
Definition measfmt.h:71
UMEASFMT_WIDTH_NUMERIC
@ UMEASFMT_WIDTH_NUMERIC
Completely omit measure units when possible.
Definition measfmt.h:64
UMEASFMT_WIDTH_SHORT
@ UMEASFMT_WIDTH_SHORT
Abbreviate measure units.
Definition measfmt.h:51
udat.h
C API: DateFormat.
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
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:316