Update readme.md
[openttd-joker.git] / lib / shared / include / unicode / tmutfmt.h
blob728ff13219a012d1c886ee98bb8d8ea183cbd18b
1 /*
2 *******************************************************************************
3 * Copyright (C) 2008-2014, Google, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 *******************************************************************************
6 */
8 #ifndef __TMUTFMT_H__
9 #define __TMUTFMT_H__
11 #include "unicode/utypes.h"
13 /**
14 * \file
15 * \brief C++ API: Format and parse duration in single time unit
19 #if !UCONFIG_NO_FORMATTING
20 #ifndef U_HIDE_DEPRECATED_API
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"
30 /**
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".
35 * @deprecated ICU 53 Use MeasureFormat and UMeasureFormatWidth instead.
37 enum UTimeUnitFormatStyle {
38 /** @deprecated ICU 53 */
39 UTMUTFMT_FULL_STYLE,
40 /** @deprecated ICU 53 */
41 UTMUTFMT_ABBREVIATED_STYLE,
42 /** @deprecated ICU 53 */
43 UTMUTFMT_FORMAT_STYLE_COUNT
45 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; /**< @deprecated ICU 53 */
48 U_NAMESPACE_BEGIN
50 class Hashtable;
51 class UVector;
53 /**
54 * Format or parse a TimeUnitAmount, using plural rules for the units where available.
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>
78 * <P>
79 * @see TimeUnitAmount
80 * @see TimeUnitFormat
81 * @deprecated ICU 53 Use the MeasureFormat class instead.
83 class U_I18N_API TimeUnitFormat: public MeasureFormat {
84 public:
86 /**
87 * Create TimeUnitFormat with default locale, and full name style.
88 * Use setLocale and/or setFormat to modify.
89 * @deprecated ICU 53
91 TimeUnitFormat(UErrorCode& status);
93 /**
94 * Create TimeUnitFormat given locale, and full name style.
95 * @deprecated ICU 53
97 TimeUnitFormat(const Locale& locale, UErrorCode& status);
99 /**
100 * Create TimeUnitFormat given locale and style.
101 * @deprecated ICU 53
103 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
106 * Copy constructor.
107 * @deprecated ICU 53
109 TimeUnitFormat(const TimeUnitFormat&);
112 * deconstructor
113 * @deprecated ICU 53
115 virtual ~TimeUnitFormat();
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.
121 * @deprecated ICU 53
123 virtual Format* clone(void) const;
126 * Assignment operator
127 * @deprecated ICU 53
129 TimeUnitFormat& operator=(const TimeUnitFormat& other);
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.
136 * @deprecated ICU 53
138 UBool operator!=(const Format& other) const;
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
144 * @deprecated ICU 53
146 void setLocale(const Locale& locale, UErrorCode& status);
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
153 * @deprecated ICU 53
155 void setNumberFormat(const NumberFormat& format, UErrorCode& status);
158 * Parse a TimeUnitAmount.
159 * @see Format#parseObject(const UnicodeString&, Formattable&, ParsePosition&) const;
160 * @deprecated ICU 53
162 virtual void parseObject(const UnicodeString& source,
163 Formattable& result,
164 ParsePosition& pos) const;
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.
175 * @deprecated ICU 53
177 static UClassID U_EXPORT2 getStaticClassID(void);
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.
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.
188 * @deprecated ICU 53
190 virtual UClassID getDynamicClassID(void) const;
192 private:
193 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
194 UTimeUnitFormatStyle fStyle;
196 void create(UTimeUnitFormatStyle style, UErrorCode& status);
198 // it might actually be simpler to make them Decimal Formats later.
199 // initialize all private data members
200 void setup(UErrorCode& status);
202 // initialize data member without fill in data for fTimeUnitToCountToPattern
203 void initDataMembers(UErrorCode& status);
205 // initialize fTimeUnitToCountToPatterns from current locale's resource.
206 void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
207 UErrorCode& status);
209 // check completeness of fTimeUnitToCountToPatterns against all time units,
210 // and all plural rules, fill in fallback as necessary.
211 void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
213 // fill in fTimeUnitToCountToPatterns from locale fall-back chain
214 void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
215 TimeUnit::UTimeUnitFields field, const UnicodeString&,
216 const char*, Hashtable*, UErrorCode&);
218 // initialize hash table
219 Hashtable* initHash(UErrorCode& status);
221 // delete hash table
222 void deleteHash(Hashtable* htable);
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);
232 inline UBool
233 TimeUnitFormat::operator!=(const Format& other) const {
234 return !operator==(other);
237 U_NAMESPACE_END
239 #endif /* U_HIDE_DEPRECATED_API */
240 #endif /* #if !UCONFIG_NO_FORMATTING */
242 #endif // __TMUTFMT_H__
243 //eof