class Formattable
Defined at line 63 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
Formattable objects can be passed to the Format class or
its subclasses for formatting. Formattable is a thin wrapper
class which interconverts between the primitive numeric types
(double, long, etc.) as well as UDate and UnicodeString.
Internally, a Formattable object is a union of primitive types.
As such, it can only store one flavor of data at a time. To
determine what flavor of data it contains, use the getType method.
As of ICU 3.0, Formattable may also wrap a UObject pointer,
which it owns. This allows an instance of any ICU class to be
encapsulated in a Formattable. For legacy reasons and for
efficiency, primitive numeric types are still stored directly
within a Formattable.
The Formattable class is not suitable for subclassing.
See UFormattable for a C wrapper.
Public Methods
void Formattable ()
Default constructor
ICU 2.4
void Formattable (UDate d, ISDATE flag)
Creates a Formattable object with a UDate instance.
Parameters
void Formattable (double d)
Creates a Formattable object with a double number.
Parameters
void Formattable (int32_t l)
Creates a Formattable object with a long number.
Parameters
void Formattable (int64_t ll)
Creates a Formattable object with an int64_t number
Parameters
void Formattable (const char * strToCopy)
Creates a Formattable object with a char string pointer.
Assumes that the char string is null terminated.
Parameters
void Formattable (StringPiece number, UErrorCode & status)
Creates a Formattable object of an appropriate numeric type from a
a decimal number in string form. The Formattable will retain the
full precision of the input in decimal format, even when it exceeds
what can be represented by a double or int64_t.
Parameters
void Formattable (const UnicodeString & strToCopy)
Creates a Formattable object with a UnicodeString object to copy from.
Parameters
void Formattable (UnicodeString * strToAdopt)
Creates a Formattable object with a UnicodeString object to adopt from.
Parameters
void Formattable (const Formattable * arrayToCopy, int32_t count)
Creates a Formattable object with an array of Formattable objects.
Parameters
void Formattable (UObject * objectToAdopt)
Creates a Formattable object that adopts the given UObject.
Parameters
void Formattable (const Formattable & )
Copy constructor.
ICU 2.0
Formattable * clone ()
Clone this object.
Clones can be used concurrently in multiple threads.
If an error occurs, then nullptr is returned.
The caller must delete the clone.
Returns
a clone of this object
bool operator!= (const Formattable & other)
Equality operator.
Parameters
Returns
true if other are unequal to this, false otherwise.
ICU 2.0
Defined at line 192 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
double getDouble ()
Gets the double value of this object. If this object is not of type
kDouble then the result is undefined.
Returns
the double value of this object.
ICU 2.0
Defined at line 292 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
int32_t getLong ()
Gets the long value of this object. If this object is not of type
kLong then the result is undefined.
Returns
the long value of this object.
ICU 2.0
Defined at line 314 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
int64_t getInt64 ()
Gets the int64 value of this object. If this object is not of type
kInt64 then the result is undefined.
Returns
the int64 value of this object.
ICU 2.8
Defined at line 340 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
UDate getDate ()
Gets the Date value of this object. If this object is not of type
kDate then the result is undefined.
Returns
the Date value of this object.
ICU 2.0
Defined at line 365 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
UnicodeString & getString (UnicodeString & result)
Gets the string value of this object. If this object is not of type
kString then the result is undefined.
Parameters
Returns
A reference to 'result'.
ICU 2.0
Defined at line 384 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
const Formattable * getArray (int32_t & count)
Gets the array value and count of this object. If this object
is not of type kArray then the result is undefined.
Parameters
Returns
the array value of this object.
ICU 2.0
Defined at line 442 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
number::impl::DecimalQuantity * getDecimalQuantity ()
Internal function, do not use.
TODO: figure out how to make this be non-public.
NumberFormat::format(Formattable, ...
needs to get at the DecimalQuantity, if it exists, for
big decimal formatting.
Defined at line 651 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
Formattable & operator= (const Formattable & rhs)
Assignment operator.
Parameters
bool operator== (const Formattable & other)
Equality comparison.
Parameters
Returns
true if other are equal to this, false otherwise.
ICU 2.0
void ~Formattable ()
Destructor.
ICU 2.0
Type getType ()
Gets the data type of this Formattable object.
Returns
the data type of this Formattable object.
ICU 2.0
UBool isNumeric ()
Returns true if the data type of this Formattable object
is kDouble, kLong, or kInt64
Returns
true if this is a pure numeric object
ICU 3.0
double getDouble (UErrorCode & status)
Gets the double value of this object. If this object is of type
long, int64 or Decimal Number then a conversion is performed, with
possible loss of precision. If the type is kObject and the
object is a Measure, then the result of
getNumber().getDouble(status) is returned. If this object is
neither a numeric type nor a Measure, then 0 is returned and
the status is set to U_INVALID_FORMAT_ERROR.
Parameters
Returns
the double value of this object.
ICU 3.0
int32_t getLong (UErrorCode & status)
Gets the long value of this object. If the magnitude is too
large to fit in a long, then the maximum or minimum long value,
as appropriate, is returned and the status is set to
U_INVALID_FORMAT_ERROR. If this object is of type kInt64 and
it fits within a long, then no precision is lost. If it is of
type kDouble, then a conversion is performed, with
truncation of any fractional part. If the type is kObject and
the object is a Measure, then the result of
getNumber().getLong(status) is returned. If this object is
neither a numeric type nor a Measure, then 0 is returned and
the status is set to U_INVALID_FORMAT_ERROR.
Parameters
Returns
the long value of this object.
ICU 3.0
int64_t getInt64 (UErrorCode & status)
Gets the int64 value of this object. If this object is of a numeric
type and the magnitude is too large to fit in an int64, then
the maximum or minimum int64 value, as appropriate, is returned
and the status is set to U_INVALID_FORMAT_ERROR. If the
magnitude fits in an int64, then a casting conversion is
performed, with truncation of any fractional part. If the type
is kObject and the object is a Measure, then the result of
getNumber().getDouble(status) is returned. If this object is
neither a numeric type nor a Measure, then 0 is returned and
the status is set to U_INVALID_FORMAT_ERROR.
Parameters
Returns
the int64 value of this object.
ICU 3.0
UDate getDate (UErrorCode & status)
Gets the Date value of this object. If the type is not a date,
status is set to U_INVALID_FORMAT_ERROR and the return value is
undefined.
Parameters
Returns
the Date value of this object.
ICU 3.0
Defined at line 711 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
UnicodeString & getString (UnicodeString & result, UErrorCode & status)
Gets the string value of this object. If the type is not a
string, status is set to U_INVALID_FORMAT_ERROR and a bogus
string is returned.
Parameters
Returns
A reference to 'result'.
ICU 3.0
Formattable & operator[] (int32_t index)
Accesses the specified element in the array value of this
Formattable object. If this object is not of type kArray then
the result is undefined.
Parameters
Returns
the accessed element in the array.
ICU 2.0
Defined at line 464 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
const UnicodeString & getString ()
Gets a const reference to the string value of this object. If
this object is not of type kString then the result is
undefined.
Returns
a const reference to the string value of this object.
ICU 2.0
Defined at line 721 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
const UnicodeString & getString (UErrorCode & status)
Gets a const reference to the string value of this object. If
the type is not a string, status is set to
U_INVALID_FORMAT_ERROR and the result is a bogus string.
Parameters
Returns
a const reference to the string value of this object.
ICU 3.0
UnicodeString & getString ()
Gets a reference to the string value of this object. If this
object is not of type kString then the result is undefined.
Returns
a reference to the string value of this object.
ICU 2.0
Defined at line 725 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
UnicodeString & getString (UErrorCode & status)
Gets a reference to the string value of this object. If the
type is not a string, status is set to U_INVALID_FORMAT_ERROR
and the result is a bogus string.
Parameters
Returns
a reference to the string value of this object.
ICU 3.0
const Formattable * getArray (int32_t & count, UErrorCode & status)
Gets the array value and count of this object. If the type is
not an array, status is set to U_INVALID_FORMAT_ERROR, count is
set to 0, and the result is nullptr.
Parameters
Returns
the array value of this object.
ICU 3.0
const UObject * getObject ()
Returns a pointer to the UObject contained within this
formattable, or nullptr if this object does not contain a UObject.
Returns
a UObject pointer, or nullptr
ICU 3.0
StringPiece getDecimalNumber (UErrorCode & status)
Returns a numeric string representation of the number contained within this
formattable, or nullptr if this object does not contain numeric type.
For values obtained by parsing, the returned decimal number retains
the full precision and range of the original input, unconstrained by
the limits of a double floating point or a 64 bit int.
This function is not thread safe, and therefore is not declared const,
even though it is logically const.
Possible errors include U_MEMORY_ALLOCATION_ERROR, and
U_INVALID_STATE if the formattable object has not been set to
a numeric type.
Parameters
Returns
the unformatted string representation of a number.
ICU 4.4
void setDouble (double d)
Sets the double value of this object and changes the type to
kDouble.
Parameters
void setLong (int32_t l)
Sets the long value of this object and changes the type to
kLong.
Parameters
void setInt64 (int64_t ll)
Sets the int64 value of this object and changes the type to
kInt64.
Parameters
void setDate (UDate d)
Sets the Date value of this object and changes the type to
kDate.
Parameters
void setString (const UnicodeString & stringToCopy)
Sets the string value of this object and changes the type to
kString.
Parameters
void setArray (const Formattable * array, int32_t count)
Sets the array value and count of this object and changes the
type to kArray.
Parameters
void adoptString (UnicodeString * stringToAdopt)
Sets and adopts the string value and count of this object and
changes the type to kArray.
Parameters
void adoptArray (Formattable * array, int32_t count)
Sets and adopts the array value and count of this object and
changes the type to kArray.
ICU 2.0
void adoptObject (UObject * objectToAdopt)
Sets and adopts the UObject value of this object and changes
the type to kObject. After this call, the caller must not
delete the given object.
Parameters
void setDecimalNumber (StringPiece numberString, UErrorCode & status)
Sets the the numeric value from a decimal number string, and changes
the type to to a numeric type appropriate for the number.
The syntax of the number is a "numeric string"
as defined in the Decimal Arithmetic Specification, available at
http://speleotrove.com/decimal
The full precision and range of the input number will be retained,
even when it exceeds what can be represented by a double or an int64.
Parameters
UClassID getDynamicClassID ()
ICU "poor man's RTTI", returns a UClassID for the actual class.
ICU 2.2
UClassID getStaticClassID ()
ICU "poor man's RTTI", returns a UClassID for this class.
ICU 2.2
Formattable * fromUFormattable (UFormattable * fmt)
Convert the UFormattable to a Formattable. Internally, this is a reinterpret_cast.
Parameters
Returns
the UFormattable as a Formattable object pointer. This is an alias to the original
UFormattable, and so is only valid while the original argument remains in scope.
ICU 52
Defined at line 743 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
const Formattable * fromUFormattable (const UFormattable * fmt)
Convert the const UFormattable to a const Formattable. Internally, this is a reinterpret_cast.
Parameters
Returns
the UFormattable as a Formattable object pointer. This is an alias to the original
UFormattable, and so is only valid while the original argument remains in scope.
ICU 52
Defined at line 747 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
UFormattable * toUFormattable ()
Convert this object pointer to a UFormattable.
Returns
this object as a UFormattable pointer. This is an alias to this object,
and so is only valid while this object remains in scope.
ICU 52
Defined at line 735 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
const UFormattable * toUFormattable ()
Convert this object pointer to a UFormattable.
Returns
this object as a UFormattable pointer. This is an alias to this object,
and so is only valid while this object remains in scope.
ICU 52
Defined at line 739 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
int32_t getLong (UErrorCode * status)
Deprecated variant of getLong(UErrorCode
&
).
Parameters
Returns
the long value of this object.
Defined at line 730 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
void populateDecimalQuantity (number::impl::DecimalQuantity & output, UErrorCode & status)
Export the value of this Formattable to a DecimalQuantity.
void adoptDecimalQuantity (number::impl::DecimalQuantity * dq)
Adopt, and set value from, a DecimalQuantity
Internal Function, do not use.
Parameters
CharString * internalGetCharString (UErrorCode & status)
Internal function to return the CharString pointer.
Parameters
Returns
pointer to the CharString - may become invalid if the object is modified
Enumerations
enum ISDATE
| Name | Value |
|---|---|
| kIsDate | 0 |
This enum is only used to let callers distinguish between
the Formattable(UDate) constructor and the Formattable(double)
constructor; the compiler cannot distinguish the signatures,
since UDate is currently typedefed to be either double or long.
If UDate is changed later to be a bonafide class
or struct, then we no longer need this enum.
ICU 2.4
Defined at line 74 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h
enum Type
| Name | Value |
|---|---|
| kDate | 0 |
| kDouble | 1 |
| kLong | 2 |
| kString | 3 |
| kArray | 4 |
| kInt64 | 5 |
| kObject | 6 |
Selector for flavor of data type contained within a
Formattable object. Formattable is a union of several
different types, and at any time contains exactly one type.
ICU 2.4
Defined at line 220 of file ../../third_party/icu/latest/source/i18n/unicode/fmtable.h