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

- File List
- Globals

# tmutfmt.h

Go to the documentation of this file.

    00001 /*
    00002  *******************************************************************************
    00003  * Copyright (C) 2010, 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 class Hashtable;
    00037
    00038
    00069 class U_I18N_API TimeUnitFormat: public MeasureFormat {
    00070 public:
    00071
    00079     enum EStyle {
    00080         kFull = 0,
    00081         kAbbreviate = 1,
    00082         kTotal = kAbbreviate + 1
    00083     };
    00084
    00090     TimeUnitFormat(UErrorCode& status);
    00091
    00096     TimeUnitFormat(const Locale& locale, UErrorCode& status);
    00097
    00102     TimeUnitFormat(const Locale& locale, EStyle style, UErrorCode& status);
    00103
    00108     TimeUnitFormat(const TimeUnitFormat&);
    00109
    00114     virtual ~TimeUnitFormat();
    00115
    00122     virtual Format* clone(void) const;
    00123
    00128     TimeUnitFormat& operator=(const TimeUnitFormat& other);
    00129
    00130
    00138     virtual UBool operator==(const Format& other) const;
    00139
    00147     UBool operator!=(const Format& other) const;
    00148
    00155     void setLocale(const Locale& locale, UErrorCode& status);
    00156
    00157
    00164     void setNumberFormat(const NumberFormat& format, UErrorCode& status);
    00165
    00166
    00167     using MeasureFormat::format;
    00168
    00177     virtual UnicodeString& format(const Formattable& obj,
    00178                                   UnicodeString& toAppendTo,
    00179                                   FieldPosition& pos,
    00180                                   UErrorCode& status) const;
    00181
    00187     virtual void parseObject(const UnicodeString& source,
    00188                              Formattable& result,
    00189                              ParsePosition& pos) const;
    00190
    00202     static UClassID U_EXPORT2 getStaticClassID(void);
    00203
    00215     virtual UClassID getDynamicClassID(void) const;
    00216
    00217 private:
    00218     NumberFormat* fNumberFormat;
    00219     Locale        fLocale;
    00220     Hashtable*    fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
    00221     PluralRules*  fPluralRules;
    00222     EStyle           fStyle;
    00223
    00224     void create(const Locale& locale, EStyle style, UErrorCode& status);
    00225
    00226     // it might actually be simpler to make them Decimal Formats later.
    00227     // initialize all private data members
    00228     void setup(UErrorCode& status);
    00229
    00230     // initialize data member without fill in data for fTimeUnitToCountToPattern
    00231     void initDataMembers(UErrorCode& status);
    00232
    00233     // initialize fTimeUnitToCountToPatterns from current locale's resource.
    00234     void readFromCurrentLocale(EStyle style, const char* key, UErrorCode& status);
    00235
    00236     // check completeness of fTimeUnitToCountToPatterns against all time units,
    00237     // and all plural rules, fill in fallback as necessary.
    00238     void checkConsistency(EStyle style, const char* key, UErrorCode& status);
    00239
    00240     // fill in fTimeUnitToCountToPatterns from locale fall-back chain
    00241     void searchInLocaleChain(EStyle style, const char* key,
    00242                              TimeUnit::UTimeUnitFields field, const char*,
    00243                              const char*, Hashtable*, UErrorCode&);
    00244
    00245     // initialize hash table
    00246     Hashtable* initHash(UErrorCode& status);
    00247
    00248     // delete hash table
    00249     void deleteHash(Hashtable* htable);
    00250
    00251     // copy hash table
    00252     void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
    00253     // get time unit name, such as "year", from time unit field enum, such as
    00254     // UTIMEUNIT_YEAR.
    00255     static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
    00256 };
    00257
    00258
    00259
    00260 inline UBool
    00261 TimeUnitFormat::operator!=(const Format& other) const  {
    00262     return !operator==(other);
    00263 }
    00264
    00265
    00266
    00267 U_NAMESPACE_END
    00268
    00269 #endif /* #if !UCONFIG_NO_FORMATTING */
    00270
    00271 #endif // __TMUTFMT_H__
    00272 //eof

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines