icu::TimeUnitFormat Class Reference

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

#include <tmutfmt.h>

Inheritance diagram for icu::TimeUnitFormat:
icu::MeasureFormat icu::Format icu::UObject icu::UMemory

Public Member Functions

 TimeUnitFormat (UErrorCode &status)
 Create TimeUnitFormat with default locale, and full name style.
 TimeUnitFormat (const Locale &locale, UErrorCode &status)
 Create TimeUnitFormat given locale, and full name style.
 TimeUnitFormat (const Locale &locale, UTimeUnitFormatStyle style, UErrorCode &status)
 Create TimeUnitFormat given locale and style.
 TimeUnitFormat (const TimeUnitFormat &)
 Copy constructor.
virtual ~TimeUnitFormat ()
 deconstructor
virtual Formatclone (void) const
 Clone this Format object polymorphically.
TimeUnitFormatoperator= (const TimeUnitFormat &other)
 Assignment operator.
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.
void setLocale (const Locale &locale, UErrorCode &status)
 Set the locale used for formatting or parsing.
void setNumberFormat (const NumberFormat &format, UErrorCode &status)
 Set the number format used for formatting or parsing.
virtual UnicodeStringformat (const Formattable &obj, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
 Format a TimeUnitAmount.
virtual void parseObject (const UnicodeString &source, Formattable &result, ParsePosition &pos) const
 Parse a TimeUnitAmount.
virtual UClassID getDynamicClassID (void) const
 Returns a unique class ID POLYMORPHICALLY.

Static Public Member Functions

static UClassID getStaticClassID (void)
 Return the class ID for this class.

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
Stable:
ICU 4.2

Definition at line 80 of file tmutfmt.h.


Constructor & Destructor Documentation

icu::TimeUnitFormat::TimeUnitFormat ( UErrorCode status  ) 

Create TimeUnitFormat with default locale, and full name style.

Use setLocale and/or setFormat to modify.

Stable:
ICU 4.2
icu::TimeUnitFormat::TimeUnitFormat ( const Locale locale,
UErrorCode status 
)

Create TimeUnitFormat given locale, and full name style.

Stable:
ICU 4.2
icu::TimeUnitFormat::TimeUnitFormat ( const Locale locale,
UTimeUnitFormatStyle  style,
UErrorCode status 
)

Create TimeUnitFormat given locale and style.

Stable:
ICU 4.8
icu::TimeUnitFormat::TimeUnitFormat ( const TimeUnitFormat  ) 

Copy constructor.

Stable:
ICU 4.2
virtual icu::TimeUnitFormat::~TimeUnitFormat (  )  [virtual]

deconstructor

Stable:
ICU 4.2

Member Function Documentation

virtual Format* icu::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.
Stable:
ICU 4.2

Implements icu::Format.

virtual UnicodeString& icu::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
Stable:
ICU 4.2

Implements icu::Format.

virtual UClassID icu::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.
Stable:
ICU 4.2

Implements icu::UObject.

static UClassID icu::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.
Stable:
ICU 4.2
UBool icu::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:
other the object to be compared with.
Returns:
true if the given Format objects are not semantically equal.
Stable:
ICU 4.2

Definition at line 260 of file tmutfmt.h.

References operator==().

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

Assignment operator.

Stable:
ICU 4.2

Reimplemented from icu::Format.

virtual UBool icu::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:
other the object to be compared with.
Returns:
true if the given Format objects are semantically equal.
Stable:
ICU 4.2

Referenced by operator!=().

virtual void icu::TimeUnitFormat::parseObject ( const UnicodeString source,
Formattable result,
ParsePosition pos 
) const [virtual]
void icu::TimeUnitFormat::setLocale ( const Locale locale,
UErrorCode status 
)

Set the locale used for formatting or parsing.

Parameters:
locale the locale to be set
status output param set to success/failure code on exit
Stable:
ICU 4.2
void icu::TimeUnitFormat::setNumberFormat ( const NumberFormat format,
UErrorCode status 
)

Set the number format used for formatting or parsing.

Parameters:
format the number formatter to be set
status output param set to success/failure code on exit
Stable:
ICU 4.2

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

Generated on 27 Mar 2014 for ICU 50.1.2 by  doxygen 1.6.1