ICU 4.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Friends
TimeUnitFormat Class Reference

Format or parse a TimeUnitAmount, using plural rules for the units where available. More...

#include <tmutfmt.h>

Inheritance diagram for TimeUnitFormat:
MeasureFormat Format UObject UMemory

Public Types

enum  EStyle { kFull = 0, kAbbreviate = 1, kTotal = kAbbreviate + 1 }
 Constants for various styles. More...
 

Public Member Functions

 TimeUnitFormat (UErrorCode &status)
 Create TimeUnitFormat with default locale, and full name style. More...
 
 TimeUnitFormat (const Locale &locale, UErrorCode &status)
 Create TimeUnitFormat given locale, and full name style. More...
 
 TimeUnitFormat (const Locale &locale, EStyle style, UErrorCode &status)
 Create TimeUnitFormat given locale and style. More...
 
 TimeUnitFormat (const TimeUnitFormat &)
 Copy constructor. More...
 
virtual ~TimeUnitFormat ()
 deconstructor More...
 
virtual Formatclone (void) const
 Clone this Format object polymorphically. More...
 
TimeUnitFormatoperator= (const TimeUnitFormat &other)
 Assignment operator. More...
 
virtual UBool operator== (const Format &other) const
 Return true if the given Format objects are semantically equal. More...
 
UBool operator!= (const Format &other) const
 Return true if the given Format objects are not semantically equal. More...
 
void setLocale (const Locale &locale, UErrorCode &status)
 Set the locale used for formatting or parsing. More...
 
void setNumberFormat (const NumberFormat &format, UErrorCode &status)
 Set the number format used for formatting or parsing. More...
 
