ICU 57.1 57.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
50class Hashtable;
51class UVector;
52
84public:
85
92
97 TimeUnitFormat(const Locale& locale, UErrorCode& status);
98
103 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
104
110
116
123 virtual Format* clone(void) const;
124
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
192private:
193 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
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
232inline UBool
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
Base class for all formats.
Definition: format.h:94
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:66
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
A formatter for measure objects.
Definition: measfmt.h:93
virtual UBool operator==(const Format &other) const
Return true if given Format objects are semantically equal.
Abstract base class for all number formats.
Definition: numfmt.h:167
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:83
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.
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.
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: tmutfmt.h:233
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:294
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:37
@ UTMUTFMT_ABBREVIATED_STYLE
Definition: tmutfmt.h:41
@ UTMUTFMT_FORMAT_STYLE_COUNT
Definition: tmutfmt.h:43
@ UTMUTFMT_FULL_STYLE
Definition: tmutfmt.h:39
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
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