Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

Formattable Class Reference

Formattable objects can be passed to the Format class or its subclasses for formatting. More...

#include <fmtable.h>

Inheritance diagram for Formattable::

UObject UMemory List of all members.

Public Types

enum  ISDATE { kIsDate }
 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. More...

enum  Type {
  kDate, kDouble, kLong, kString,
  kArray, kInt64
}
 The list of possible data types of this Formattable object. More...


Public Methods

 Formattable ()
 Default constructor. More...

 Formattable (UDate d, ISDATE flag)
 Creates a Formattable object with a UDate instance. More...

 Formattable (double d)
 Creates a Formattable object with a double number. More...

 Formattable (int32_t l)
 Creates a Formattable object with a long number. More...

 Formattable (int64_t ll)
 Creates a Formattable object with an int64_t number. More...

 Formattable (const char *strToCopy)
 Creates a Formattable object with a char string pointer. More...

 Formattable (const UnicodeString &strToCopy)
 Creates a Formattable object with a UnicodeString object to copy from. More...

 Formattable (UnicodeString *strToAdopt)
 Creates a Formattable object with a UnicodeString object to adopt from. More...

 Formattable (const Formattable *arrayToCopy, int32_t count)
 Creates a Formattable object with an array of Formattable objects. More...

 Formattable (const Formattable &)
 Copy constructor. More...

Formattable & operator= (const Formattable &rhs)
 Assignment operator. More...

UBool operator== (const Formattable &other) const
 Equality comparison. More...

UBool operator!= (const Formattable &other) const
 Equality operator. More...

virtual ~Formattable ()
 Destructor. More...

Formattable * clone () const
 Clone this object. More...

Type getType (void) const
 Gets the data type of this Formattable object. More...

double getDouble (void) const
 Gets the double value of this object. More...

double getDouble (UErrorCode *status) const
 Gets the double value of this object. More...

int32_t getLong (void) const
 Gets the long value of this object. More...

int32_t getLong (UErrorCode *status) const
 Gets the long value of this object. More...

int64_t getInt64 (void) const
 Gets the int64 value of this object. More...

int64_t getInt64 (UErrorCode *status) const
 Gets the int64 value of this object. More...

UDate getDate () const
 Gets the Date value of this object. More...

UDate getDate (UErrorCode *status) const
 Gets the Date value of this object. More...

UnicodeString & getString (UnicodeString &result) const
 Gets the string value of this object. More...

UnicodeString & getString (UnicodeString &result, UErrorCode *status) const
 Gets the string value of this object. More...

const UnicodeString & getString (void) const
 Gets a const reference to the string value of this object. More...

const UnicodeString & getString (UErrorCode *status) const
 Gets a const reference to the string value of this object. More...

UnicodeString & getString (void)
 Gets a reference to the string value of this object. More...

UnicodeString & getString (UErrorCode *status)
 Gets a reference to the string value of this object. More...

const Formattable * getArray (int32_t &count) const
 Gets the array value and count of this object. More...

const Formattable * getArray (int32_t &count, UErrorCode *status) const
 Gets the array value and count of this object. More...

Formattable & operator[] (int32_t index)
 Accesses the specified element in the array value of this Formattable object. More...

void setDouble (double d)
 Sets the double value of this object. More...

void setLong (int32_t l)
 Sets the long value of this object. More...

void setInt64 (int64_t ll)
 Sets the int64 value of this object. More...

void setDate (UDate d)
 Sets the Date value of this object. More...

void setString (const UnicodeString &stringToCopy)
 Sets the string value of this object. More...

void setArray (const Formattable *array, int32_t count)
 Sets the array value and count of this object. More...

void adoptString (UnicodeString *stringToAdopt)
 Sets and adopts the string value and count of this object. More...

void adoptArray (Formattable *array, int32_t count)
 Sets and adopts the array value and count of this object. More...

virtual UClassID getDynamicClassID () const
 ICU "poor man's RTTI", returns a UClassID for the actual class. More...


Static Public Methods

UClassID getStaticClassID ()
 ICU "poor man's RTTI", returns a UClassID for this class. More...


Private Methods

void dispose (void)
 Cleans up the memory for unwanted values. More...

UnicodeString * getBogus () const

Static Private Methods

