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"
00025 #if !UCONFIG_NO_FORMATTING
00026
00027 U_NAMESPACE_BEGIN
00028
00047 class U_I18N_API Formattable : public UObject {
00048 public:
00058 enum ISDATE { kIsDate };
00059
00064 Formattable();
00065
00072 Formattable(UDate d, ISDATE flag);
00073
00079 Formattable(double d);
00080
00086 Formattable(int32_t l);
00087
00093 Formattable(int64_t ll);
00094
00095 #if !UCONFIG_NO_CONVERSION
00096
00102 Formattable(const char* strToCopy);
00103 #endif
00104
00110 Formattable(const UnicodeString& strToCopy);
00111
00117 Formattable(UnicodeString* strToAdopt);
00118
00125 Formattable(const Formattable* arrayToCopy, int32_t count);
00126
00132 Formattable(UObject* objectToAdopt);
00133
00138 Formattable(const Formattable&);
00139
00145 Formattable& operator=(const Formattable &rhs);
00146
00153 UBool operator==(const Formattable &other) const;
00154
00161 UBool operator!=(const Formattable& other) const
00162 { return !operator==(other); }
00163
00168 virtual ~Formattable();
00169
00181 Formattable *clone() const;
00182
00189 enum Type {
00195 kDate,
00196
00202 kDouble,
00203
00209 kLong,
00210
00216 kString,
00217
00223 kArray,
00224
00230 kInt64,
00231
00237 kObject
00238 };
00239
00245 Type getType(void) const;
00246
00253 UBool isNumeric() const;
00254
00261 double getDouble(void) const { return fValue.fDouble; }
00262
00275 double getDouble(UErrorCode& status) const;
00276
00283 int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
00284
00301 int32_t getLong(UErrorCode& status) const;
00302
00309 int64_t getInt64(void) const { return fValue.fInt64; }
00310
00326 int64_t getInt64(UErrorCode& status) const;
00327
00334 UDate getDate() const { return fValue.fDate; }
00335
00344 UDate getDate(UErrorCode& status) const;
00345
00353 UnicodeString& getString(UnicodeString& result) const
00354 { result=*fValue.fString; return result; }
00355
00365 UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
00366
00374 inline const UnicodeString& getString(void) const;
00375
00384 const UnicodeString& getString(UErrorCode& status) const;
00385
00392 inline UnicodeString& getString(void);
00393
00402 UnicodeString& getString(UErrorCode& status);
00403
00411 const Formattable* getArray(int32_t& count) const
00412 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00413
00423 const Formattable* getArray(int32_t& count, UErrorCode& status) const;
00424
00433 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00434
00441 const UObject* getObject() const;
00442
00449 void setDouble(double d);
00450
00457 void setLong(int32_t l);
00458
00465 void setInt64(int64_t ll);
00466
00473 void setDate(UDate d);
00474
00481 void setString(const UnicodeString& stringToCopy);
00482
00490 void setArray(const Formattable* array, int32_t count);
00491
00498 void adoptString(UnicodeString* stringToAdopt);
00499
00505 void adoptArray(Formattable* array, int32_t count);
00506
00514 void adoptObject(UObject* objectToAdopt);
00515
00521 virtual UClassID getDynamicClassID() const;
00522
00528 static UClassID U_EXPORT2 getStaticClassID();
00529
00536 inline int32_t getLong(UErrorCode* status) const;
00537
00538 private:
00543 void dispose(void);
00544
00552 static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00553
00554 UnicodeString* getBogus() const;
00555
00556 union {
00557 UObject* fObject;
00558 UnicodeString* fString;
00559 double fDouble;
00560 int64_t fInt64;
00561 UDate fDate;
00562 struct {
00563 Formattable* fArray;
00564 int32_t fCount;
00565 } fArrayAndCount;
00566 } fValue;
00567
00568 Type fType;
00569 UnicodeString fBogus;
00570 };
00571
00572 inline Formattable*
00573 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00574 {
00575 Formattable *result = new Formattable[count];
00576 for (int32_t i=0; i<count; ++i) result[i] = array[i];
00577 return result;
00578 }
00579
00580 inline UDate Formattable::getDate(UErrorCode& status) const {
00581 if (fType != kDate) {
00582 if (U_SUCCESS(status)) {
00583 status = U_INVALID_FORMAT_ERROR;
00584 }
00585 return 0;
00586 }
00587 return fValue.fDate;
00588 }
00589
00590 inline const UnicodeString& Formattable::getString(void) const {
00591 return *fValue.fString;
00592 }
00593
00594 inline UnicodeString& Formattable::getString(void) {
00595 return *fValue.fString;
00596 }
00597
00598 inline int32_t Formattable::getLong(UErrorCode* status) const {
00599 return getLong(*status);
00600 }
00601
00602 U_NAMESPACE_END
00603
00604 #endif
00605
00606 #endif //_FMTABLE
00607
00608