ICU 65.1  65.1
tmutfmt.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  *******************************************************************************
5  * Copyright (C) 2008-2014, Google, International Business Machines Corporation
6  * and others. All Rights Reserved.
7  *******************************************************************************
8  */
9 
10 #ifndef __TMUTFMT_H__
11 #define __TMUTFMT_H__
12 
13 #include "unicode/utypes.h"
14 
21 #if U_SHOW_CPLUSPLUS_API
22 
23 #if !UCONFIG_NO_FORMATTING
24 
25 #include "unicode/unistr.h"
26 #include "unicode/tmunit.h"
27 #include "unicode/tmutamt.h"
28 #include "unicode/measfmt.h"
29 #include "unicode/numfmt.h"
30 #include "unicode/plurrule.h"
31 
32 #ifndef U_HIDE_DEPRECATED_API
33 
48 };
52 U_NAMESPACE_BEGIN
53 
54 class Hashtable;
55 class UVector;
56 
57 struct TimeUnitFormatReadSink;
58 
90 public:
91 
97  TimeUnitFormat(UErrorCode& status);
98 
103  TimeUnitFormat(const Locale& locale, UErrorCode& status);
104 
109  TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
110 
116 
121  virtual ~TimeUnitFormat();
122 
129  virtual TimeUnitFormat* clone() const;
130 
135  TimeUnitFormat& operator=(const TimeUnitFormat& other);
136 
144  UBool operator!=(const Format& other) const;
145 
152  void setLocale(const Locale& locale, UErrorCode& status);
153 
154 
161  void setNumberFormat(const NumberFormat& format, UErrorCode& status);
162 
168  virtual void parseObject(const UnicodeString& source,
169  Formattable& result,
170  ParsePosition& pos) const;
171 
183  static UClassID U_EXPORT2 getStaticClassID(void);
184 
196  virtual UClassID getDynamicClassID(void) const;
197 
198 private:
199  Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
200  UTimeUnitFormatStyle fStyle;
201 
202  void create(UTimeUnitFormatStyle style, UErrorCode& status);
203 
204  // it might actually be simpler to make them Decimal Formats later.
205  // initialize all private data members
206  void setup(UErrorCode& status);
207 
208  // initialize data member without fill in data for fTimeUnitToCountToPattern
209  void initDataMembers(UErrorCode& status);
210 
211  // initialize fTimeUnitToCountToPatterns from current locale's resource.
212  void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
213  UErrorCode& status);
214 
215  // check completeness of fTimeUnitToCountToPatterns against all time units,
216  // and all plural rules, fill in fallback as necessary.
217  void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
218 
219  // fill in fTimeUnitToCountToPatterns from locale fall-back chain
220  void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
222  const char*, Hashtable*, UErrorCode&);
223 
224  // initialize hash table
225  Hashtable* initHash(UErrorCode& status);
226 
227  // delete hash table
228  void deleteHash(Hashtable* htable);
229 
230  // copy hash table
231  void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
232  // get time unit name, such as "year", from time unit field enum, such as
233  // UTIMEUNIT_YEAR.
234  static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
235 
236  friend struct TimeUnitFormatReadSink;
237 };
238 
239 inline UBool
240 TimeUnitFormat::operator!=(const Format& other) const {
241  return !operator==(other);
242 }
243 
244 U_NAMESPACE_END
245 
246 #endif /* U_HIDE_DEPRECATED_API */
247 #endif /* #if !UCONFIG_NO_FORMATTING */
248 
249 #endif /* U_SHOW_CPLUSPLUS_API */
250 
251 #endif // __TMUTFMT_H__
252 //eof
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:89
Base class for all formats.
Definition: format.h:98
UTimeUnitFields
Constants for all the time units we supported.
Definition: tmunit.h:41
static UClassID getStaticClassID(void)
Return the class ID for this class.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:123
virtual void parseObject(const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const
Parse a string to produce an object.
C++ API: Unicode String.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
MeasureFormat & operator=(const MeasureFormat &rhs)
Assignment operator.
C++ API: PluralRules object.
C++ API: time unit object.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
UTimeUnitFormatStyle
Constants for various styles.
Definition: tmutfmt.h:41
One more than the highest normal UTimeUnitFields value.
Definition: tmunit.h:54
C++ API: Compatibility APIs for measure formatting.
C++ API: time unit amount object.
virtual MeasureFormat * clone() const
Clones this object polymorphically.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
Basic definitions for ICU, for both C and C++ APIs.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: tmutfmt.h:240
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
C++ API: Compatibility APIs for number formatting.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
virtual UBool operator==(const Format &other) const
Return true if given Format objects are semantically equal.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195