Formattable * createArrayCopy (const Formattable *array, int32_t count)
 Creates a new Formattable array and copies the values from the specified original. More...


Private Attributes

Formattable:: { ... }  fValue
Type fType
UnicodeString fBogus
UnicodeString * fString
double fDouble
int64_t fInt64
UDate fDate
Formattable * fArray
int32_t fCount
Formattable:: { ... } ::@11 fArrayAndCount

Detailed Description

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.

Note that this is fundamentally different from the Java behavior, since in this case the various formattable objects do not occupy a hierarchy, but are all wrapped within this one class. Formattable encapsulates all the polymorphism in itself.

It would be easy to change this so that Formattable was an abstract base class of a genuine hierarchy, and that would clean up the code that currently must explicitly check for type, but that seems like overkill at this point.

The Formattable class is not suitable for subclassing.

Definition at line 43 of file fmtable.h.


Member Enumeration Documentation

enum Formattable::ISDATE
 

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.

Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.
Enumeration values:
kIsDate 

Definition at line 54 of file fmtable.h.

enum Formattable::Type
 

The list of possible data types of this Formattable object.

Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.
Enumeration values:
kDate 
Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.
kDouble 
Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.
kLong 
Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.
kString 
Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.
kArray 
Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.
kInt64 
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

Definition at line 174 of file fmtable.h.


Constructor & Destructor Documentation

Formattable::Formattable (    ) 
 

Default constructor.

Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.

Formattable::Formattable (  UDate    d,
ISDATE    flag
) 
 

Creates a Formattable object with a UDate instance.

Parameters:
d  the UDate instance.
flag  the flag to indicate this is a date. Always set it to kIsDate
Stable:
ICU 2.0

Formattable::Formattable (  double    d ) 
 

Creates a Formattable object with a double number.

Parameters:
d  the double number.
Stable:
ICU 2.0

Formattable::Formattable (  int32_t    l ) 
 

Creates a Formattable object with a long number.

Parameters:
l  the long number.
Stable:
ICU 2.0

Formattable::Formattable (  int64_t    ll ) 
 

Creates a Formattable object with an int64_t number.

Parameters:
ll  the int64_t number.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

Formattable::Formattable (  const char *    strToCopy ) 
 

Creates a Formattable object with a char string pointer.

Assumes that the char string is null terminated.

Parameters:
strToCopy  the char string.
Stable:
ICU 2.0

Formattable::Formattable (  const UnicodeString &    strToCopy ) 
 

Creates a Formattable object with a UnicodeString object to copy from.

Parameters:
strToCopy  the UnicodeString string.
Stable:
ICU 2.0

Formattable::Formattable (  UnicodeString *    strToAdopt ) 
 

Creates a Formattable object with a UnicodeString object to adopt from.

Parameters:
strToAdopt  the UnicodeString string.
Stable:
ICU 2.0

Formattable::Formattable (  const Formattable *    arrayToCopy,
int32_t    count
) 
 

Creates a Formattable object with an array of Formattable objects.

Parameters:
arrayToCopy  the Formattable object array.
count  the array count.
Stable:
ICU 2.0

Formattable::Formattable (  const Formattable &    ) 
 

Copy constructor.

Stable:
ICU 2.0

virtual Formattable::~Formattable (    )  [virtual]
 

Destructor.

Stable:
ICU 2.0


Member Function Documentation

void Formattable::adoptArray (  Formattable *    array,
int32_t    count
) 
 

Sets and adopts the array value and count of this object.

Stable:
ICU 2.0

void Formattable::adoptString (  UnicodeString *    stringToAdopt ) 
 

Sets and adopts the string value and count of this object.

Parameters:
stringToAdopt  the new string value to be adopted.
Stable:
ICU 2.0

Formattable* Formattable::clone (  void    )  const
 

Clone this object.

Clones can be used concurrently in multiple threads. If an error occurs, then NULL is returned. The caller must delete the clone.

Returns:
a clone of this object
See also:
getDynamicClassID
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

Formattable * Formattable::createArrayCopy (  const Formattable *    array,
int32_t    count
)  [inline, static, private]
 

Creates a new Formattable array and copies the values from the specified original.

Parameters:
array  the original array
count  the original array count
Returns:
the new Formattable array.

Definition at line 456 of file fmtable.h.

void Formattable::dispose (  void    )  [private]
 

