ICU 55.1  55.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 
50 class Hashtable;
51 class UVector;
52 
84 public:
85 
92 
97  TimeUnitFormat(const Locale& locale, UErrorCode& status);
98 
103  TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
104 
110 
115  virtual ~TimeUnitFormat();
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 
192 private:
193  Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
194  UTimeUnitFormatStyle fStyle;
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 
232 inline UBool
233 TimeUnitFormat::operator!=(const Format& other) const {
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
icu::TimeUnitFormat::setLocale
void setLocale(const Locale &locale, UErrorCode &status)
Set the locale used for formatting or parsing.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const Locale &locale, UErrorCode &status)
Create TimeUnitFormat given locale, and full name style.
icu::TimeUnitFormat::clone
virtual Format * clone(void) const
Clone this Format object polymorphically.
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:172
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:358
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
UTMUTFMT_ABBREVIATED_STYLE
@ UTMUTFMT_ABBREVIATED_STYLE
Definition: tmutfmt.h:41
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
icu::TimeUnitFormat::setNumberFormat
void setNumberFormat(const NumberFormat &format, UErrorCode &status)
Set the number format used for formatting or parsing.
measfmt.h
C++ API: Formatter for measure objects.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:119
icu::TimeUnitFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
UTimeUnitFormatStyle
UTimeUnitFormatStyle
Constants for various styles.
Definition: tmutfmt.h:37
icu::Format
Base class for all formats.
Definition: format.h:94
icu::TimeUnitFormat::operator=
TimeUnitFormat & operator=(const TimeUnitFormat &other)
Assignment operator.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
icu::TimeUnitFormat::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &pos) const
Parse a TimeUnitAmount.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
UTMUTFMT_FORMAT_STYLE_COUNT
@ UTMUTFMT_FORMAT_STYLE_COUNT
Definition: tmutfmt.h:43
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const TimeUnitFormat &)
Copy constructor.
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const Locale &locale, UTimeUnitFormatStyle style, UErrorCode &status)
Create TimeUnitFormat given locale and style.
UTMUTFMT_FULL_STYLE
@ UTMUTFMT_FULL_STYLE
Definition: tmutfmt.h:39
icu::MeasureFormat
A formatter for measure objects.
Definition: measfmt.h:93
icu::TimeUnitFormat::~TimeUnitFormat
virtual ~TimeUnitFormat()
deconstructor
tmutamt.h
C++ API: time unit amount object.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(UErrorCode &status)
Create TimeUnitFormat with default locale, and full name style.
numfmt.h
C++ API: Abstract base class for all number formats.
icu::TimeUnitFormat
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:83
icu::TimeUnitFormat::getStaticClassID
static UClassID getStaticClassID(void)
Return the class ID for this class.
plurrule.h
C++ API: PluralRules object.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
icu::TimeUnit::UTimeUnitFields
UTimeUnitFields
Constants for all the time units we supported.
Definition: tmunit.h:36
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
unistr.h
C++ API: Unicode String.
tmunit.h
C++ API: time unit object.