jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * Copyright (C) 2008-2014, Google, International Business Machines Corporation jpayne@69: * and others. All Rights Reserved. jpayne@69: ******************************************************************************* jpayne@69: */ jpayne@69: jpayne@69: #ifndef __TMUTFMT_H__ jpayne@69: #define __TMUTFMT_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Format and parse duration in single time unit jpayne@69: */ jpayne@69: jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/unistr.h" jpayne@69: #include "unicode/tmunit.h" jpayne@69: #include "unicode/tmutamt.h" jpayne@69: #include "unicode/measfmt.h" jpayne@69: #include "unicode/numfmt.h" jpayne@69: #include "unicode/plurrule.h" jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * Constants for various styles. jpayne@69: * There are 2 styles: full name and abbreviated name. jpayne@69: * For example, for English, the full name for hour duration is "3 hours", jpayne@69: * and the abbreviated name is "3 hrs". jpayne@69: * @deprecated ICU 53 Use MeasureFormat and UMeasureFormatWidth instead. jpayne@69: */ jpayne@69: enum UTimeUnitFormatStyle { jpayne@69: /** @deprecated ICU 53 */ jpayne@69: UTMUTFMT_FULL_STYLE, jpayne@69: /** @deprecated ICU 53 */ jpayne@69: UTMUTFMT_ABBREVIATED_STYLE, jpayne@69: /** @deprecated ICU 53 */ jpayne@69: UTMUTFMT_FORMAT_STYLE_COUNT jpayne@69: }; jpayne@69: typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; /**< @deprecated ICU 53 */ jpayne@69: jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class Hashtable; jpayne@69: class UVector; jpayne@69: jpayne@69: struct TimeUnitFormatReadSink; jpayne@69: jpayne@69: /** jpayne@69: * Format or parse a TimeUnitAmount, using plural rules for the units where available. jpayne@69: * jpayne@69: *

jpayne@69: * Code Sample: jpayne@69: *

jpayne@69:  *   // create time unit amount instance - a combination of Number and time unit
jpayne@69:  *   UErrorCode status = U_ZERO_ERROR;
jpayne@69:  *   TimeUnitAmount* source = new TimeUnitAmount(2, TimeUnit::UTIMEUNIT_YEAR, status);
jpayne@69:  *   // create time unit format instance
jpayne@69:  *   TimeUnitFormat* format = new TimeUnitFormat(Locale("en"), status);
jpayne@69:  *   // format a time unit amount
jpayne@69:  *   UnicodeString formatted;
jpayne@69:  *   Formattable formattable;
jpayne@69:  *   if (U_SUCCESS(status)) {
jpayne@69:  *       formattable.adoptObject(source);
jpayne@69:  *       formatted = ((Format*)format)->format(formattable, formatted, status);
jpayne@69:  *       Formattable result;
jpayne@69:  *       ((Format*)format)->parseObject(formatted, result, status);
jpayne@69:  *       if (U_SUCCESS(status)) {
jpayne@69:  *           assert (result == formattable);
jpayne@69:  *       }
jpayne@69:  *   }
jpayne@69:  * 
jpayne@69: * jpayne@69: *

jpayne@69: * @see TimeUnitAmount jpayne@69: * @see TimeUnitFormat jpayne@69: * @deprecated ICU 53 Use the MeasureFormat class instead. jpayne@69: */ jpayne@69: class U_I18N_API TimeUnitFormat: public MeasureFormat { jpayne@69: public: jpayne@69: jpayne@69: /** jpayne@69: * Create TimeUnitFormat with default locale, and full name style. jpayne@69: * Use setLocale and/or setFormat to modify. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: TimeUnitFormat(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create TimeUnitFormat given locale, and full name style. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: TimeUnitFormat(const Locale& locale, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create TimeUnitFormat given locale and style. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: TimeUnitFormat(const TimeUnitFormat&); jpayne@69: jpayne@69: /** jpayne@69: * deconstructor jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: virtual ~TimeUnitFormat(); jpayne@69: jpayne@69: /** jpayne@69: * Clone this Format object polymorphically. The caller owns the result and jpayne@69: * should delete it when done. jpayne@69: * @return A copy of the object. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: virtual TimeUnitFormat* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: TimeUnitFormat& operator=(const TimeUnitFormat& other); jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given Format objects are not semantically equal. jpayne@69: * Objects of different subclasses are considered unequal. jpayne@69: * @param other the object to be compared with. jpayne@69: * @return true if the given Format objects are not semantically equal. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: UBool operator!=(const Format& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the locale used for formatting or parsing. jpayne@69: * @param locale the locale to be set jpayne@69: * @param status output param set to success/failure code on exit jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: void setLocale(const Locale& locale, UErrorCode& status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Set the number format used for formatting or parsing. jpayne@69: * @param format the number formatter to be set jpayne@69: * @param status output param set to success/failure code on exit jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: void setNumberFormat(const NumberFormat& format, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Parse a TimeUnitAmount. jpayne@69: * @see Format#parseObject(const UnicodeString&, Formattable&, ParsePosition&) const; jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: virtual void parseObject(const UnicodeString& source, jpayne@69: Formattable& result, jpayne@69: ParsePosition& pos) const; jpayne@69: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for comparing to jpayne@69: * a return value from getDynamicClassID(). For example: jpayne@69: *

jpayne@69:      * .   Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * .   if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      * .       erived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This jpayne@69: * method is to implement a simple version of RTTI, since not all C++ jpayne@69: * compilers support genuine RTTI. Polymorphic operator==() and clone() jpayne@69: * methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @deprecated ICU 53 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: jpayne@69: private: jpayne@69: Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT]; jpayne@69: UTimeUnitFormatStyle fStyle; jpayne@69: jpayne@69: void create(UTimeUnitFormatStyle style, UErrorCode& status); jpayne@69: jpayne@69: // it might actually be simpler to make them Decimal Formats later. jpayne@69: // initialize all private data members jpayne@69: void setup(UErrorCode& status); jpayne@69: jpayne@69: // initialize data member without fill in data for fTimeUnitToCountToPattern jpayne@69: void initDataMembers(UErrorCode& status); jpayne@69: jpayne@69: // initialize fTimeUnitToCountToPatterns from current locale's resource. jpayne@69: void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: // check completeness of fTimeUnitToCountToPatterns against all time units, jpayne@69: // and all plural rules, fill in fallback as necessary. jpayne@69: void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status); jpayne@69: jpayne@69: // fill in fTimeUnitToCountToPatterns from locale fall-back chain jpayne@69: void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName, jpayne@69: TimeUnit::UTimeUnitFields field, const UnicodeString&, jpayne@69: const char*, Hashtable*, UErrorCode&); jpayne@69: jpayne@69: // initialize hash table jpayne@69: Hashtable* initHash(UErrorCode& status); jpayne@69: jpayne@69: // delete hash table jpayne@69: void deleteHash(Hashtable* htable); jpayne@69: jpayne@69: // copy hash table jpayne@69: void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); jpayne@69: // get time unit name, such as "year", from time unit field enum, such as jpayne@69: // UTIMEUNIT_YEAR. jpayne@69: static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status); jpayne@69: jpayne@69: friend struct TimeUnitFormatReadSink; jpayne@69: }; jpayne@69: jpayne@69: inline UBool jpayne@69: TimeUnitFormat::operator!=(const Format& other) const { jpayne@69: return !operator==(other); jpayne@69: } jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // __TMUTFMT_H__ jpayne@69: //eof