Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/tmutfmt.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004  *******************************************************************************
0005  * Copyright (C) 2008-2014, Google, International Business Machines Corporation
0006  * and others. All Rights Reserved.
0007  *******************************************************************************
0008  */
0009 
0010 #ifndef __TMUTFMT_H__
0011 #define __TMUTFMT_H__
0012 
0013 #include "unicode/utypes.h"
0014 
0015 /**
0016  * \file
0017  * \brief C++ API: Format and parse duration in single time unit
0018  */
0019 
0020 
0021 #if U_SHOW_CPLUSPLUS_API
0022 
0023 #if !UCONFIG_NO_FORMATTING
0024 
0025 #include "unicode/unistr.h"
0026 #include "unicode/tmunit.h"
0027 #include "unicode/tmutamt.h"
0028 #include "unicode/measfmt.h"
0029 #include "unicode/numfmt.h"
0030 #include "unicode/plurrule.h"
0031 
0032 #ifndef U_HIDE_DEPRECATED_API
0033 
0034 /**
0035  * Constants for various styles.
0036  * There are 2 styles: full name and abbreviated name.
0037  * For example, for English, the full name for hour duration is "3 hours",
0038  * and the abbreviated name is "3 hrs".
0039  * @deprecated ICU 53 Use MeasureFormat and UMeasureFormatWidth instead.
0040  */
0041 enum UTimeUnitFormatStyle {
0042     /** @deprecated ICU 53 */
0043     UTMUTFMT_FULL_STYLE,
0044     /** @deprecated ICU 53 */
0045     UTMUTFMT_ABBREVIATED_STYLE,
0046     /** @deprecated ICU 53 */
0047     UTMUTFMT_FORMAT_STYLE_COUNT
0048 };
0049 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; /**< @deprecated ICU 53 */
0050 
0051 
0052 U_NAMESPACE_BEGIN
0053 
0054 class Hashtable;
0055 class UVector;
0056 
0057 struct TimeUnitFormatReadSink;
0058 
0059 /**
0060  * Format or parse a TimeUnitAmount, using plural rules for the units where available.
0061  *
0062  * <P>
0063  * Code Sample:
0064  * <pre>
0065  *   // create time unit amount instance - a combination of Number and time unit
0066  *   UErrorCode status = U_ZERO_ERROR;
0067  *   TimeUnitAmount* source = new TimeUnitAmount(2, TimeUnit::UTIMEUNIT_YEAR, status);
0068  *   // create time unit format instance
0069  *   TimeUnitFormat* format = new TimeUnitFormat(Locale("en"), status);
0070  *   // format a time unit amount
0071  *   UnicodeString formatted;
0072  *   Formattable formattable;
0073  *   if (U_SUCCESS(status)) {
0074  *       formattable.adoptObject(source);
0075  *       formatted = ((Format*)format)->format(formattable, formatted, status);
0076  *       Formattable result;
0077  *       ((Format*)format)->parseObject(formatted, result, status);
0078  *       if (U_SUCCESS(status)) {
0079  *           assert (result == formattable);
0080  *       }
0081  *   }
0082  * </pre>
0083  *
0084  * <P>
0085  * @see TimeUnitAmount
0086  * @see TimeUnitFormat
0087  * @deprecated ICU 53 Use the MeasureFormat class instead.
0088  */
0089 class U_I18N_API TimeUnitFormat: public MeasureFormat {
0090 public:
0091 
0092     /**
0093      * Create TimeUnitFormat with default locale, and full name style.
0094      * Use setLocale and/or setFormat to modify.
0095      * @deprecated ICU 53
0096      */
0097     TimeUnitFormat(UErrorCode& status);
0098 
0099     /**
0100      * Create TimeUnitFormat given locale, and full name style.
0101      * @deprecated ICU 53
0102      */
0103     TimeUnitFormat(const Locale& locale, UErrorCode& status);
0104 
0105     /**
0106      * Create TimeUnitFormat given locale and style.
0107      * @deprecated ICU 53
0108      */
0109     TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
0110 
0111     /**
0112      * Copy constructor.
0113      * @deprecated ICU 53
0114      */
0115     TimeUnitFormat(const TimeUnitFormat&);
0116 
0117     /**
0118      * deconstructor
0119      * @deprecated ICU 53
0120      */
0121     virtual ~TimeUnitFormat();
0122 
0123     /**
0124      * Clone this Format object polymorphically. The caller owns the result and
0125      * should delete it when done.
0126      * @return    A copy of the object.
0127      * @deprecated ICU 53
0128      */
0129     virtual TimeUnitFormat* clone() const override;
0130 
0131     /**
0132      * Assignment operator
0133      * @deprecated ICU 53
0134      */
0135     TimeUnitFormat& operator=(const TimeUnitFormat& other);
0136 
0137     /**
0138      * Set the locale used for formatting or parsing.
0139      * @param locale  the locale to be set
0140      * @param status  output param set to success/failure code on exit
0141      * @deprecated ICU 53
0142      */
0143     void setLocale(const Locale& locale, UErrorCode& status);
0144 
0145 
0146     /**
0147      * Set the number format used for formatting or parsing.
0148      * @param format  the number formatter to be set
0149      * @param status  output param set to success/failure code on exit
0150      * @deprecated ICU 53
0151      */
0152     void setNumberFormat(const NumberFormat& format, UErrorCode& status);
0153 
0154     /**
0155      * Parse a TimeUnitAmount.
0156      * @see Format#parseObject(const UnicodeString&, Formattable&, ParsePosition&) const;
0157      * @deprecated ICU 53
0158      */
0159     virtual void parseObject(const UnicodeString& source,
0160                              Formattable& result,
0161                              ParsePosition& pos) const override;
0162 
0163     /**
0164      * Return the class ID for this class. This is useful only for comparing to
0165      * a return value from getDynamicClassID(). For example:
0166      * <pre>
0167      * .   Base* polymorphic_pointer = createPolymorphicObject();
0168      * .   if (polymorphic_pointer->getDynamicClassID() ==
0169      * .       erived::getStaticClassID()) ...
0170      * </pre>
0171      * @return          The class ID for all objects of this class.
0172      * @deprecated ICU 53
0173      */
0174     static UClassID U_EXPORT2 getStaticClassID(void);
0175 
0176     /**
0177      * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
0178      * method is to implement a simple version of RTTI, since not all C++
0179      * compilers support genuine RTTI. Polymorphic operator==() and clone()
0180      * methods call this method.
0181      *
0182      * @return          The class ID for this object. All objects of a
0183      *                  given class have the same class ID.  Objects of
0184      *                  other classes have different class IDs.
0185      * @deprecated ICU 53
0186      */
0187     virtual UClassID getDynamicClassID(void) const override;
0188 
0189 private:
0190     Hashtable*    fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
0191     UTimeUnitFormatStyle fStyle;
0192 
0193     void create(UTimeUnitFormatStyle style, UErrorCode& status);
0194 
0195     // it might actually be simpler to make them Decimal Formats later.
0196     // initialize all private data members
0197     void setup(UErrorCode& status);
0198 
0199     // initialize data member without fill in data for fTimeUnitToCountToPattern
0200     void initDataMembers(UErrorCode& status);
0201 
0202     // initialize fTimeUnitToCountToPatterns from current locale's resource.
0203     void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
0204                                UErrorCode& status);
0205 
0206     // check completeness of fTimeUnitToCountToPatterns against all time units,
0207     // and all plural rules, fill in fallback as necessary.
0208     void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
0209 
0210     // fill in fTimeUnitToCountToPatterns from locale fall-back chain
0211     void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
0212                              TimeUnit::UTimeUnitFields field, const UnicodeString&,
0213                              const char*, Hashtable*, UErrorCode&);
0214 
0215     // initialize hash table
0216     Hashtable* initHash(UErrorCode& status);
0217 
0218     // delete hash table
0219     void deleteHash(Hashtable* htable);
0220 
0221     // copy hash table
0222     void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
0223     // get time unit name, such as "year", from time unit field enum, such as
0224     // UTIMEUNIT_YEAR.
0225     static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
0226 
0227     friend struct TimeUnitFormatReadSink;
0228 };
0229 
0230 U_NAMESPACE_END
0231 
0232 #endif /* U_HIDE_DEPRECATED_API */
0233 #endif /* #if !UCONFIG_NO_FORMATTING */
0234 
0235 #endif /* U_SHOW_CPLUSPLUS_API */
0236 
0237 #endif // __TMUTFMT_H__
0238 //eof