00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __TMUTFMT_H__
00009 #define __TMUTFMT_H__
00010
00011 #include "unicode/utypes.h"
00012
00019 #if !UCONFIG_NO_FORMATTING
00020
00021 #include "unicode/unistr.h"
00022 #include "unicode/tmunit.h"
00023 #include "unicode/tmutamt.h"
00024 #include "unicode/measfmt.h"
00025 #include "unicode/numfmt.h"
00026 #include "unicode/plurrule.h"
00027
00035 enum UTimeUnitFormatStyle {
00037 UTMUTFMT_FULL_STYLE,
00039 UTMUTFMT_ABBREVIATED_STYLE,
00041 UTMUTFMT_FORMAT_STYLE_COUNT
00042 };
00043 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle;
00045 U_NAMESPACE_BEGIN
00046
00047 class Hashtable;
00048 class UVector;
00049
00080 class U_I18N_API TimeUnitFormat: public MeasureFormat {
00081 public:
00082
00088 TimeUnitFormat(UErrorCode& status);
00089
00094 TimeUnitFormat(const Locale& locale, UErrorCode& status);
00095
00100 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
00101
00106 TimeUnitFormat(const TimeUnitFormat&);
00107
00112 virtual ~TimeUnitFormat();
00113
00120 virtual Format* clone(void) const;
00121
00126 TimeUnitFormat& operator=(const TimeUnitFormat& other);
00127
00128
00136 virtual UBool operator==(const Format& other) const;
00137
00145 UBool operator!=(const Format& other) const;
00146
00153 void setLocale(const Locale& locale, UErrorCode& status);
00154
00155
00162 void setNumberFormat(const NumberFormat& format, UErrorCode& status);
00163
00164
00165 using MeasureFormat::format;
00166
00175 virtual UnicodeString& format(const Formattable& obj,
00176 UnicodeString& toAppendTo,
00177 FieldPosition& pos,
00178 UErrorCode& status) const;
00179
00185 virtual void parseObject(const UnicodeString& source,
00186 Formattable& result,
00187 ParsePosition& pos) const;
00188
00200 static UClassID U_EXPORT2 getStaticClassID(void);
00201
00213 virtual UClassID getDynamicClassID(void) const;
00214
00215 private:
00216 NumberFormat* fNumberFormat;
00217 Locale fLocale;
00218 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
00219 PluralRules* fPluralRules;
00220 UTimeUnitFormatStyle fStyle;
00221
00222 void create(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
00223
00224
00225
00226 void setup(UErrorCode& status);
00227
00228
00229 void initDataMembers(UErrorCode& status);
00230
00231
00232 void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
00233 UErrorCode& status);
00234
00235
00236
00237 void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
00238
00239
00240 void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
00241 TimeUnit::UTimeUnitFields field, const UnicodeString&,
00242 const char*, Hashtable*, UErrorCode&);
00243
00244
00245 Hashtable* initHash(UErrorCode& status);
00246
00247
00248 void deleteHash(Hashtable* htable);
00249
00250
00251 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
00252
00253
00254 static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
00255 };
00256
00257
00258
00259 inline UBool
00260 TimeUnitFormat::operator!=(const Format& other) const {
00261 return !operator==(other);
00262 }
00263
00264
00265
00266 U_NAMESPACE_END
00267
00268 #endif
00269
00270 #endif // __TMUTFMT_H__
00271