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
00021 #if !UCONFIG_NO_FORMATTING
00022
00023 #include "unicode/uobject.h"
00024 #include "unicode/unistr.h"
00025
00026 U_NAMESPACE_BEGIN
00027
00044 class U_I18N_API Formattable : public UObject {
00045 public:
00055 enum ISDATE { kIsDate };
00056
00061 Formattable();
00068 Formattable(UDate d, ISDATE);
00074 Formattable(double d);
00080 Formattable(int32_t l);
00087 Formattable(const char* strToCopy);
00093 Formattable(const UnicodeString& stringToCopy);
00099 Formattable(UnicodeString* stringToAdopt);
00106 Formattable(const Formattable* arrayToCopy, int32_t count);
00107
00112 Formattable(const Formattable&);
00117 Formattable& operator=(const Formattable&);
00124 UBool operator==(const Formattable&) const;
00125
00132 UBool operator!=(const Formattable& other) const
00133 { return !operator==(other); }
00134
00139 virtual ~Formattable();
00140
00145 enum Type {
00146 kDate,
00147 kDouble,
00148 kLong,
00149 kString,
00150 kArray
00151 };
00152
00158 Type getType(void) const;
00159
00165 double getDouble(void) const { return fValue.fDouble; }
00171 int32_t getLong(void) const { return fValue.fLong; }
00177 UDate getDate(void) const { return fValue.fDate; }
00178
00185 UnicodeString& getString(UnicodeString& result) const
00186 { result=*fValue.fString; return result; }
00187
00193 inline const UnicodeString& getString(void) const;
00194
00200 inline UnicodeString& getString(void);
00201
00208 const Formattable* getArray(int32_t& count) const
00209 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00210
00217 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00218
00224 void setDouble(double d);
00230 void setLong(int32_t l);
00236 void setDate(UDate d);
00242 void setString(const UnicodeString& stringToCopy);
00249 void setArray(const Formattable* array, int32_t count);
00255 void adoptString(UnicodeString* stringToAdopt);
00260 void adoptArray(Formattable* array, int32_t count);
00261
00267 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
00268
00274 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
00275
00276 private:
00281 void dispose(void);
00282
00290 static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00291
00292
00293
00294
00295 union {
00296 UnicodeString* fString;
00297 double fDouble;
00298 int32_t fLong;
00299 UDate fDate;
00300 struct
00301 {
00302 Formattable* fArray;
00303 int32_t fCount;
00304 } fArrayAndCount;
00305 } fValue;
00306
00307 Type fType;
00308
00313 static const char fgClassID;
00314 };
00315
00316 inline Formattable*
00317 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00318 {
00319 Formattable *result = new Formattable[count];
00320 for (int32_t i=0; i<count; ++i) result[i] = array[i];
00321 return result;
00322 }
00323
00324 inline const UnicodeString& Formattable::getString(void) const {
00325 return *fValue.fString;
00326 }
00327
00328 inline UnicodeString& Formattable::getString(void) {
00329 return *fValue.fString;
00330 }
00331
00332 U_NAMESPACE_END
00333
00334 #endif
00335
00336 #endif //_FMTABLE
00337
00338