michael@0: /* michael@0: ******************************************************************************** michael@0: * Copyright (C) 1997-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************** michael@0: * michael@0: * File FMTABLE.H michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 02/29/97 aliu Creation. michael@0: ******************************************************************************** michael@0: */ michael@0: #ifndef FMTABLE_H michael@0: #define FMTABLE_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing michael@0: */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/stringpiece.h" michael@0: #include "unicode/uformattable.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class CharString; michael@0: class DigitList; michael@0: michael@0: /** michael@0: * \def UNUM_INTERNAL_STACKARRAY_SIZE michael@0: * @internal michael@0: */ michael@0: #if U_PLATFORM == U_PF_OS400 michael@0: #define UNUM_INTERNAL_STACKARRAY_SIZE 144 michael@0: #else michael@0: #define UNUM_INTERNAL_STACKARRAY_SIZE 128 michael@0: #endif michael@0: michael@0: /** michael@0: * Formattable objects can be passed to the Format class or michael@0: * its subclasses for formatting. Formattable is a thin wrapper michael@0: * class which interconverts between the primitive numeric types michael@0: * (double, long, etc.) as well as UDate and UnicodeString. michael@0: * michael@0: *

Internally, a Formattable object is a union of primitive types. michael@0: * As such, it can only store one flavor of data at a time. To michael@0: * determine what flavor of data it contains, use the getType method. michael@0: * michael@0: *

As of ICU 3.0, Formattable may also wrap a UObject pointer, michael@0: * which it owns. This allows an instance of any ICU class to be michael@0: * encapsulated in a Formattable. For legacy reasons and for michael@0: * efficiency, primitive numeric types are still stored directly michael@0: * within a Formattable. michael@0: * michael@0: *

The Formattable class is not suitable for subclassing. michael@0: * michael@0: *

