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 #include "unicode/stringpiece.h"
00021
00027 #if !UCONFIG_NO_FORMATTING
00028
00029 U_NAMESPACE_BEGIN
00030
00031 class CharString;
00032 class DigitList;
00033
00038 #if U_PLATFORM == U_PF_OS400
00039 #define UNUM_INTERNAL_STACKARRAY_SIZE 144
00040 #else
00041 #define UNUM_INTERNAL_STACKARRAY_SIZE 128
00042 #endif
00043
00062 class U_I18N_API Formattable : public UObject {
00063 public:
00073 enum ISDATE { kIsDate };
00074
00079 Formattable();
00080
00087 Formattable(UDate d, ISDATE flag);
00088
00094 Formattable(double d);
00095
00101 Formattable(int32_t l);
00102
00108 Formattable(int64_t ll);
00109
00110 #if !UCONFIG_NO_CONVERSION
00111
00117 Formattable(const char* strToCopy);
00118 #endif
00119
00133 Formattable(const StringPiece &number, UErrorCode &status);
00134
00140 Formattable(const UnicodeString& strToCopy);
00141
00147 Formattable(UnicodeString* strToAdopt);
00148
00155 Formattable(const Formattable* arrayToCopy, int32_t count);
00156
00162 Formattable(UObject* objectToAdopt);
00163
00168 Formattable(const Formattable&);
00169
00175 Formattable& operator=(const Formattable &rhs);
00176
00183 UBool operator==(const Formattable &other) const;
00184
00191 UBool operator!=(const Formattable& other) const
00192 { return !operator==(other); }
00193
00198 virtual ~Formattable();
00199
00211 Formattable *clone() const;
00212
00219 enum Type {
00225 kDate,
00226
00232 kDouble,
00233
00239 kLong,
00240
00246 kString,
00247
00253 kArray,
00254
00260 kInt64,
00261
00267 kObject
00268 };
00269
00275 Type getType(void) const;
00276
00283 UBool isNumeric() const;
00284
00291 double getDouble(void) const { return fValue.fDouble; }
00292
00305 double getDouble(UErrorCode& status) const;
00306
00313 int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
00314
00331 int32_t getLong(UErrorCode& status) const;
00332
00339 int64_t getInt64(void) const { return fValue.fInt64; }
00340
00356 int64_t getInt64(UErrorCode& status) const;
00357
00364 UDate getDate() const { return fValue.fDate; }
00365
00374 UDate getDate(UErrorCode& status) const;
00375
00383 UnicodeString& getString(UnicodeString& result) const
00384 { result=*fValue.fString; return result; }
00385
00395 UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
00396
00404 inline const UnicodeString& getString(void) const;
00405
00414 const UnicodeString& getString(UErrorCode& status) const;
00415
00422 inline UnicodeString& getString(void);
00423
00432 UnicodeString& getString(UErrorCode& status);
00433
00441 const Formattable* getArray(int32_t& count) const
00442 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00443
00453 const Formattable* getArray(int32_t& count, UErrorCode& status) const;
00454
00463 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00464
00471 const UObject* getObject() const;
00472
00491 StringPiece getDecimalNumber(UErrorCode &status);
00492
00499 void setDouble(double d);
00500
00507 void setLong(int32_t l);
00508
00515 void setInt64(int64_t ll);
00516
00523 void setDate(UDate d);
00524
00531 void setString(const UnicodeString& stringToCopy);
00532
00540 void setArray(const Formattable* array, int32_t count);
00541
00548 void adoptString(UnicodeString* stringToAdopt);
00549
00555 void adoptArray(Formattable* array, int32_t count);
00556
00564 void adoptObject(UObject* objectToAdopt);
00565
00580 void setDecimalNumber(const StringPiece &numberString,
00581 UErrorCode &status);
00582
00588 virtual UClassID getDynamicClassID() const;
00589
00595 static UClassID U_EXPORT2 getStaticClassID();
00596
00597 #ifndef U_HIDE_DEPRECATED_API
00598
00604 inline int32_t getLong(UErrorCode* status) const;
00605 #endif
00606
00607 #ifndef U_HIDE_INTERNAL_API
00608
00616 DigitList *getDigitList() const { return fDecimalNum;}
00617
00621 DigitList *getInternalDigitList();
00622
00629 void adoptDigitList(DigitList *dl);
00630 #endif
00631
00632 private:
00637 void dispose(void);
00638
00642 void init();
00643
00644 UnicodeString* getBogus() const;
00645
00646 union {
00647 UObject* fObject;
00648 UnicodeString* fString;
00649 double fDouble;
00650 int64_t fInt64;
00651 UDate fDate;
00652 struct {
00653 Formattable* fArray;
00654 int32_t fCount;
00655 } fArrayAndCount;
00656 } fValue;
00657
00658 CharString *fDecimalStr;
00659
00660 DigitList *fDecimalNum;
00661
00662 char fStackData[UNUM_INTERNAL_STACKARRAY_SIZE];
00663
00664 Type fType;
00665 UnicodeString fBogus;
00666 };
00667
00668 inline UDate Formattable::getDate(UErrorCode& status) const {
00669 if (fType != kDate) {
00670 if (U_SUCCESS(status)) {
00671 status = U_INVALID_FORMAT_ERROR;
00672 }
00673 return 0;
00674 }
00675 return fValue.fDate;
00676 }
00677
00678 inline const UnicodeString& Formattable::getString(void) const {
00679 return *fValue.fString;
00680 }
00681
00682 inline UnicodeString& Formattable::getString(void) {
00683 return *fValue.fString;
00684 }
00685
00686 #ifndef U_HIDE_DEPRECATED_API
00687 inline int32_t Formattable::getLong(UErrorCode* status) const {
00688 return getLong(*status);
00689 }
00690 #endif
00691
00692
00693 U_NAMESPACE_END
00694
00695 #endif
00696
00697 #endif //_FMTABLE
00698