]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
729e4ab9 A |
3 | /* |
4 | ******************************************************************************* | |
57a6839d | 5 | * Copyright (C) 2008-2014, Google, International Business Machines Corporation |
4388f060 | 6 | * and others. All Rights Reserved. |
729e4ab9 A |
7 | ******************************************************************************* |
8 | */ | |
9 | ||
10 | #ifndef __TMUTFMT_H__ | |
11 | #define __TMUTFMT_H__ | |
12 | ||
13 | #include "unicode/utypes.h" | |
14 | ||
15 | /** | |
16 | * \file | |
17 | * \brief C++ API: Format and parse duration in single time unit | |
18 | */ | |
19 | ||
20 | ||
21 | #if !UCONFIG_NO_FORMATTING | |
b331163b | 22 | #ifndef U_HIDE_DEPRECATED_API |
729e4ab9 A |
23 | |
24 | #include "unicode/unistr.h" | |
25 | #include "unicode/tmunit.h" | |
26 | #include "unicode/tmutamt.h" | |
27 | #include "unicode/measfmt.h" | |
28 | #include "unicode/numfmt.h" | |
29 | #include "unicode/plurrule.h" | |
30 | ||
57a6839d | 31 | |
729e4ab9 | 32 | /** |
4388f060 A |
33 | * Constants for various styles. |
34 | * There are 2 styles: full name and abbreviated name. | |
35 | * For example, for English, the full name for hour duration is "3 hours", | |
36 | * and the abbreviated name is "3 hrs". | |
57a6839d | 37 | * @deprecated ICU 53 Use MeasureFormat and UMeasureFormatWidth instead. |
729e4ab9 | 38 | */ |
4388f060 | 39 | enum UTimeUnitFormatStyle { |
57a6839d | 40 | /** @deprecated ICU 53 */ |
4388f060 | 41 | UTMUTFMT_FULL_STYLE, |
57a6839d | 42 | /** @deprecated ICU 53 */ |
4388f060 | 43 | UTMUTFMT_ABBREVIATED_STYLE, |
57a6839d | 44 | /** @deprecated ICU 53 */ |
4388f060 A |
45 | UTMUTFMT_FORMAT_STYLE_COUNT |
46 | }; | |
57a6839d A |
47 | typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; /**< @deprecated ICU 53 */ |
48 | ||
729e4ab9 | 49 | |
f3c0d7a5 | 50 | #if U_SHOW_CPLUSPLUS_API |
729e4ab9 A |
51 | U_NAMESPACE_BEGIN |
52 | ||
53 | class Hashtable; | |
51004dcb | 54 | class UVector; |
729e4ab9 | 55 | |
f3c0d7a5 A |
56 | struct TimeUnitFormatReadSink; |
57 | ||
729e4ab9 A |
58 | /** |
59 | * Format or parse a TimeUnitAmount, using plural rules for the units where available. | |
60 | * | |
61 | * <P> | |
62 | * Code Sample: | |
63 | * <pre> | |
64 | * // create time unit amount instance - a combination of Number and time unit | |
65 | * UErrorCode status = U_ZERO_ERROR; | |
66 | * TimeUnitAmount* source = new TimeUnitAmount(2, TimeUnit::UTIMEUNIT_YEAR, status); | |
67 | * // create time unit format instance | |
68 | * TimeUnitFormat* format = new TimeUnitFormat(Locale("en"), status); | |
69 | * // format a time unit amount | |
70 | * UnicodeString formatted; | |
71 | * Formattable formattable; | |
72 | * if (U_SUCCESS(status)) { | |
73 | * formattable.adoptObject(source); | |
74 | * formatted = ((Format*)format)->format(formattable, formatted, status); | |
75 | * Formattable result; | |
76 | * ((Format*)format)->parseObject(formatted, result, status); | |
77 | * if (U_SUCCESS(status)) { | |
78 | * assert (result == formattable); | |
79 | * } | |
80 | * } | |
81 | * </pre> | |
82 | * | |
83 | * <P> | |
84 | * @see TimeUnitAmount | |
85 | * @see TimeUnitFormat | |
57a6839d | 86 | * @deprecated ICU 53 Use the MeasureFormat class instead. |
729e4ab9 A |
87 | */ |
88 | class U_I18N_API TimeUnitFormat: public MeasureFormat { | |
89 | public: | |
90 | ||
729e4ab9 A |
91 | /** |
92 | * Create TimeUnitFormat with default locale, and full name style. | |
93 | * Use setLocale and/or setFormat to modify. | |
b331163b | 94 | * @deprecated ICU 53 |
729e4ab9 A |
95 | */ |
96 | TimeUnitFormat(UErrorCode& status); | |
97 | ||
98 | /** | |
99 | * Create TimeUnitFormat given locale, and full name style. | |
b331163b | 100 | * @deprecated ICU 53 |
729e4ab9 A |
101 | */ |
102 | TimeUnitFormat(const Locale& locale, UErrorCode& status); | |
103 | ||
104 | /** | |
105 | * Create TimeUnitFormat given locale and style. | |
b331163b | 106 | * @deprecated ICU 53 |
729e4ab9 | 107 | */ |
4388f060 | 108 | TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status); |
729e4ab9 A |
109 | |
110 | /** | |
111 | * Copy constructor. | |
b331163b | 112 | * @deprecated ICU 53 |
729e4ab9 A |
113 | */ |
114 | TimeUnitFormat(const TimeUnitFormat&); | |
115 | ||
116 | /** | |
117 | * deconstructor | |
b331163b | 118 | * @deprecated ICU 53 |
729e4ab9 A |
119 | */ |
120 | virtual ~TimeUnitFormat(); | |
121 | ||
122 | /** | |
123 | * Clone this Format object polymorphically. The caller owns the result and | |
124 | * should delete it when done. | |
125 | * @return A copy of the object. | |
b331163b | 126 | * @deprecated ICU 53 |
729e4ab9 A |
127 | */ |
128 | virtual Format* clone(void) const; | |
129 | ||
130 | /** | |
131 | * Assignment operator | |
b331163b | 132 | * @deprecated ICU 53 |
729e4ab9 A |
133 | */ |
134 | TimeUnitFormat& operator=(const TimeUnitFormat& other); | |
135 | ||
729e4ab9 A |
136 | /** |
137 | * Return true if the given Format objects are not semantically equal. | |
138 | * Objects of different subclasses are considered unequal. | |
139 | * @param other the object to be compared with. | |
140 | * @return true if the given Format objects are not semantically equal. | |
b331163b | 141 | * @deprecated ICU 53 |
729e4ab9 A |
142 | */ |
143 | UBool operator!=(const Format& other) const; | |
144 | ||
145 | /** | |
146 | * Set the locale used for formatting or parsing. | |
147 | * @param locale the locale to be set | |
148 | * @param status output param set to success/failure code on exit | |
b331163b | 149 | * @deprecated ICU 53 |
729e4ab9 A |
150 | */ |
151 | void setLocale(const Locale& locale, UErrorCode& status); | |
152 | ||
153 | ||
154 | /** | |
155 | * Set the number format used for formatting or parsing. | |
156 | * @param format the number formatter to be set | |
157 | * @param status output param set to success/failure code on exit | |
b331163b | 158 | * @deprecated ICU 53 |
729e4ab9 A |
159 | */ |
160 | void setNumberFormat(const NumberFormat& format, UErrorCode& status); | |
161 | ||
729e4ab9 A |
162 | /** |
163 | * Parse a TimeUnitAmount. | |
164 | * @see Format#parseObject(const UnicodeString&, Formattable&, ParsePosition&) const; | |
b331163b | 165 | * @deprecated ICU 53 |
729e4ab9 A |
166 | */ |
167 | virtual void parseObject(const UnicodeString& source, | |
168 | Formattable& result, | |
169 | ParsePosition& pos) const; | |
170 | ||
171 | /** | |
172 | * Return the class ID for this class. This is useful only for comparing to | |
173 | * a return value from getDynamicClassID(). For example: | |
174 | * <pre> | |
175 | * . Base* polymorphic_pointer = createPolymorphicObject(); | |
176 | * . if (polymorphic_pointer->getDynamicClassID() == | |
177 | * . erived::getStaticClassID()) ... | |
178 | * </pre> | |
179 | * @return The class ID for all objects of this class. | |
b331163b | 180 | * @deprecated ICU 53 |
729e4ab9 A |
181 | */ |
182 | static UClassID U_EXPORT2 getStaticClassID(void); | |
183 | ||
184 | /** | |
185 | * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This | |
186 | * method is to implement a simple version of RTTI, since not all C++ | |
187 | * compilers support genuine RTTI. Polymorphic operator==() and clone() | |
188 | * methods call this method. | |
189 | * | |
190 | * @return The class ID for this object. All objects of a | |
191 | * given class have the same class ID. Objects of | |
192 | * other classes have different class IDs. | |
b331163b | 193 | * @deprecated ICU 53 |
729e4ab9 A |
194 | */ |
195 | virtual UClassID getDynamicClassID(void) const; | |
196 | ||
197 | private: | |
729e4ab9 | 198 | Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT]; |
4388f060 | 199 | UTimeUnitFormatStyle fStyle; |
729e4ab9 | 200 | |
57a6839d | 201 | void create(UTimeUnitFormatStyle style, UErrorCode& status); |
729e4ab9 A |
202 | |
203 | // it might actually be simpler to make them Decimal Formats later. | |
204 | // initialize all private data members | |
205 | void setup(UErrorCode& status); | |
206 | ||
207 | // initialize data member without fill in data for fTimeUnitToCountToPattern | |
208 | void initDataMembers(UErrorCode& status); | |
209 | ||
210 | // initialize fTimeUnitToCountToPatterns from current locale's resource. | |
51004dcb A |
211 | void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts, |
212 | UErrorCode& status); | |
729e4ab9 A |
213 | |
214 | // check completeness of fTimeUnitToCountToPatterns against all time units, | |
215 | // and all plural rules, fill in fallback as necessary. | |
4388f060 | 216 | void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status); |
729e4ab9 A |
217 | |
218 | // fill in fTimeUnitToCountToPatterns from locale fall-back chain | |
4388f060 A |
219 | void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName, |
220 | TimeUnit::UTimeUnitFields field, const UnicodeString&, | |
729e4ab9 A |
221 | const char*, Hashtable*, UErrorCode&); |
222 | ||
223 | // initialize hash table | |
224 | Hashtable* initHash(UErrorCode& status); | |
225 | ||
226 | // delete hash table | |
227 | void deleteHash(Hashtable* htable); | |
228 | ||
229 | // copy hash table | |
230 | void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); | |
231 | // get time unit name, such as "year", from time unit field enum, such as | |
232 | // UTIMEUNIT_YEAR. | |
233 | static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status); | |
729e4ab9 | 234 | |
f3c0d7a5 | 235 | friend struct TimeUnitFormatReadSink; |
57a6839d | 236 | }; |
729e4ab9 A |
237 | |
238 | inline UBool | |
239 | TimeUnitFormat::operator!=(const Format& other) const { | |
240 | return !operator==(other); | |
241 | } | |
242 | ||
729e4ab9 | 243 | U_NAMESPACE_END |
f3c0d7a5 | 244 | #endif // U_SHOW_CPLUSPLUS_API |
729e4ab9 | 245 | |
b331163b | 246 | #endif /* U_HIDE_DEPRECATED_API */ |
729e4ab9 A |
247 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
248 | ||
249 | #endif // __TMUTFMT_H__ | |
250 | //eof |