See UFormattable for a C wrapper. michael@0: */ michael@0: class U_I18N_API Formattable : public UObject { michael@0: public: michael@0: /** michael@0: * This enum is only used to let callers distinguish between michael@0: * the Formattable(UDate) constructor and the Formattable(double) michael@0: * constructor; the compiler cannot distinguish the signatures, michael@0: * since UDate is currently typedefed to be either double or long. michael@0: * If UDate is changed later to be a bonafide class michael@0: * or struct, then we no longer need this enum. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: enum ISDATE { kIsDate }; michael@0: michael@0: /** michael@0: * Default constructor michael@0: * @stable ICU 2.4 michael@0: */ michael@0: Formattable(); // Type kLong, value 0 michael@0: michael@0: /** michael@0: * Creates a Formattable object with a UDate instance. michael@0: * @param d the UDate instance. michael@0: * @param flag the flag to indicate this is a date. Always set it to kIsDate michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(UDate d, ISDATE flag); michael@0: michael@0: /** michael@0: * Creates a Formattable object with a double number. michael@0: * @param d the double number. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(double d); michael@0: michael@0: /** michael@0: * Creates a Formattable object with a long number. michael@0: * @param l the long number. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(int32_t l); michael@0: michael@0: /** michael@0: * Creates a Formattable object with an int64_t number michael@0: * @param ll the int64_t number. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: Formattable(int64_t ll); michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: /** michael@0: * Creates a Formattable object with a char string pointer. michael@0: * Assumes that the char string is null terminated. michael@0: * @param strToCopy the char string. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(const char* strToCopy); michael@0: #endif michael@0: michael@0: /** michael@0: * Creates a Formattable object of an appropriate numeric type from a michael@0: * a decimal number in string form. The Formattable will retain the michael@0: * full precision of the input in decimal format, even when it exceeds michael@0: * what can be represented by a double or int64_t. michael@0: * michael@0: * @param number the unformatted (not localized) string representation michael@0: * of the Decimal number. michael@0: * @param status the error code. Possible errors include U_INVALID_FORMAT_ERROR michael@0: * if the format of the string does not conform to that of a michael@0: * decimal number. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: Formattable(const StringPiece &number, UErrorCode &status); michael@0: michael@0: /** michael@0: * Creates a Formattable object with a UnicodeString object to copy from. michael@0: * @param strToCopy the UnicodeString string. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(const UnicodeString& strToCopy); michael@0: michael@0: /** michael@0: * Creates a Formattable object with a UnicodeString object to adopt from. michael@0: * @param strToAdopt the UnicodeString string. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(UnicodeString* strToAdopt); michael@0: michael@0: /** michael@0: * Creates a Formattable object with an array of Formattable objects. michael@0: * @param arrayToCopy the Formattable object array. michael@0: * @param count the array count. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(const Formattable* arrayToCopy, int32_t count); michael@0: michael@0: /** michael@0: * Creates a Formattable object that adopts the given UObject. michael@0: * @param objectToAdopt the UObject to set this object to michael@0: * @stable ICU 3.0 michael@0: */ michael@0: Formattable(UObject* objectToAdopt); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable(const Formattable&); michael@0: michael@0: /** michael@0: * Assignment operator. michael@0: * @param rhs The Formattable object to copy into this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable& operator=(const Formattable &rhs); michael@0: michael@0: /** michael@0: * Equality comparison. michael@0: * @param other the object to be compared with. michael@0: * @return TRUE if other are equal to this, FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool operator==(const Formattable &other) const; michael@0: michael@0: /** michael@0: * Equality operator. michael@0: * @param other the object to be compared with. michael@0: * @return TRUE if other are unequal to this, FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool operator!=(const Formattable& other) const michael@0: { return !operator==(other); } michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~Formattable(); michael@0: michael@0: /** michael@0: * Clone this object. michael@0: * Clones can be used concurrently in multiple threads. michael@0: * If an error occurs, then NULL is returned. michael@0: * The caller must delete the clone. michael@0: * michael@0: * @return a clone of this object michael@0: * michael@0: * @see getDynamicClassID michael@0: * @stable ICU 2.8 michael@0: */ michael@0: Formattable *clone() const; michael@0: michael@0: /** michael@0: * Selector for flavor of data type contained within a michael@0: * Formattable object. Formattable is a union of several michael@0: * different types, and at any time contains exactly one type. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: enum Type { michael@0: /** michael@0: * Selector indicating a UDate value. Use getDate to retrieve michael@0: * the value. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: kDate, michael@0: michael@0: /** michael@0: * Selector indicating a double value. Use getDouble to michael@0: * retrieve the value. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: kDouble, michael@0: michael@0: /** michael@0: * Selector indicating a 32-bit integer value. Use getLong to michael@0: * retrieve the value. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: kLong, michael@0: michael@0: /** michael@0: * Selector indicating a UnicodeString value. Use getString michael@0: * to retrieve the value. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: kString, michael@0: michael@0: /** michael@0: * Selector indicating an array of Formattables. Use getArray michael@0: * to retrieve the value. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: kArray, michael@0: michael@0: /** michael@0: * Selector indicating a 64-bit integer value. Use getInt64 michael@0: * to retrieve the value. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: kInt64, michael@0: michael@0: /** michael@0: * Selector indicating a UObject value. Use getObject to michael@0: * retrieve the value. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: kObject michael@0: }; michael@0: michael@0: /** michael@0: * Gets the data type of this Formattable object. michael@0: * @return the data type of this Formattable object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Type getType(void) const; michael@0: michael@0: /** michael@0: * Returns TRUE if the data type of this Formattable object michael@0: * is kDouble, kLong, or kInt64 michael@0: * @return TRUE if this is a pure numeric object michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UBool isNumeric() const; michael@0: michael@0: /** michael@0: * Gets the double value of this object. If this object is not of type michael@0: * kDouble then the result is undefined. michael@0: * @return the double value of this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: double getDouble(void) const { return fValue.fDouble; } michael@0: michael@0: /** michael@0: * Gets the double value of this object. If this object is of type michael@0: * long, int64 or Decimal Number then a conversion is peformed, with michael@0: * possible loss of precision. If the type is kObject and the michael@0: * object is a Measure, then the result of michael@0: * getNumber().getDouble(status) is returned. If this object is michael@0: * neither a numeric type nor a Measure, then 0 is returned and michael@0: * the status is set to U_INVALID_FORMAT_ERROR. michael@0: * @param status the error code michael@0: * @return the double value of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: double getDouble(UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Gets the long value of this object. If this object is not of type michael@0: * kLong then the result is undefined. michael@0: * @return the long value of this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t getLong(void) const { return (int32_t)fValue.fInt64; } michael@0: michael@0: /** michael@0: * Gets the long value of this object. If the magnitude is too michael@0: * large to fit in a long, then the maximum or minimum long value, michael@0: * as appropriate, is returned and the status is set to michael@0: * U_INVALID_FORMAT_ERROR. If this object is of type kInt64 and michael@0: * it fits within a long, then no precision is lost. If it is of michael@0: * type kDouble, then a conversion is peformed, with michael@0: * truncation of any fractional part. If the type is kObject and michael@0: * the object is a Measure, then the result of michael@0: * getNumber().getLong(status) is returned. If this object is michael@0: * neither a numeric type nor a Measure, then 0 is returned and michael@0: * the status is set to U_INVALID_FORMAT_ERROR. michael@0: * @param status the error code michael@0: * @return the long value of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: int32_t getLong(UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Gets the int64 value of this object. If this object is not of type michael@0: * kInt64 then the result is undefined. michael@0: * @return the int64 value of this object. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: int64_t getInt64(void) const { return fValue.fInt64; } michael@0: michael@0: /** michael@0: * Gets the int64 value of this object. If this object is of a numeric michael@0: * type and the magnitude is too large to fit in an int64, then michael@0: * the maximum or minimum int64 value, as appropriate, is returned michael@0: * and the status is set to U_INVALID_FORMAT_ERROR. If the michael@0: * magnitude fits in an int64, then a casting conversion is michael@0: * peformed, with truncation of any fractional part. If the type michael@0: * is kObject and the object is a Measure, then the result of michael@0: * getNumber().getDouble(status) is returned. If this object is michael@0: * neither a numeric type nor a Measure, then 0 is returned and michael@0: * the status is set to U_INVALID_FORMAT_ERROR. michael@0: * @param status the error code michael@0: * @return the int64 value of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: int64_t getInt64(UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Gets the Date value of this object. If this object is not of type michael@0: * kDate then the result is undefined. michael@0: * @return the Date value of this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UDate getDate() const { return fValue.fDate; } michael@0: michael@0: /** michael@0: * Gets the Date value of this object. If the type is not a date, michael@0: * status is set to U_INVALID_FORMAT_ERROR and the return value is michael@0: * undefined. michael@0: * @param status the error code. michael@0: * @return the Date value of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UDate getDate(UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Gets the string value of this object. If this object is not of type michael@0: * kString then the result is undefined. michael@0: * @param result Output param to receive the Date value of this object. michael@0: * @return A reference to 'result'. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& getString(UnicodeString& result) const michael@0: { result=*fValue.fString; return result; } michael@0: michael@0: /** michael@0: * Gets the string value of this object. If the type is not a michael@0: * string, status is set to U_INVALID_FORMAT_ERROR and a bogus michael@0: * string is returned. michael@0: * @param result Output param to receive the Date value of this object. michael@0: * @param status the error code. michael@0: * @return A reference to 'result'. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UnicodeString& getString(UnicodeString& result, UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Gets a const reference to the string value of this object. If michael@0: * this object is not of type kString then the result is michael@0: * undefined. michael@0: * @return a const reference to the string value of this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline const UnicodeString& getString(void) const; michael@0: michael@0: /** michael@0: * Gets a const reference to the string value of this object. If michael@0: * the type is not a string, status is set to michael@0: * U_INVALID_FORMAT_ERROR and the result is a bogus string. michael@0: * @param status the error code. michael@0: * @return a const reference to the string value of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: const UnicodeString& getString(UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Gets a reference to the string value of this object. If this michael@0: * object is not of type kString then the result is undefined. michael@0: * @return a reference to the string value of this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& getString(void); michael@0: michael@0: /** michael@0: * Gets a reference to the string value of this object. If the michael@0: * type is not a string, status is set to U_INVALID_FORMAT_ERROR michael@0: * and the result is a bogus string. michael@0: * @param status the error code. michael@0: * @return a reference to the string value of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UnicodeString& getString(UErrorCode& status); michael@0: michael@0: /** michael@0: * Gets the array value and count of this object. If this object michael@0: * is not of type kArray then the result is undefined. michael@0: * @param count fill-in with the count of this object. michael@0: * @return the array value of this object. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: const Formattable* getArray(int32_t& count) const michael@0: { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; } michael@0: michael@0: /** michael@0: * Gets the array value and count of this object. If the type is michael@0: * not an array, status is set to U_INVALID_FORMAT_ERROR, count is michael@0: * set to 0, and the result is NULL. michael@0: * @param count fill-in with the count of this object. michael@0: * @param status the error code. michael@0: * @return the array value of this object. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: const Formattable* getArray(int32_t& count, UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Accesses the specified element in the array value of this michael@0: * Formattable object. If this object is not of type kArray then michael@0: * the result is undefined. michael@0: * @param index the specified index. michael@0: * @return the accessed element in the array. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; } michael@0: michael@0: /** michael@0: * Returns a pointer to the UObject contained within this michael@0: * formattable, or NULL if this object does not contain a UObject. michael@0: * @return a UObject pointer, or NULL michael@0: * @stable ICU 3.0 michael@0: */ michael@0: const UObject* getObject() const; michael@0: michael@0: /** michael@0: * Returns a numeric string representation of the number contained within this michael@0: * formattable, or NULL if this object does not contain numeric type. michael@0: * For values obtained by parsing, the returned decimal number retains michael@0: * the full precision and range of the original input, unconstrained by michael@0: * the limits of a double floating point or a 64 bit int. michael@0: * michael@0: * This function is not thread safe, and therfore is not declared const, michael@0: * even though it is logically const. michael@0: * michael@0: * Possible errors include U_MEMORY_ALLOCATION_ERROR, and michael@0: * U_INVALID_STATE if the formattable object has not been set to michael@0: * a numeric type. michael@0: * michael@0: * @param status the error code. michael@0: * @return the unformatted string representation of a number. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: StringPiece getDecimalNumber(UErrorCode &status); michael@0: michael@0: /** michael@0: * Sets the double value of this object and changes the type to michael@0: * kDouble. michael@0: * @param d the new double value to be set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setDouble(double d); michael@0: michael@0: /** michael@0: * Sets the long value of this object and changes the type to michael@0: * kLong. michael@0: * @param l the new long value to be set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setLong(int32_t l); michael@0: michael@0: /** michael@0: * Sets the int64 value of this object and changes the type to michael@0: * kInt64. michael@0: * @param ll the new int64 value to be set. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: void setInt64(int64_t ll); michael@0: michael@0: /** michael@0: * Sets the Date value of this object and changes the type to michael@0: * kDate. michael@0: * @param d the new Date value to be set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setDate(UDate d); michael@0: michael@0: /** michael@0: * Sets the string value of this object and changes the type to michael@0: * kString. michael@0: * @param stringToCopy the new string value to be set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setString(const UnicodeString& stringToCopy); michael@0: michael@0: /** michael@0: * Sets the array value and count of this object and changes the michael@0: * type to kArray. michael@0: * @param array the array value. michael@0: * @param count the number of array elements to be copied. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setArray(const Formattable* array, int32_t count); michael@0: michael@0: /** michael@0: * Sets and adopts the string value and count of this object and michael@0: * changes the type to kArray. michael@0: * @param stringToAdopt the new string value to be adopted. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void adoptString(UnicodeString* stringToAdopt); michael@0: michael@0: /** michael@0: * Sets and adopts the array value and count of this object and michael@0: * changes the type to kArray. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void adoptArray(Formattable* array, int32_t count); michael@0: michael@0: /** michael@0: * Sets and adopts the UObject value of this object and changes michael@0: * the type to kObject. After this call, the caller must not michael@0: * delete the given object. michael@0: * @param objectToAdopt the UObject value to be adopted michael@0: * @stable ICU 3.0 michael@0: */ michael@0: void adoptObject(UObject* objectToAdopt); michael@0: michael@0: /** michael@0: * Sets the the numeric value from a decimal number string, and changes michael@0: * the type to to a numeric type appropriate for the number. michael@0: * The syntax of the number is a "numeric string" michael@0: * as defined in the Decimal Arithmetic Specification, available at michael@0: * http://speleotrove.com/decimal michael@0: * The full precision and range of the input number will be retained, michael@0: * even when it exceeds what can be represented by a double or an int64. michael@0: * michael@0: * @param numberString a string representation of the unformatted decimal number. michael@0: * @param status the error code. Set to U_INVALID_FORMAT_ERROR if the michael@0: * incoming string is not a valid decimal number. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: void setDecimalNumber(const StringPiece &numberString, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: virtual UClassID getDynamicClassID() const; michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for this class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Convert the UFormattable to a Formattable. Internally, this is a reinterpret_cast. michael@0: * @param fmt a valid UFormattable michael@0: * @return the UFormattable as a Formattable object pointer. This is an alias to the original michael@0: * UFormattable, and so is only valid while the original argument remains in scope. michael@0: * @draft ICU 52 michael@0: */ michael@0: static inline Formattable *fromUFormattable(UFormattable *fmt); michael@0: michael@0: /** michael@0: * Convert the const UFormattable to a const Formattable. Internally, this is a reinterpret_cast. michael@0: * @param fmt a valid UFormattable michael@0: * @return the UFormattable as a Formattable object pointer. This is an alias to the original michael@0: * UFormattable, and so is only valid while the original argument remains in scope. michael@0: * @draft ICU 52 michael@0: */ michael@0: static inline const Formattable *fromUFormattable(const UFormattable *fmt); michael@0: michael@0: /** michael@0: * Convert this object pointer to a UFormattable. michael@0: * @return this object as a UFormattable pointer. This is an alias to this object, michael@0: * and so is only valid while this object remains in scope. michael@0: * @draft ICU 52 michael@0: */ michael@0: inline UFormattable *toUFormattable(); michael@0: michael@0: /** michael@0: * Convert this object pointer to a UFormattable. michael@0: * @return this object as a UFormattable pointer. This is an alias to this object, michael@0: * and so is only valid while this object remains in scope. michael@0: * @draft ICU 52 michael@0: */ michael@0: inline const UFormattable *toUFormattable() const; michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Deprecated variant of getLong(UErrorCode&). michael@0: * @param status the error code michael@0: * @return the long value of this object. michael@0: * @deprecated ICU 3.0 use getLong(UErrorCode&) instead michael@0: */ michael@0: inline int32_t getLong(UErrorCode* status) const; michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Internal function, do not use. michael@0: * TODO: figure out how to make this be non-public. michael@0: * NumberFormat::format(Formattable, ... michael@0: * needs to get at the DigitList, if it exists, for michael@0: * big decimal formatting. michael@0: * @internal michael@0: */ michael@0: DigitList *getDigitList() const { return fDecimalNum;} michael@0: michael@0: /** michael@0: * @internal michael@0: */ michael@0: DigitList *getInternalDigitList(); michael@0: michael@0: /** michael@0: * Adopt, and set value from, a DigitList michael@0: * Internal Function, do not use. michael@0: * @param dl the Digit List to be adopted michael@0: * @internal michael@0: */ michael@0: void adoptDigitList(DigitList *dl); michael@0: michael@0: /** michael@0: * Internal function to return the CharString pointer. michael@0: * @param status error code michael@0: * @return pointer to the CharString - may become invalid if the object is modified michael@0: * @internal michael@0: */ michael@0: CharString *internalGetCharString(UErrorCode &status); michael@0: michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: private: michael@0: /** michael@0: * Cleans up the memory for unwanted values. For example, the adopted michael@0: * string or array objects. michael@0: */ michael@0: void dispose(void); michael@0: michael@0: /** michael@0: * Common initialization, for use by constructors. michael@0: */ michael@0: void init(); michael@0: michael@0: UnicodeString* getBogus() const; michael@0: michael@0: union { michael@0: UObject* fObject; michael@0: UnicodeString* fString; michael@0: double fDouble; michael@0: int64_t fInt64; michael@0: UDate fDate; michael@0: struct { michael@0: Formattable* fArray; michael@0: int32_t fCount; michael@0: } fArrayAndCount; michael@0: } fValue; michael@0: michael@0: CharString *fDecimalStr; michael@0: michael@0: DigitList *fDecimalNum; michael@0: michael@0: char fStackData[UNUM_INTERNAL_STACKARRAY_SIZE]; // must be big enough for DigitList michael@0: michael@0: Type fType; michael@0: UnicodeString fBogus; // Bogus string when it's needed. michael@0: }; michael@0: michael@0: inline UDate Formattable::getDate(UErrorCode& status) const { michael@0: if (fType != kDate) { michael@0: if (U_SUCCESS(status)) { michael@0: status = U_INVALID_FORMAT_ERROR; michael@0: } michael@0: return 0; michael@0: } michael@0: return fValue.fDate; michael@0: } michael@0: michael@0: inline const UnicodeString& Formattable::getString(void) const { michael@0: return *fValue.fString; michael@0: } michael@0: michael@0: inline UnicodeString& Formattable::getString(void) { michael@0: return *fValue.fString; michael@0: } michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: inline int32_t Formattable::getLong(UErrorCode* status) const { michael@0: return getLong(*status); michael@0: } michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: #ifndef U_HIDE_DRAFT_API michael@0: inline UFormattable* Formattable::toUFormattable() { michael@0: return reinterpret_cast(this); michael@0: } michael@0: michael@0: inline const UFormattable* Formattable::toUFormattable() const { michael@0: return reinterpret_cast(this); michael@0: } michael@0: michael@0: inline Formattable* Formattable::fromUFormattable(UFormattable *fmt) { michael@0: return reinterpret_cast(fmt); michael@0: } michael@0: michael@0: inline const Formattable* Formattable::fromUFormattable(const UFormattable *fmt) { michael@0: return reinterpret_cast(fmt); michael@0: } michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif //_FMTABLE michael@0: //eof