/* ******************************************************************************** * Copyright (C) 1997-1999, International Business Machines * 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 #include "unicode/utypes.h" #include "unicode/unistr.h" class U_I18N_API Formattable { public: enum ISDATE { kIsDate }; Formattable(); // Type kLong, value 0 Formattable(UDate d, ISDATE); Formattable(double d); Formattable(int32_t l); Formattable(const char* strToCopy); Formattable(const UnicodeString& stringToCopy); Formattable(UnicodeString* stringToAdopt); Formattable(const Formattable* arrayToCopy, int32_t count); Formattable(const Formattable&); Formattable& operator=(const Formattable&); UBool operator==(const Formattable&) const; UBool operator!=(const Formattable& other) const { return !operator==(other); } virtual ~Formattable(); enum Type { kDate, // Date kDouble, // double kLong, // long kString, // UnicodeString kArray // Formattable[] }; Type getType(void) const; double getDouble(void) const { return fValue.fDouble; } int32_t getLong(void) const { return fValue.fLong; } UDate getDate(void) const { return fValue.fDate; } UnicodeString& getString(UnicodeString& result) const { result=*fValue.fString; return result; } inline const UnicodeString& getString(void) const; inline UnicodeString& getString(void); const Formattable* getArray(int32_t& count) const { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; } Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; } void setDouble(double d); void setLong(int32_t l); void setDate(UDate d); void setString(const UnicodeString& stringToCopy); void setArray(const Formattable* array, int32_t count); void adoptString(UnicodeString* stringToAdopt); void adoptArray(Formattable* array, int32_t count); private: void dispose(void); static Formattable* createArrayCopy(const Formattable* array, int32_t count); // 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; int32_t fLong; UDate fDate; struct { Formattable* fArray; int32_t fCount; } fArrayAndCount; } fValue; Type fType; }; 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; } inline const UnicodeString& Formattable::getString(void) const { return *fValue.fString; } inline UnicodeString& Formattable::getString(void) { return *fValue.fString; } #endif //_FMTABLE //eof