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

- Search for |

- File List
- Globals

# tmutfmt.h

Go to the documentation of this file.

    00001 /*
    00002  *******************************************************************************
    00003  * Copyright (C) 2008, Google, International Business Machines Corporation and *
    00004  * others. All Rights Reserved.                                                *
    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
    00032 union UHashTok;
    00033
    00034 U_NAMESPACE_BEGIN
    00035
    00036 U_CDECL_BEGIN
    00037
    00041 static UBool U_CALLCONV hashTableValueComparator(UHashTok val1, UHashTok val2) ;
    00042
    00043 U_CDECL_END
    00044
    00045
    00046 class Hashtable;
    00047
    00048
    00079 class U_I18N_API TimeUnitFormat: public MeasureFormat {
    00080 public:
    00081
    00089     enum EStyle {
    00090         kFull = 0,
    00091         kAbbreviate = 1,
    00092         kTotal = kAbbreviate + 1
    00093     };
    00094
    00100     TimeUnitFormat(UErrorCode& status);
    00101
    00106     TimeUnitFormat(const Locale& locale, UErrorCode& status);
    00107
    00112     TimeUnitFormat(const Locale& locale, EStyle style, UErrorCode& status);
    00113
    00118     TimeUnitFormat(const TimeUnitFormat&);
    00119
    00124     virtual ~TimeUnitFormat();
    00125
    00132     virtual Format* clone(void) const;
    00133
    00138     TimeUnitFormat& operator=(const TimeUnitFormat& other);
    00139
    00140
    00148     virtual UBool operator==(const Format& other) const;
    00149
    00157     UBool operator!=(const Format& other) const;
    00158
    00165     void setLocale(const Locale& locale, UErrorCode& status);
    00166
    00167
    00174     void setNumberFormat(const NumberFormat& format, UErrorCode& status);
    00175
    00184     virtual UnicodeString& format(const Formattable& obj,
    00185                                   UnicodeString& toAppendTo,
    00186                                   FieldPosition& pos,
    00187                                   UErrorCode& status) const;
    00188
    00194     virtual void parseObject(const UnicodeString& source,
    00195                              Formattable& result,
    00196                              ParsePosition& pos) const;
    00197
    00209     static UClassID U_EXPORT2 getStaticClassID(void);
    00210
    00222     virtual UClassID getDynamicClassID(void) const;
    00223
    00224 private:
    00225     NumberFormat* fNumberFormat;
    00226     Locale        fLocale;
    00227     Hashtable*    fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
    00228     PluralRules*  fPluralRules;
    00229     EStyle           fStyle;
    00230
    00231     friend UBool U_CALLCONV hashTableValueComparator(UHashTok val1, UHashTok val2);
    00232
    00233     void create(const Locale& locale, EStyle style, UErrorCode& status);
    00234
    00235     // it might actually be simpler to make them Decimal Formats later.
    00236     // initialize all private data members
    00237     void setup(UErrorCode& status);
    00238
    00239     // initialize data member without fill in data for fTimeUnitToCountToPattern
    00240     void initDataMembers(UErrorCode& status);
    00241
    00242     // initialize fTimeUnitToCountToPatterns from current locale's resource.
    00243     void readFromCurrentLocale(EStyle style, const char* key, UErrorCode& status);
    00244
    00245     // check completeness of fTimeUnitToCountToPatterns against all time units,
    00246     // and all plural rules, fill in fallback as necessary.
    00247     void checkConsistency(EStyle style, const char* key, UErrorCode& status);
    00248
    00249     // fill in fTimeUnitToCountToPatterns from locale fall-back chain
    00250     void searchInLocaleChain(EStyle style, const char* key,
    00251                              TimeUnit::UTimeUnitFields field, const char*,
    00252                              const char*, Hashtable*, UErrorCode&);
    00253
    00254     // initialize hash table
    00255     Hashtable* initHash(UErrorCode& status);
    00256
    00257     // delete hash table
    00258     void deleteHash(Hashtable* htable);
    00259
    00260     // copy hash table
    00261     void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
    00262     // get time unit name, such as "year", from time unit field enum, such as
    00263     // UTIMEUNIT_YEAR.
    00264     static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
    00265 };
    00266
    00267
    00268
    00269 inline UBool
    00270 TimeUnitFormat::operator!=(const Format& other) const  {
    00271     return !operator==(other);
    00272 }
    00273
    00274
    00275
    00276 U_NAMESPACE_END
    00277
    00278 #endif /* #if !UCONFIG_NO_FORMATTING */
    00279
    00280 #endif // __TMUTFMT_H__
    00281 //eof