ICU 50.2 50.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
17
18
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
44
46
47class Hashtable;
48class UVector;
49
81public:
82
89
94 TimeUnitFormat(const Locale& locale, UErrorCode& status);
95
100 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
101
107
113
120 virtual Format* clone(void) const;
121
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
163
164
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
215private:
216 NumberFormat* fNumberFormat;
217 Locale fLocale;
218 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
219 PluralRules* fPluralRules;
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
259inline UBool
261 return !operator==(other);
262}
263
264
265
267
268#endif /* #if !UCONFIG_NO_FORMATTING */
269
270#endif // __TMUTFMT_H__
271//eof
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Format()
Default constructor for subclass use only.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition format.h:119
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
MeasureFormat()
Default constructor.
Abstract base class for all number formats.
Definition numfmt.h:166
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition plurrule.h:127
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &pos) const
Parse a TimeUnitAmount.
TimeUnitFormat & operator=(const TimeUnitFormat &other)
Assignment operator.
static UClassID getStaticClassID(void)
Return the class ID for this class.
TimeUnitFormat(const Locale &locale, UTimeUnitFormatStyle style, UErrorCode &status)
Create TimeUnitFormat given locale and style.
void setNumberFormat(const NumberFormat &format, UErrorCode &status)
Set the number format used for formatting or parsing.
TimeUnitFormat(UErrorCode &status)
Create TimeUnitFormat with default locale, and full name style.
TimeUnitFormat(const TimeUnitFormat &)
Copy constructor.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
virtual ~TimeUnitFormat()
deconstructor
virtual Format * clone(void) const
Clone this Format object polymorphically.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
Format a TimeUnitAmount.
TimeUnitFormat(const Locale &locale, UErrorCode &status)
Create TimeUnitFormat given locale, and full name style.
void setLocale(const Locale &locale, UErrorCode &status)
Set the locale used for formatting or parsing.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition tmutfmt.h:260
UTimeUnitFields
Constants for all the time units we supported.
Definition tmunit.h:36
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
C++ API: Formatter for measure objects.
C++ API: Abstract base class for all number formats.
C++ API: PluralRules object.
C++ API: time unit object.
C++ API: time unit amount object.
UTimeUnitFormatStyle
Constants for various styles.
Definition tmutfmt.h:35
@ UTMUTFMT_ABBREVIATED_STYLE
Definition tmutfmt.h:39
@ UTMUTFMT_FORMAT_STYLE_COUNT
Definition tmutfmt.h:41
@ UTMUTFMT_FULL_STYLE
Definition tmutfmt.h:37
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#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_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129