1999-12-28 23:57:50 +00:00
|
|
|
/*
|
|
|
|
********************************************************************************
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (C) 1997-2003, International Business Machines
|
1999-12-28 23:57:50 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
* File FMTABLE.H
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/29/97 aliu Creation.
|
|
|
|
********************************************************************************
|
|
|
|
*/
|
|
|
|
#ifndef FMTABLE_H
|
|
|
|
#define FMTABLE_H
|
|
|
|
|
2003-12-11 01:47:45 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/unistr.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* <P>
|
|
|
|
* 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.
|
|
|
|
* <P>
|
|
|
|
* 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.
|
2003-11-05 21:59:41 +00:00
|
|
|
*
|
|
|
|
* The Formattable class is not suitable for subclassing.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-06-27 01:19:20 +00:00
|
|
|
class U_I18N_API Formattable : public UObject {
|
1999-12-28 23:57:50 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* 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.
|
2002-12-19 00:11:32 +00:00
|
|
|
* @draft ICU 2.4
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
enum ISDATE { kIsDate };
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2002-12-19 00:11:32 +00:00
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
* @draft ICU 2.4
|
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(); // Type kLong, value 0
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with a UDate instance.
|
|
|
|
* @param d the UDate instance.
|
2003-06-09 06:13:14 +00:00
|
|
|
* @param flag the flag to indicate this is a date. Always set it to kIsDate
|
2002-12-05 00:30:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-06-09 06:13:14 +00:00
|
|
|
Formattable(UDate d, ISDATE flag);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with a double number.
|
|
|
|
* @param d the double number.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(double d);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with a long number.
|
2003-05-10 00:27:54 +00:00
|
|
|
* @param l the long number.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(int32_t l);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
2003-10-31 22:47:25 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with an int64_t number
|
|
|
|
* @param ll the int64_t number.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
Formattable(int64_t ll);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with a char string pointer.
|
|
|
|
* Assumes that the char string is null terminated.
|
|
|
|
* @param strToCopy the char string.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(const char* strToCopy);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with a UnicodeString object to copy from.
|
|
|
|
* @param strToCopy the UnicodeString string.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(const UnicodeString& strToCopy);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with a UnicodeString object to adopt from.
|
|
|
|
* @param strToAdopt the UnicodeString string.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(UnicodeString* strToAdopt);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Creates a Formattable object with an array of Formattable objects.
|
|
|
|
* @param arrayToCopy the Formattable object array.
|
|
|
|
* @param count the array count.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(const Formattable* arrayToCopy, int32_t count);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable(const Formattable&);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Assignment operator.
|
2003-05-10 00:27:54 +00:00
|
|
|
* @param rhs The Formattable object to copy into this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
Formattable& operator=(const Formattable &rhs);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Equality comparison.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param other the object to be compared with.
|
|
|
|
* @return TRUE if other are equal to this, FALSE otherwise.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-05-10 00:27:54 +00:00
|
|
|
UBool operator==(const Formattable &other) const;
|
2002-07-01 11:04:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Equality operator.
|
|
|
|
* @param other the object to be compared with.
|
|
|
|
* @return TRUE if other are unequal to this, FALSE otherwise.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2002-07-01 11:04:45 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool operator!=(const Formattable& other) const
|
1999-12-28 23:57:50 +00:00
|
|
|
{ return !operator==(other); }
|
|
|
|
|
2000-03-22 19:19:33 +00:00
|
|
|
/**
|
|
|
|
* Destructor.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2000-03-22 19:19:33 +00:00
|
|
|
*/
|
1999-12-28 23:57:50 +00:00
|
|
|
virtual ~Formattable();
|
|
|
|
|
2003-11-05 21:59:41 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @return a clone of this object
|
|
|
|
*
|
|
|
|
* @see getDynamicClassID
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
Formattable *clone() const;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* The list of possible data types of this Formattable object.
|
2002-12-19 00:11:32 +00:00
|
|
|
* @draft ICU 2.4
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
enum Type {
|
2003-11-04 23:10:46 +00:00
|
|
|
/** @draft ICU 2.4 */
|
1999-12-28 23:57:50 +00:00
|
|
|
kDate, // Date
|
2003-11-04 23:10:46 +00:00
|
|
|
/** @draft ICU 2.4 */
|
1999-12-28 23:57:50 +00:00
|
|
|
kDouble, // double
|
2003-11-04 23:10:46 +00:00
|
|
|
/** @draft ICU 2.4 */
|
1999-12-28 23:57:50 +00:00
|
|
|
kLong, // long
|
2003-11-04 23:10:46 +00:00
|
|
|
/** @draft ICU 2.4 */
|
1999-12-28 23:57:50 +00:00
|
|
|
kString, // UnicodeString
|
2003-11-04 23:10:46 +00:00
|
|
|
/** @draft ICU 2.4 */
|
2003-10-31 22:47:25 +00:00
|
|
|
kArray, // Formattable[]
|
2003-11-04 23:10:46 +00:00
|
|
|
/** @draft ICU 2.8 */
|
|
|
|
kInt64 // int64
|
2003-10-31 22:47:25 +00:00
|
|
|
};
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the data type of this Formattable object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the data type of this Formattable object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
Type getType(void) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the double value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the double value of this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
double getDouble(void) const { return fValue.fDouble; }
|
2003-11-04 23:10:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param status the error code
|
|
|
|
* @return the double value of this object.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
double getDouble(UErrorCode* status) const;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Gets the long value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the long value of this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-10-31 22:47:25 +00:00
|
|
|
int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
|
2003-11-04 23:10:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param status the error code
|
|
|
|
* @return the long value of this object.
|
|
|
|
* @stable ICU 2.0
|
|
|
|
*/
|
|
|
|
int32_t getLong(UErrorCode* status) const;
|
|
|
|
|
2003-10-31 22:47:25 +00:00
|
|
|
/**
|
|
|
|
* Gets the int64 value of this object.
|
|
|
|
* @return the int64 value of this object.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
int64_t getInt64(void) const { return fValue.fInt64; }
|
2003-11-04 23:10:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param status the error code
|
|
|
|
* @return the int64 value of this object.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
int64_t getInt64(UErrorCode* status) const;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Gets the Date value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the Date value of this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2003-11-04 23:10:46 +00:00
|
|
|
UDate getDate() const { return fValue.fDate; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Date value of this object.
|
|
|
|
* @param 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.
|
|
|
|
* @return the Date value of this object.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
UDate getDate(UErrorCode* status) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the string value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param result Output param to receive the Date value of this object.
|
|
|
|
* @return A reference to 'result'.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeString& getString(UnicodeString& result) const
|
|
|
|
{ result=*fValue.fString; return result; }
|
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
/**
|
|
|
|
* Gets the string value of this object.
|
|
|
|
* @param result Output param to receive the Date value of this object.
|
|
|
|
* @param 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.
|
|
|
|
* @return A reference to 'result'.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
UnicodeString& getString(UnicodeString& result, UErrorCode* status) const;
|
|
|
|
|
2000-06-14 20:52:50 +00:00
|
|
|
/**
|
|
|
|
* Gets a const reference to the string value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return a const reference to the string value of this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2000-06-14 20:52:50 +00:00
|
|
|
*/
|
|
|
|
inline const UnicodeString& getString(void) const;
|
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
/**
|
|
|
|
* Gets a const reference to the string value of this object.
|
|
|
|
* @param 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.
|
|
|
|
* @return a const reference to the string value of this object.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
const UnicodeString& getString(UErrorCode* status) const;
|
|
|
|
|
2000-06-14 20:52:50 +00:00
|
|
|
/**
|
|
|
|
* Gets a reference to the string value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return a reference to the string value of this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
2000-06-14 20:52:50 +00:00
|
|
|
*/
|
|
|
|
inline UnicodeString& getString(void);
|
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
/**
|
|
|
|
* Gets a reference to the string value of this object.
|
|
|
|
* @param 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.
|
|
|
|
* @return a reference to the string value of this object.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
UnicodeString& getString(UErrorCode* status);
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Gets the array value and count of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param count fill-in with the count of this object.
|
|
|
|
* @return the array value of this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
const Formattable* getArray(int32_t& count) const
|
|
|
|
{ count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
|
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
/**
|
|
|
|
* Gets the array value and count of this object.
|
|
|
|
* @param count fill-in with the count of this object.
|
|
|
|
* @param 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.
|
|
|
|
* @return the array value of this object.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
const Formattable* getArray(int32_t& count, UErrorCode* status) const;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Accesses the specified element in the array value of this Formattable object.
|
|
|
|
* @param index the specified index.
|
|
|
|
* @return the accessed element in the array.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the double value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param d the new double value to be set.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setDouble(double d);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Sets the long value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param l the new long value to be set.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setLong(int32_t l);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
2003-10-31 22:47:25 +00:00
|
|
|
/**
|
|
|
|
* Sets the int64 value of this object.
|
|
|
|
* @param ll the new int64 value to be set.
|
|
|
|
* @draft ICU 2.8
|
|
|
|
*/
|
|
|
|
void setInt64(int64_t ll);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Sets the Date value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param d the new Date value to be set.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setDate(UDate d);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Sets the string value of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param stringToCopy the new string value to be set.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setString(const UnicodeString& stringToCopy);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Sets the array value and count of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param array the array value.
|
|
|
|
* @param count the number of array elements to be copied.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setArray(const Formattable* array, int32_t count);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Sets and adopts the string value and count of this object.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param stringToAdopt the new string value to be adopted.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void adoptString(UnicodeString* stringToAdopt);
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Sets and adopts the array value and count of this object.
|
2002-12-04 23:46:16 +00:00
|
|
|
* @stable ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void adoptArray(Formattable* array, int32_t count);
|
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
|
|
|
*
|
2003-11-18 02:37:24 +00:00
|
|
|
* @stable ICU 2.2
|
2002-06-29 00:04:16 +00:00
|
|
|
*/
|
2003-08-31 20:53:46 +00:00
|
|
|
virtual UClassID getDynamicClassID() const;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for this class.
|
|
|
|
*
|
2003-11-18 02:37:24 +00:00
|
|
|
* @stable ICU 2.2
|
2002-06-29 00:04:16 +00:00
|
|
|
*/
|
2003-08-31 20:53:46 +00:00
|
|
|
static UClassID getStaticClassID();
|
2002-06-29 00:04:16 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Cleans up the memory for unwanted values. For example, the adopted
|
|
|
|
* string or array objects.
|
|
|
|
*/
|
|
|
|
void dispose(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Formattable array and copies the values from the specified
|
|
|
|
* original.
|
|
|
|
* @param array the original array
|
|
|
|
* @param count the original array count
|
|
|
|
* @return the new Formattable array.
|
|
|
|
*/
|
|
|
|
static Formattable* createArrayCopy(const Formattable* array, int32_t count);
|
|
|
|
|
2003-11-26 22:57:27 +00:00
|
|
|
UnicodeString* getBogus() const;
|
2003-11-04 23:10:46 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
// Note: For now, we do not handle unsigned long and unsigned
|
|
|
|
// double types. Smaller unsigned types, such as unsigned
|
|
|
|
// short, can fit within a long.
|
|
|
|
union {
|
|
|
|
UnicodeString* fString;
|
|
|
|
double fDouble;
|
2003-10-31 22:47:25 +00:00
|
|
|
int64_t fInt64;
|
|
|
|
UDate fDate;
|
1999-12-28 23:57:50 +00:00
|
|
|
struct
|
|
|
|
{
|
2003-11-26 22:57:27 +00:00
|
|
|
Formattable* fArray;
|
|
|
|
int32_t fCount;
|
1999-12-28 23:57:50 +00:00
|
|
|
} fArrayAndCount;
|
|
|
|
} fValue;
|
|
|
|
|
|
|
|
Type fType;
|
2003-11-26 22:57:27 +00:00
|
|
|
UnicodeString fBogus; // Bogus string when it's needed.
|
1999-12-28 23:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Formattable*
|
|
|
|
Formattable::createArrayCopy(const Formattable* array, int32_t count)
|
|
|
|
{
|
|
|
|
Formattable *result = new Formattable[count];
|
|
|
|
for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy!
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-11-04 23:10:46 +00:00
|
|
|
inline UDate Formattable::getDate(UErrorCode* status) const {
|
|
|
|
if (status && U_SUCCESS(*status) && fType != kDate) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return fValue.fDate;
|
|
|
|
}
|
|
|
|
|
2000-06-14 20:52:50 +00:00
|
|
|
inline const UnicodeString& Formattable::getString(void) const {
|
|
|
|
return *fValue.fString;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline UnicodeString& Formattable::getString(void) {
|
|
|
|
return *fValue.fString;
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#endif //_FMTABLE
|
|
|
|
//eof
|
|
|
|
|