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