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 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
}
 The list of possible data types of this Formattable object. More...


Public Methods

 Formattable ()
 Formattable (UDate d, ISDATE)
 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 (const char *strToCopy)
 Creates a Formattable object with a char string pointer. More...

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

 Formattable (UnicodeString *stringToAdopt)
 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 &)
 Assignment operator. More...

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

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

virtual ~Formattable ()
 Destructor. 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...

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

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

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

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

UnicodeStringgetString (void)
 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...

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 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...


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
UnicodeStringfString
double fDouble
int32_t fLong
UDate fDate
Formattable * fArray
int32_t fCount
Formattable:: { ... } ::@7 fArrayAndCount

Static Private Attributes

const char fgClassID
 The address of this static class variable serves as this class's ID for ICU "poor man's RTTI". More...


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.

Definition at line 41 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.

Enumeration values:
kIsDate 

Definition at line 51 of file fmtable.h.

enum Formattable::Type
 

The list of possible data types of this Formattable object.

Enumeration values:
kDate 
kDouble 
kLong 
kString 
kArray 

Definition at line 136 of file fmtable.h.


Constructor & Destructor Documentation

Formattable::Formattable  
 

Formattable::Formattable UDate    d,
ISDATE   
 

Creates a Formattable object with a UDate instance.

Parameters:
d  the UDate instance.
ISDATE  the flag to indicate this is a date.
Stable:

Formattable::Formattable double    d
 

Creates a Formattable object with a double number.

Parameters:
d  the double number.
Stable:

Formattable::Formattable int32_t    l
 

Creates a Formattable object with a long number.

Parameters:
d  the long number.
Stable:

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:

Formattable::Formattable const UnicodeString   stringToCopy
 

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

Parameters:
strToCopy  the UnicodeString string.
Stable:

Formattable::Formattable UnicodeString   stringToAdopt
 

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

Parameters:
strToAdopt  the UnicodeString string.
Stable:

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:

Formattable::Formattable const Formattable &   
 

Copy constructor.

Stable:

virtual Formattable::~Formattable   [virtual]
 

Destructor.

Stable:


Member Function Documentation

void Formattable::adoptArray Formattable *    array,
int32_t    count
 

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

Stable:

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:

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 308 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 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:

Definition at line 199 of file fmtable.h.

UDate Formattable::getDate void    const [inline]
 

Gets the Date value of this object.

Returns:
the Date value of this object.
Stable:

Definition at line 168 of file fmtable.h.

double Formattable::getDouble void    const [inline]
 

Gets the double value of this object.

Returns:
the double value of this object.
Stable:

Definition at line 156 of file fmtable.h.

virtual UClassID Formattable::getDynamicClassID void    const [inline, virtual]
 

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

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

Reimplemented from UObject.

Definition at line 258 of file fmtable.h.

int32_t Formattable::getLong void    const [inline]
 

Gets the long value of this object.

Returns:
the long value of this object.
Stable:

Definition at line 162 of file fmtable.h.

UClassID Formattable::getStaticClassID void    [inline, static]
 

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

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

Definition at line 265 of file fmtable.h.

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:

Definition at line 319 of file fmtable.h.

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:

Definition at line 315 of file fmtable.h.

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:

Definition at line 176 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:

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:

Definition at line 124 of file fmtable.h.

Formattable& Formattable::operator= const Formattable &   
 

Assignment operator.

Stable:

UBool Formattable::operator== const Formattable &    const
 

Equality comparison.

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

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:

Definition at line 208 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:

void Formattable::setDate UDate    d
 

Sets the Date value of this object.

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

void Formattable::setDouble double    d
 

Sets the double value of this object.

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

void Formattable::setLong int32_t    l
 

Sets the long value of this object.

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

void Formattable::setString const UnicodeString   stringToCopy
 

Sets the string value of this object.

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


Member Data Documentation

Formattable* Formattable::fArray [private]
 

Definition at line 293 of file fmtable.h.

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

int32_t Formattable::fCount [private]
 

Definition at line 294 of file fmtable.h.

UDate Formattable::fDate [private]
 

Definition at line 290 of file fmtable.h.

double Formattable::fDouble [private]
 

Definition at line 288 of file fmtable.h.

int32_t Formattable::fLong [private]
 

Definition at line 289 of file fmtable.h.

UnicodeString* Formattable::fString [private]
 

Definition at line 287 of file fmtable.h.

Type Formattable::fType [private]
 

Definition at line 298 of file fmtable.h.

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

const char Formattable::fgClassID [static, private]
 

The address of this static class variable serves as this class's ID for ICU "poor man's RTTI".

Definition at line 304 of file fmtable.h.


The documentation for this class was generated from the following file:
Generated on Thu Aug 15 14:13:58 2002 for ICU 2.2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001