Cleans up the memory for unwanted values.

For example, the adopted string or array objects.

const Formattable* Formattable::getArray (  int32_t &    count,
UErrorCode *    status
)  const
 

Gets the array value and count of this object.

Parameters:
count  fill-in with the count of this object.
status  the error code. If the type is not an array, status is set to U_INVALID_FORMAT_ERROR, count is set to 0, and the result is NULL.
Returns:
the array value of this object.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

const Formattable* Formattable::getArray (  int32_t &    count )  const [inline]
 

Gets the array value and count of this object.

Parameters:
count  fill-in with the count of this object.
Returns:
the array value of this object.
Stable:
ICU 2.0

Definition at line 327 of file fmtable.h.

UnicodeString* Formattable::getBogus (    )  const [private]
 

UDate Formattable::getDate (  UErrorCode *    status )  const [inline]
 

Gets the Date value of this object.

Parameters:
status  the error code. If the type is not a date, status is set to U_INVALID_FORMAT_ERROR and the return value is undefined.
Returns:
the Date value of this object.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

Definition at line 463 of file fmtable.h.

UDate Formattable::getDate (    )  const [inline]
 

Gets the Date value of this object.

Returns:
the Date value of this object.
Stable:
ICU 2.0

Definition at line 259 of file fmtable.h.

double Formattable::getDouble (  UErrorCode *    status )  const
 

Gets the double value of this object.

This converts from long or int64 values as required (conversion from int64 can lose precision). If the type is not a numeric type, 0 is returned and the status is set to U_INVALID_FORMAT_ERROR.

Parameters:
status  the error code
Returns:
the double value of this object.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

double Formattable::getDouble (  void    )  const [inline]
 

Gets the double value of this object.

Returns:
the double value of this object.
Stable:
ICU 2.0

Definition at line 201 of file fmtable.h.

virtual UClassID Formattable::getDynamicClassID (  void    )  const [virtual]
 

ICU "poor man's RTTI", returns a UClassID for the actual class.

Stable:
ICU 2.2

Reimplemented from UObject.

int64_t Formattable::getInt64 (  UErrorCode *    status )  const
 

Gets the int64 value of this object.

This converts from double or int64 values as required. If the value value won't fit in an int64, the maximum or minimum in64 value, as appropriate, is returned and the status is set to U_INVALID_FORMAT_ERROR. If the type is not a numeric type, 0 is returned and the status is set to U_INVALID_FORMAT_ERROR.

Parameters:
status  the error code
Returns:
the int64 value of this object.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

int64_t Formattable::getInt64 (  void    )  const [inline]
 

Gets the int64 value of this object.

Returns:
the int64 value of this object.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

Definition at line 239 of file fmtable.h.

int32_t Formattable::getLong (  UErrorCode *    status )  const
 

Gets the long value of this object.

This converts from double or int64 values as required. If the magnitude is too large to fit in a long, the maximum or minimum long value, as appropriate, is returned and the status is set to U_INVALID_FORMAT_ERROR. If the type is not a numeric type, 0 is returned and the status is set to U_INVALID_FORMAT_ERROR.

Parameters:
status  the error code
Returns:
the long value of this object.
Stable:
ICU 2.0

int32_t Formattable::getLong (  void    )  const [inline]
 

Gets the long value of this object.

Returns:
the long value of this object.
Stable:
ICU 2.0

Definition at line 219 of file fmtable.h.

UClassID Formattable::getStaticClassID (  void    )  [static]
 

ICU "poor man's RTTI", returns a UClassID for this class.

Stable:
ICU 2.2

UnicodeString& Formattable::getString (  UErrorCode *    status ) 
 

Gets a reference to the string value of this object.

Parameters:
status  the error code. If the type is not a string, status is set to U_INVALID_FORMAT_ERROR and the result is a bogus string.
Returns:
a reference to the string value of this object.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

UnicodeString & Formattable::getString (  void    )  [inline]
 

Gets a reference to the string value of this object.

Returns:
a reference to the string value of this object.
Stable:
ICU 2.0

Definition at line 475 of file fmtable.h.

const UnicodeString& Formattable::getString (  UErrorCode *    status )  const
 

Gets a const reference to the string value of this object.

