ICU 54.1  54.1
tmutfmt.h
Go to the documentation of this file.
1 /*
2  *******************************************************************************
3  * Copyright (C) 2008-2014, Google, International Business Machines Corporation
4  * and others. All Rights Reserved.
5  *******************************************************************************
6  */
7 
8 #ifndef __TMUTFMT_H__
9 #define __TMUTFMT_H__
10 
11 #include "unicode/utypes.h"
12 
19 #if !UCONFIG_NO_FORMATTING
20 #ifndef U_HIDE_DEPRECATED_API
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 
29 
44 };
49 
50 class Hashtable;
51 class UVector;
52 
84 public:
85 
91  TimeUnitFormat(UErrorCode& status);
92 
97  TimeUnitFormat(const Locale& locale, UErrorCode& status);
98 
103  TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
104 
110 
115  virtual ~TimeUnitFormat();
116 
123  virtual Format* clone(void) const;
124 
129  TimeUnitFormat& operator=(const TimeUnitFormat& other);
130 
138  UBool operator!=(const Format& other) const;
139 
146  void setLocale(const Locale& locale, UErrorCode& status);
147 
148 
155  void setNumberFormat(const NumberFormat& format, UErrorCode& status);
156 
162  virtual void parseObject(const UnicodeString& source,
163  Formattable& result,
164  ParsePosition& pos) const;
165 
177  static UClassID U_EXPORT2 getStaticClassID(void);
178 
190  virtual UClassID getDynamicClassID(void) const;
191 
192 private:
193  Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
194  UTimeUnitFormatStyle fStyle;
195 
196  void create(UTimeUnitFormatStyle style, UErrorCode& status);
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.
206  void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
207  UErrorCode& status);
208 
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);
212 
213  // fill in fTimeUnitToCountToPatterns from locale fall-back chain
214  void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
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);
229 
230 };
231 
232 inline UBool
233 TimeUnitFormat::operator!=(const Format& other) const {
234  return !operator==(other);
235 }
236 
238 
239 #endif /* U_HIDE_DEPRECATED_API */
240 #endif /* #if !UCONFIG_NO_FORMATTING */
241 
242 #endif // __TMUTFMT_H__
243 //eof
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:83
Base class for all formats.
Definition: format.h:94
UTimeUnitFields
Constants for all the time units we supported.
Definition: tmunit.h:36
static UClassID getStaticClassID(void)
Return the class ID for this class.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
A formatter for measure objects.
Definition: measfmt.h:95
Abstract base class for all number formats.
Definition: numfmt.h:172
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
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:358
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
UTimeUnitFormatStyle
Constants for various styles.
Definition: tmutfmt.h:37
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
C++ API: Formatter for measure objects.
virtual Format * clone() const
Clones this object polymorphically.
C++ API: time unit amount object.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
virtual void parseObject(const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const
Parse a string to produce an object.
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: format.h:119
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:245
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
C++ API: Abstract base class for all number formats.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185