ICU 50.1.2  50.1.2
tmutfmt.h
Go to the documentation of this file.
1 /*
2  *******************************************************************************
3  * Copyright (C) 2008-2012, 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 class UVector;
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, const UVector& pluralCounts,
233  UErrorCode& status);
234 
235  // check completeness of fTimeUnitToCountToPatterns against all time units,
236  // and all plural rules, fill in fallback as necessary.
237  void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
238 
239  // fill in fTimeUnitToCountToPatterns from locale fall-back chain
240  void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
242  const char*, Hashtable*, UErrorCode&);
243 
244  // initialize hash table
245  Hashtable* initHash(UErrorCode& status);
246 
247  // delete hash table
248  void deleteHash(Hashtable* htable);
249 
250  // copy hash table
251  void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
252  // get time unit name, such as "year", from time unit field enum, such as
253  // UTIMEUNIT_YEAR.
254  static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
255 };
256 
257 
258 
259 inline UBool
260 TimeUnitFormat::operator!=(const Format& other) const {
261  return !operator==(other);
262 }
263 
264 
265 
267 
268 #endif /* #if !UCONFIG_NO_FORMATTING */
269 
270 #endif // __TMUTFMT_H__
271 //eof
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:80
Base class for all formats.
Definition: format.h:94
UTimeUnitFields
Constants for all the time units we supported.
Definition: tmunit.h:36
A formatter for measure objects.
Definition: measfmt.h:41
Abstract base class for all number formats.
Definition: numfmt.h:166
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
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:96
virtual Format * clone() const =0
Clone this object polymorphically.
C++ API: PluralRules object.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:127
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:35
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
C++ API: Formatter for measure objects.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
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
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Basic definitions for ICU, for both C and C++ APIs.
Format & operator=(const Format &)
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:246
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
C++ API: Abstract base class for all number formats.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:182