Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

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

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 Member Functions

 Formattable ()
 Default constructor ICU 2.4.

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

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

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

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

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

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

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

 Formattable (const Formattable &)
 Copy constructor.

Formattableoperator= (const Formattable &rhs)
 Assignment operator.

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

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

virtual ~Formattable ()
 Destructor.

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

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

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

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

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

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

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

const FormattablegetArray (int32_t &count) const
 Gets the array value and count of this object.

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

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

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

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

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

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

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

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

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


Static Public Member Functions

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


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.


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

enum Formattable::Type
 

The list of possible data types of this Formattable object.

ICU 2.4


Constructor & Destructor Documentation

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 ICU 2.0

Formattable::Formattable double  d  ) 
 

Creates a Formattable object with a double number.

Parameters:
d the double number. ICU 2.0

Formattable::Formattable int32_t  l  ) 
 

Creates a Formattable object with a long number.

Parameters:
l the long number. ICU 2.0

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

Formattable::Formattable const UnicodeString strToCopy  ) 
 

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

Parameters:
strToCopy the UnicodeString string. ICU 2.0

Formattable::Formattable UnicodeString strToAdopt  ) 
 

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

Parameters:
strToAdopt the UnicodeString string. 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. ICU 2.0

Formattable::Formattable const Formattable  ) 
 

Copy constructor.

ICU 2.0

virtual Formattable::~Formattable  )  [virtual]
 

Destructor.

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.

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

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

UDate Formattable::getDate void   )  const [inline]
 

Gets the Date value of this object.

Returns:
the Date value of this object. ICU 2.0

double Formattable::getDouble void   )  const [inline]
 

Gets the double value of this object.

Returns:
the double value of this object. ICU 2.0

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

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

ICU 2.2

Implements UObject.

int32_t Formattable::getLong void   )  const [inline]
 

Gets the long value of this object.

Returns:
the long value of this object. ICU 2.0

UClassID Formattable::getStaticClassID  )  [inline, static]
 

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

ICU 2.2

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

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

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'. ICU 2.0

Type Formattable::getType void   )  const
 

Gets the data type of this Formattable object.

Returns:
the data type of this Formattable object. 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. ICU 2.0

Formattable& Formattable::operator= const Formattable rhs  ) 
 

Assignment operator.

Parameters:
rhs The Formattable object to copy into this object. 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. 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. ICU 2.0

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

void Formattable::setDate UDate  d  ) 
 

Sets the Date value of this object.

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

void Formattable::setDouble double  d  ) 
 

Sets the double value of this object.

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

void Formattable::setLong int32_t  l  ) 
 

Sets the long value of this object.

Parameters:
l the new long value to be set. 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. ICU 2.0


The documentation for this class was generated from the following file:
Generated on Wed Sep 3 17:47:19 2003 for ICU 2.6 by doxygen 1.3.2