ICU 4.8.1.1  4.8.1.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-2011, 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 
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 
42 };
46 
47 class Hashtable;
48 
49 
81 public:
82 
88  TimeUnitFormat(UErrorCode& status);
89 
94  TimeUnitFormat(const Locale& locale, UErrorCode& status);
95 
100  TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
101 
107 
112  virtual ~TimeUnitFormat();
113 
120  virtual Format* clone(void) const;
121 
126  TimeUnitFormat& operator=(const TimeUnitFormat& other);
127 
128 
136  virtual UBool operator==(const Format& other) const;
137 
145  UBool operator!=(const Format& other) const;
146 
153  void setLocale(const Locale& locale, UErrorCode& status);
154 
155 
162  void setNumberFormat(const NumberFormat& format, UErrorCode& status);
163 
164 
165  using MeasureFormat::format;
166 
175  virtual UnicodeString& format(const Formattable& obj,
176  UnicodeString& toAppendTo,
177  FieldPosition& pos,
178  UErrorCode& status) const;
179 
185  virtual void parseObject(const UnicodeString& source,
186  Formattable& result,
187  ParsePosition& pos) const;
188 
200  static UClassID U_EXPORT2 getStaticClassID(void);
201 
213  virtual UClassID getDynamicClassID(void) const;
214 
215 private:
216  NumberFormat* fNumberFormat;
217  Locale fLocale;
218  Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
219  PluralRules* fPluralRules;
220  UTimeUnitFormatStyle fStyle;
221 
222  void create(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
223 
224  // it might actually be simpler to make them Decimal Formats later.
225  // initialize all private data members
226  void setup(UErrorCode& status);
227 
228  // initialize data member without fill in data for fTimeUnitToCountToPattern
229  void initDataMembers(UErrorCode& status);
230 
231  // initialize fTimeUnitToCountToPatterns from current locale's resource.
232  void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
233 
234  // check completeness of fTimeUnitToCountToPatterns against all time units,
235  // and all plural rules, fill in fallback as necessary.
236  void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
237 
238  // fill in fTimeUnitToCountToPatterns from locale fall-back chain
239  void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
241  const char*, Hashtable*, UErrorCode&);
242 
243  // initialize hash table
244  Hashtable* initHash(UErrorCode& status);
245 
246  // delete hash table
247  void deleteHash(Hashtable* htable);
248 
249  // copy hash table
250  void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
251  // get time unit name, such as "year", from time unit field enum, such as
252  // UTIMEUNIT_YEAR.
253  static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
254 };
255 
256 
257 
258 inline UBool
259 TimeUnitFormat::operator!=(const Format& other) const {
260  return !operator==(other);
261 }
262 
263 
264 
266 
267 #endif /* #if !UCONFIG_NO_FORMATTING */
268 
269 #endif // __TMUTFMT_H__
270 //eof
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:119
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:80
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
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:259
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:521
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:131
Abstract base class for all number formats.
Definition: numfmt.h:165
UTimeUnitFormatStyle
Constants for various styles.
Definition: tmutfmt.h:35
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
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:188
#define U_EXPORT2
Definition: platform.h:314
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_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:52
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:385
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:639
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:126
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:94
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
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:228
Format & operator=(const Format &)