00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef FMTABLE_H
00016 #define FMTABLE_H
00017
00018 #include "unicode/utypes.h"
00019 #include "unicode/unistr.h"
00020
00021 #if !UCONFIG_NO_FORMATTING
00022
00023 U_NAMESPACE_BEGIN
00024
00043 class U_I18N_API Formattable : public UObject {
00044 public:
00054 enum ISDATE { kIsDate };
00055
00060 Formattable();
00061
00068 Formattable(UDate d, ISDATE flag);
00069
00075 Formattable(double d);
00076
00082 Formattable(int32_t l);
00083
00089 Formattable(int64_t ll);
00090
00097 Formattable(const char* strToCopy);
00098
00104 Formattable(const UnicodeString& strToCopy);
00105
00111 Formattable(UnicodeString* strToAdopt);
00112
00119 Formattable(const Formattable* arrayToCopy, int32_t count);
00120
00126 Formattable(UObject* objectToAdopt);
00127
00132 Formattable(const Formattable&);
00133
00139 Formattable& operator=(const Formattable &rhs);
00140
00147 UBool operator==(const Formattable &other) const;
00148
00155 UBool operator!=(const Formattable& other) const
00156 { return !operator==(other); }
00157
00162 virtual ~Formattable();
00163
00175 Formattable *clone() const;
00176
00183 enum Type {
00189 kDate,
00190
00196 kDouble,
00197
00203 kLong,
00204
00210 kString,
00211
00217 kArray,
00218
00224 kInt64,
00225
00231 kObject
00232 };
00233
00239 Type getType(void) const;
00240
00247 UBool isNumeric() const;
00248
00255 double getDouble(void) const { return fValue.fDouble; }
00256
00269 double getDouble(UErrorCode& status) const;
00270
00277 int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
00278
00295 int32_t getLong(UErrorCode& status) const;
00296
00303 int64_t getInt64(void) const { return fValue.fInt64; }
00304
00320 int64_t getInt64(UErrorCode& status) const;
00321
00328 UDate getDate() const { return fValue.fDate; }
00329
00338 UDate getDate(UErrorCode& status) const;
00339
00347 UnicodeString& getString(UnicodeString& result) const
00348 { result=*fValue.fString; return result; }
00349
00359 UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
00360
00368 inline const UnicodeString& getString(void) const;
00369
00378 const UnicodeString& getString(UErrorCode& status) const;
00379
00386 inline UnicodeString& getString(void);
00387
00396 UnicodeString& getString(UErrorCode& status);
00397
00405 const Formattable* getArray(int32_t& count) const
00406 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00407
00417 const Formattable* getArray(int32_t& count, UErrorCode& status) const;
00418
00427 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00428
00435 const UObject* getObject() const;
00436
00443 void setDouble(double d);
00444
00451 void setLong(int32_t l);
00452
00459 void setInt64(int64_t ll);
00460
00467 void setDate(UDate d);
00468
00475 void setString(const UnicodeString& stringToCopy);
00476
00484 void setArray(const Formattable* array, int32_t count);
00485
00492 void adoptString(UnicodeString* stringToAdopt);
00493
00499 void adoptArray(Formattable* array, int32_t count);
00500
00508 void adoptObject(UObject* objectToAdopt);
00509
00515 virtual UClassID getDynamicClassID() const;
00516
00522 static UClassID U_EXPORT2 getStaticClassID();
00523
00530 inline int32_t getLong(UErrorCode* status) const;
00531
00532 private:
00537 void dispose(void);
00538
00546 static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00547
00548 UnicodeString* getBogus() const;
00549
00550 union {
00551 UObject* fObject;
00552 UnicodeString* fString;
00553 double fDouble;
00554 int64_t fInt64;
00555 UDate fDate;
00556 struct {
00557 Formattable* fArray;
00558 int32_t fCount;
00559 } fArrayAndCount;
00560 } fValue;
00561
00562 Type fType;
00563 UnicodeString fBogus;
00564 };
00565
00566 inline Formattable*
00567 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00568 {
00569 Formattable *result = new Formattable[count];
00570 for (int32_t i=0; i<count; ++i) result[i] = array[i];
00571 return result;
00572 }
00573
00574 inline UDate Formattable::getDate(UErrorCode& status) const {
00575 if (fType != kDate) {
00576 if (U_SUCCESS(status)) {
00577 status = U_INVALID_FORMAT_ERROR;
00578 }
00579 return 0;
00580 }
00581 return fValue.fDate;
00582 }
00583
00584 inline const UnicodeString& Formattable::getString(void) const {
00585 return *fValue.fString;
00586 }
00587
00588 inline UnicodeString& Formattable::getString(void) {
00589 return *fValue.fString;
00590 }
00591
00592 inline int32_t Formattable::getLong(UErrorCode* status) const {
00593 return getLong(*status);
00594 }
00595
00596 U_NAMESPACE_END
00597
00598 #endif
00599
00600 #endif //_FMTABLE
00601
00602