00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef FMTABLE_H
00016 #define FMTABLE_H
00017
00018
00019 #include "unicode/utypes.h"
00020 #include "unicode/uobject.h"
00021 #include "unicode/unistr.h"
00022
00023 U_NAMESPACE_BEGIN
00024
00041 class U_I18N_API Formattable : public UObject {
00042 public:
00051 enum ISDATE { kIsDate };
00052
00053 Formattable();
00060 Formattable(UDate d, ISDATE);
00066 Formattable(double d);
00072 Formattable(int32_t l);
00079 Formattable(const char* strToCopy);
00085 Formattable(const UnicodeString& stringToCopy);
00091 Formattable(UnicodeString* stringToAdopt);
00098 Formattable(const Formattable* arrayToCopy, int32_t count);
00099
00104 Formattable(const Formattable&);
00109 Formattable& operator=(const Formattable&);
00116 UBool operator==(const Formattable&) const;
00117
00124 UBool operator!=(const Formattable& other) const
00125 { return !operator==(other); }
00126
00131 virtual ~Formattable();
00132
00136 enum Type {
00137 kDate,
00138 kDouble,
00139 kLong,
00140 kString,
00141 kArray
00142 };
00143
00149 Type getType(void) const;
00150
00156 double getDouble(void) const { return fValue.fDouble; }
00162 int32_t getLong(void) const { return fValue.fLong; }
00168 UDate getDate(void) const { return fValue.fDate; }
00169
00176 UnicodeString& getString(UnicodeString& result) const
00177 { result=*fValue.fString; return result; }
00178
00184 inline const UnicodeString& getString(void) const;
00185
00191 inline UnicodeString& getString(void);
00192
00199 const Formattable* getArray(int32_t& count) const
00200 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00201
00208 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00209
00215 void setDouble(double d);
00221 void setLong(int32_t l);
00227 void setDate(UDate d);
00233 void setString(const UnicodeString& stringToCopy);
00240 void setArray(const Formattable* array, int32_t count);
00246 void adoptString(UnicodeString* stringToAdopt);
00251 void adoptArray(Formattable* array, int32_t count);
00252
00258 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
00259
00265 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
00266
00267 private:
00272 void dispose(void);
00273
00281 static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00282
00283
00284
00285
00286 union {
00287 UnicodeString* fString;
00288 double fDouble;
00289 int32_t fLong;
00290 UDate fDate;
00291 struct
00292 {
00293 Formattable* fArray;
00294 int32_t fCount;
00295 } fArrayAndCount;
00296 } fValue;
00297
00298 Type fType;
00299
00304 static const char fgClassID;
00305 };
00306
00307 inline Formattable*
00308 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00309 {
00310 Formattable *result = new Formattable[count];
00311 for (int32_t i=0; i<count; ++i) result[i] = array[i];
00312 return result;
00313 }
00314
00315 inline const UnicodeString& Formattable::getString(void) const {
00316 return *fValue.fString;
00317 }
00318
00319 inline UnicodeString& Formattable::getString(void) {
00320 return *fValue.fString;
00321 }
00322
00323 U_NAMESPACE_END
00324
00325 #endif //_FMTABLE
00326
00327