Parameters:
status  the error code. If the type is not a string, status is set to U_INVALID_FORMAT_ERROR and the result is a bogus string.
Returns:
a const reference to the string value of this object.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

const UnicodeString & Formattable::getString (  void    )  const [inline]
 

Gets a const reference to the string value of this object.

Returns:
a const reference to the string value of this object.
Stable:
ICU 2.0

Definition at line 471 of file fmtable.h.

UnicodeString& Formattable::getString (  UnicodeString &    result,
UErrorCode *    status
)  const
 

Gets the string value of this object.

Parameters:
result  Output param to receive the Date value of this object.
status  the error code. If the type is not a string, status is set to U_INVALID_FORMAT_ERROR and the result is set to bogus.
Returns:
A reference to 'result'.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

UnicodeString& Formattable::getString (  UnicodeString &    result )  const [inline]
 

Gets the string value of this object.

Parameters:
result  Output param to receive the Date value of this object.
Returns:
A reference to 'result'.
Stable:
ICU 2.0

Definition at line 276 of file fmtable.h.

Type Formattable::getType (  void    )  const
 

Gets the data type of this Formattable object.

Returns:
the data type of this Formattable object.
Stable:
ICU 2.0

UBool Formattable::operator!= (  const Formattable &    other )  const [inline]
 

Equality operator.

Parameters:
other  the object to be compared with.
Returns:
TRUE if other are unequal to this, FALSE otherwise.
Stable:
ICU 2.0

Definition at line 148 of file fmtable.h.

Formattable& Formattable::operator= (  const Formattable &    rhs ) 
 

Assignment operator.

Parameters:
rhs  The Formattable object to copy into this object.
Stable:
ICU 2.0

UBool Formattable::operator== (  const Formattable &    other )  const
 

Equality comparison.

Parameters:
other  the object to be compared with.
Returns:
TRUE if other are equal to this, FALSE otherwise.
Stable:
ICU 2.0

Formattable& Formattable::operator[] (  int32_t    index )  [inline]
 

Accesses the specified element in the array value of this Formattable object.

Parameters:
index  the specified index.
Returns:
the accessed element in the array.
Stable:
ICU 2.0

Definition at line 346 of file fmtable.h.

void Formattable::setArray (  const Formattable *    array,
int32_t    count
) 
 

Sets the array value and count of this object.

Parameters:
array  the array value.
count  the number of array elements to be copied.
Stable:
ICU 2.0

void Formattable::setDate (  UDate    d ) 
 

Sets the Date value of this object.

Parameters:
d  the new Date value to be set.
Stable:
ICU 2.0

void Formattable::setDouble (  double    d ) 
 

Sets the double value of this object.

Parameters:
d  the new double value to be set.
Stable:
ICU 2.0

void Formattable::setInt64 (  int64_t    ll ) 
 

Sets the int64 value of this object.

Parameters:
ll  the new int64 value to be set.
Draft:
This API has been introduced in ICU 2.8. It is still in draft state and may be modified in a future release.

void Formattable::setLong (  int32_t    l ) 
 

Sets the long value of this object.

Parameters:
l  the new long value to be set.
Stable:
ICU 2.0

void Formattable::setString (  const UnicodeString &    stringToCopy ) 
 

Sets the string value of this object.

Parameters:
stringToCopy  the new string value to be set.
Stable:
ICU 2.0


Member Data Documentation

Formattable* Formattable::fArray [private]
 

Definition at line 446 of file fmtable.h.

struct { ... } Formattable::fArrayAndCount [private]
 

UnicodeString Formattable::fBogus [private]
 

Definition at line 452 of file fmtable.h.

int32_t Formattable::fCount [private]
 

Definition at line 447 of file fmtable.h.

UDate Formattable::fDate [private]
 

Definition at line 443 of file fmtable.h.

double Formattable::fDouble [private]
 

Definition at line 441 of file fmtable.h.

int64_t Formattable::fInt64 [private]
 

Definition at line 442 of file fmtable.h.

UnicodeString* Formattable::fString [private]
 

Definition at line 440 of file fmtable.h.

Type Formattable::fType [private]
 

Definition at line 451 of file fmtable.h.

union { ... } Formattable::fValue [private]
 


The documentation for this class was generated from the following file:
Generated on Thu Jan 29 13:22:38 2004 for ICU 2.8 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001