virtual UnicodeStringformat (const Formattable &obj, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
 Format a TimeUnitAmount. More...
 
virtual void parseObject (const UnicodeString &source, Formattable &result, ParsePosition &pos) const
 Parse a TimeUnitAmount. More...
 
virtual UClassID getDynamicClassID (void) const
 Returns a unique class ID POLYMORPHICALLY. More...
 
- Public Member Functions inherited from Format
virtual ~Format ()
 Destructor. More...
 
UBool operator!= (const Format &other) const
 Return true if the given Format objects are not semantically equal. More...
 
UnicodeStringformat (const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
 Formats an object to produce a string. More...
 
void parseObject (const UnicodeString &source, Formattable &result, UErrorCode &status) const
 Parses a string to produce an object. More...
 
Locale getLocale (ULocDataLocaleType type, UErrorCode &status) const
 Get the locale for this format object. More...
 
const char * getLocaleID (ULocDataLocaleType type, UErrorCode &status) const
 Get the locale for this format object. More...
 
- Public Member Functions inherited from UObject
virtual ~UObject ()
 Destructor. More...
 

Static Public Member Functions

static UClassID getStaticClassID (void)
 Return the class ID for this class. More...
 
- Static Public Member Functions inherited from MeasureFormat
static MeasureFormatcreateCurrencyFormat (const Locale &locale, UErrorCode &ec)
 Return a formatter for CurrencyAmount objects in the given locale. More...
 
static MeasureFormatcreateCurrencyFormat (UErrorCode &ec)
 Return a formatter for CurrencyAmount objects in the default locale. More...
 
- Static Public Member Functions inherited from UMemory
static void * operator new (size_t size)
 Override for ICU4C C++ memory management. More...
 
static void * operator new[] (size_t size)
 Override for ICU4C C++ memory management. More...
 
static void operator delete (void *p)
 Override for ICU4C C++ memory management. More...
 
static void operator delete[] (void *p)
 Override for ICU4C C++ memory management. More...
 
static void * operator new (size_t, void *ptr)
 Override for ICU4C C++ memory management for STL. More...
 
static void operator delete (void *, void *)
 Override for ICU4C C++ memory management for STL. More...
 

Friends

UBool hashTableValueComparator (UHashTok val1, UHashTok val2)
 

Additional Inherited Members

- Protected Member Functions inherited from MeasureFormat
 MeasureFormat ()
 Default constructor. More...
 
- Protected Member Functions inherited from Format
void setLocaleIDs (const char *valid, const char *actual)
 
 Format ()
 Default constructor for subclass use only. More...
 
 Format (const Format &)
 
Formatoperator= (const Format &)
 
- Static Protected Member Functions inherited from Format
static void syntaxError (const UnicodeString &pattern, int32_t pos, UParseError &parseError)
 Simple function for initializing a UParseError from a UnicodeString. More...
 

Detailed Description

Format or parse a TimeUnitAmount, using plural rules for the units where available.

Code Sample:

  // create time unit amount instance - a combination of Number and time unit
  UErrorCode status = U_ZERO_ERROR;
  TimeUnitAmount* source = new TimeUnitAmount(2, TimeUnit::UTIMEUNIT_YEAR, status);
  // create time unit format instance
  TimeUnitFormat* format = new TimeUnitFormat(Locale("en"), status);
  // format a time unit amount
  UnicodeString formatted;
  Formattable formattable;
  if (U_SUCCESS(status)) {
      formattable.adoptObject(source);
      formatted = ((Format*)format)->format(formattable, formatted, status);
      Formattable result;
      ((Format*)format)->parseObject(formatted, result, status);
      if (U_SUCCESS(status)) {
          assert (result == formattable); 
      }
  }
See Also
TimeUnitAmount
TimeUnitFormat
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 79 of file tmutfmt.h.

Member Enumeration Documentation

Constants for various styles.

There are 2 styles: full name and abbreviated name. For example, for English, the full name for hour duration is "3 hours", and the abbreviated name is "3 hrs".

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 89 of file tmutfmt.h.

Constructor & Destructor Documentation

TimeUnitFormat::TimeUnitFormat ( UErrorCode status)

Create TimeUnitFormat with default locale, and full name style.

Use setLocale and/or setFormat to modify.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
TimeUnitFormat::TimeUnitFormat ( const Locale locale,
UErrorCode status 
)

Create TimeUnitFormat given locale, and full name style.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
TimeUnitFormat::TimeUnitFormat ( const Locale locale,
EStyle  style,
UErrorCode status 
)

Create TimeUnitFormat given locale and style.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
TimeUnitFormat::TimeUnitFormat ( const TimeUnitFormat )

Copy constructor.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
virtual TimeUnitFormat::~TimeUnitFormat ( )
virtual

deconstructor

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Member Function Documentation

virtual Format* TimeUnitFormat::clone ( void  ) const
virtual

Clone this Format object polymorphically.

The caller owns the result and should delete it when done.

Returns
A copy of the object.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Implements Format.

virtual UnicodeString& TimeUnitFormat::format ( const Formattable obj,
UnicodeString toAppendTo,
FieldPosition pos,
UErrorCode status 
) const
virtual

Format a TimeUnitAmount.

If the formattable object is not a time unit amount object, or the number in time unit amount is not a double type or long type numeric, it returns a failing status: U_ILLEGAL_ARGUMENT_ERROR.

See Also
Format::format(const Formattable&, UnicodeString&, FieldPosition&, UErrorCode&) const
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Implements Format.

virtual UClassID TimeUnitFormat::getDynamicClassID ( void  ) const
virtual

Returns a unique class ID POLYMORPHICALLY.

Pure virtual override. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphic operator==() and clone() methods call this method.

Returns
The class ID for this object. All objects of a given class have the same class ID. Objects of other classes have different class IDs.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Implements Format.

static UClassID TimeUnitFormat::getStaticClassID ( void  )
static

Return the class ID for this class.

This is useful only for comparing to a return value from getDynamicClassID(). For example:

.   Base* polymorphic_pointer = createPolymorphicObject();
.   if (polymorphic_pointer->getDynamicClassID() ==
.       erived::getStaticClassID()) ...
Returns
The class ID for all objects of this class.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
UBool TimeUnitFormat::operator!= ( const Format other) const
inline

Return true if the given Format objects are not semantically equal.

Objects of different subclasses are considered unequal.

Parameters
otherthe object to be compared with.
Returns
true if the given Format objects are not semantically equal.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 270 of file tmutfmt.h.

References operator==().

TimeUnitFormat& TimeUnitFormat::operator= ( const TimeUnitFormat other)

Assignment operator.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
virtual UBool TimeUnitFormat::operator== ( const Format other) const
virtual

Return true if the given Format objects are semantically equal.

Objects of different subclasses are considered unequal.

Parameters
otherthe object to be compared with.
Returns
true if the given Format objects are semantically equal.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Implements Format.

Referenced by operator!=().

virtual void TimeUnitFormat::parseObject ( const UnicodeString source,
Formattable result,
ParsePosition pos 
) const
virtual

Parse a TimeUnitAmount.

See Also
Format::parseObject(const UnicodeString&, Formattable&, ParsePosition&) const;
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Implements Format.

void TimeUnitFormat::setLocale ( const Locale locale,
UErrorCode status 
)

Set the locale used for formatting or parsing.

Parameters
localethe locale to be set
statusoutput param set to success/failure code on exit
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2
void TimeUnitFormat::setNumberFormat ( const NumberFormat format,
UErrorCode status 
)

Set the number format used for formatting or parsing.

Parameters
formatthe number formatter to be set
statusoutput param set to success/failure code on exit
Draft:
This API may be changed in the future versions and was introduced in ICU 4.2

Friends And Related Function Documentation

UBool hashTableValueComparator ( UHashTok  val1,
UHashTok  val2 
)
friend
Internal:
Do not use. This API is for internal use only. ICU 4.2

The documentation for this class was generated from the following file: