00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef MEASUREFORMAT_H
00012 #define MEASUREFORMAT_H
00013
00014 #include "unicode/utypes.h"
00015
00016 #if !UCONFIG_NO_FORMATTING
00017
00018 #include "unicode/format.h"
00019 #include "unicode/udat.h"
00020
00034 enum UMeasureFormatWidth {
00035
00036
00041 UMEASFMT_WIDTH_WIDE,
00042
00047 UMEASFMT_WIDTH_SHORT,
00048
00053 UMEASFMT_WIDTH_NARROW,
00054
00060 UMEASFMT_WIDTH_NUMERIC,
00061
00066 UMEASFMT_WIDTH_COUNT = 4
00067 };
00069 typedef enum UMeasureFormatWidth UMeasureFormatWidth;
00070
00071 U_NAMESPACE_BEGIN
00072
00073 class Measure;
00074 class MeasureUnit;
00075 class NumberFormat;
00076 class PluralRules;
00077 class MeasureFormatCacheData;
00078 class SharedNumberFormat;
00079 class SharedPluralRules;
00080 class QuantityFormatter;
00081 class SimpleFormatter;
00082 class ListFormatter;
00083 class DateFormat;
00084
00093 class U_I18N_API MeasureFormat : public Format {
00094 public:
00095 using Format::parseObject;
00096 using Format::format;
00097
00102 MeasureFormat(
00103 const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
00104
00109 MeasureFormat(
00110 const Locale &locale,
00111 UMeasureFormatWidth width,
00112 NumberFormat *nfToAdopt,
00113 UErrorCode &status);
00114
00119 MeasureFormat(const MeasureFormat &other);
00120
00125 MeasureFormat &operator=(const MeasureFormat &rhs);
00126
00131 virtual ~MeasureFormat();
00132
00137 virtual UBool operator==(const Format &other) const;
00138
00143 virtual Format *clone() const;
00144
00149 virtual UnicodeString &format(
00150 const Formattable &obj,
00151 UnicodeString &appendTo,
00152 FieldPosition &pos,
00153 UErrorCode &status) const;
00154
00161 virtual void parseObject(
00162 const UnicodeString &source,
00163 Formattable &reslt,
00164 ParsePosition &pos) const;
00165
00182 UnicodeString &formatMeasures(
00183 const Measure *measures,
00184 int32_t measureCount,
00185 UnicodeString &appendTo,
00186 FieldPosition &pos,
00187 UErrorCode &status) const;
00188
00202 UnicodeString &formatMeasurePerUnit(
00203 const Measure &measure,
00204 const MeasureUnit &perUnit,
00205 UnicodeString &appendTo,
00206 FieldPosition &pos,
00207 UErrorCode &status) const;
00208
00209
00218 static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
00219 UErrorCode& ec);
00220
00228 static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
00229
00241 static UClassID U_EXPORT2 getStaticClassID(void);
00242
00254 virtual UClassID getDynamicClassID(void) const;
00255
00256 protected:
00261 MeasureFormat();
00262
00263 #ifndef U_HIDE_INTERNAL_API
00264
00270 void initMeasureFormat(
00271 const Locale &locale,
00272 UMeasureFormatWidth width,
00273 NumberFormat *nfToAdopt,
00274 UErrorCode &status);
00282 UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
00283
00289 void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
00290
00295 const NumberFormat &getNumberFormat() const;
00296
00301 const PluralRules &getPluralRules() const;
00302
00307 Locale getLocale(UErrorCode &status) const;
00308
00313 const char *getLocaleID(UErrorCode &status) const;
00314
00315 #endif
00316
00317 private:
00318 const MeasureFormatCacheData *cache;
00319 const SharedNumberFormat *numberFormat;
00320 const SharedPluralRules *pluralRules;
00321 UMeasureFormatWidth width;
00322
00323
00324
00325
00326 ListFormatter *listFormatter;
00327
00328 const SimpleFormatter *getFormatterOrNull(
00329 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const;
00330
00331 const SimpleFormatter *getFormatter(
00332 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
00333 UErrorCode &errorCode) const;
00334
00335 const SimpleFormatter *getPluralFormatter(
00336 const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
00337 UErrorCode &errorCode) const;
00338
00339 const SimpleFormatter *getPerFormatter(
00340 UMeasureFormatWidth width,
00341 UErrorCode &status) const;
00342
00343 int32_t withPerUnitAndAppend(
00344 const UnicodeString &formatted,
00345 const MeasureUnit &perUnit,
00346 UnicodeString &appendTo,
00347 UErrorCode &status) const;
00348
00349 UnicodeString &formatMeasure(
00350 const Measure &measure,
00351 const NumberFormat &nf,
00352 UnicodeString &appendTo,
00353 FieldPosition &pos,
00354 UErrorCode &status) const;
00355
00356 UnicodeString &formatMeasuresSlowTrack(
00357 const Measure *measures,
00358 int32_t measureCount,
00359 UnicodeString& appendTo,
00360 FieldPosition& pos,
00361 UErrorCode& status) const;
00362
00363 UnicodeString &formatNumeric(
00364 const Formattable *hms,
00365
00366 int32_t bitMap,
00367 UnicodeString &appendTo,
00368 UErrorCode &status) const;
00369
00370 UnicodeString &formatNumeric(
00371 UDate date,
00372 const DateFormat &dateFmt,
00373 UDateFormatField smallestField,
00374 const Formattable &smallestAmount,
00375 UnicodeString &appendTo,
00376 UErrorCode &status) const;
00377 };
00378
00379 U_NAMESPACE_END
00380
00381 #endif // #if !UCONFIG_NO_FORMATTING
00382 #endif // #ifndef MEASUREFORMAT_H