ICU 4.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tmutfmt.h
Go to the documentation of this file.
1 /*
2  *******************************************************************************
3  * Copyright (C) 2008, Google, International Business Machines Corporation and *
4  * 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 
21 #include "unicode/unistr.h"
22 #include "unicode/tmunit.h"
23 #include "unicode/tmutamt.h"
24 #include "unicode/measfmt.h"
25 #include "unicode/numfmt.h"
26 #include "unicode/plurrule.h"
27 
32 union UHashTok;
33 
35 
37 
41 static UBool U_CALLCONV hashTableValueComparator(UHashTok val1, UHashTok val2) ;
42 
44 
45 
46 class Hashtable;
47 
48 
80 public:
81 
89  enum EStyle {
90  kFull = 0,
91  kAbbreviate = 1,
92  kTotal = kAbbreviate + 1
93  };
94 
100  TimeUnitFormat(UErrorCode& status);
101 
106  TimeUnitFormat(const Locale& locale, UErrorCode& status);
107 
112  TimeUnitFormat(const Locale& locale, EStyle style, UErrorCode& status);
113 
119 
124  virtual ~TimeUnitFormat();
125 
132  virtual Format* clone(void) const;
133 
138  TimeUnitFormat& operator=(const TimeUnitFormat& other);
139 
140 
148  virtual UBool operator==(const Format& other) const;
149 
157  UBool operator!=(const Format& other) const;
158 
165  void setLocale(const Locale& locale, UErrorCode& status);
166 
167 
174  void setNumberFormat(const NumberFormat& format, UErrorCode& status);
175 
184  virtual UnicodeString& format(const Formattable& obj,
185  UnicodeString& toAppendTo,
186  FieldPosition& pos,
187  UErrorCode& status) const;
188 
194  virtual void parseObject(const UnicodeString& source,
195  Formattable& result,
196  ParsePosition& pos) const;
197 
209  static UClassID U_EXPORT2 getStaticClassID(void);
210 
222  virtual UClassID getDynamicClassID(void) const;
223 
224 private:
225  NumberFormat* fNumberFormat;
226  Locale fLocale;
227  Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
228  PluralRules* fPluralRules;
229  EStyle fStyle;
230 
231  friend UBool U_CALLCONV hashTableValueComparator(UHashTok val1, UHashTok val2);
232 
233  void create(const Locale& locale, EStyle style, UErrorCode& status);
234 
235  // it might actually be simpler to make them Decimal Formats later.
236  // initialize all private data members
237  void setup(UErrorCode& status);
238 
239  // initialize data member without fill in data for fTimeUnitToCountToPattern
240  void initDataMembers(UErrorCode& status);
241 
242  // initialize fTimeUnitToCountToPatterns from current locale's resource.
243  void readFromCurrentLocale(EStyle style, const char* key, UErrorCode& status);
244 
245  // check completeness of fTimeUnitToCountToPatterns against all time units,
246  // and all plural rules, fill in fallback as necessary.
247  void checkConsistency(EStyle style, const char* key, UErrorCode& status);
248 
249  // fill in fTimeUnitToCountToPatterns from locale fall-back chain
250  void searchInLocaleChain(EStyle style, const char* key,
251  TimeUnit::UTimeUnitFields field, const char*,
252  const char*, Hashtable*, UErrorCode&);
253 
254  // initialize hash table
255  Hashtable* initHash(UErrorCode& status);
256 
257  // delete hash table
258  void deleteHash(Hashtable* htable);
259 
260  // copy hash table
261  void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
262  // get time unit name, such as "year", from time unit field enum, such as
263  // UTIMEUNIT_YEAR.
264  static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
265 };
266 
267 
268 
269 inline UBool
270 TimeUnitFormat::operator!=(const Format& other) const {
271  return !operator==(other);
272 }
273 
274 
275 
277 
278 #endif /* #if !UCONFIG_NO_FORMATTING */
279 
280 #endif // __TMUTFMT_H__
281 //eof
virtual UClassID getDynamicClassID() const =0
Returns a unique class ID POLYMORPHICALLY.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:118
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:79
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: utypes.h:254
C++ API: Unicode String.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: tmutfmt.h:270
C++ API: PluralRules object.
C++ API: time unit object.
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:101
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:475
A formatter for measure objects.
Definition: measfmt.h:41
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:183
Abstract base class for all number formats.
Definition: numfmt.h:162
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
EStyle
Constants for various styles.
Definition: tmutfmt.h:89
C++ API: Formatter for measure objects.
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:187
#define U_EXPORT2
Definition: platform.h:338
UTimeUnitFields
Constants for all the time units we supported.
Definition: tmunit.h:36
virtual Format * clone() const =0
Clone this object polymorphically.
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
C++ API: time unit amount object.
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:102
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:47
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:339
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:593
Defines rules for mapping positive long values onto a small set of keywords.
Definition: plurrule.h:104
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
Base class for all formats.
Definition: format.h:93
Basic definitions for ICU, for both C and C++ APIs.
C++ API: Abstract base class for all number formats.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:181
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208
Format & operator=(const Format &)