Go to the documentation of this file.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 DecimalNumberString;
00032 class DigitList;
00033
00052 class U_I18N_API Formattable : public UObject {
00053 public:
00063 enum ISDATE { kIsDate };
00064
00069 Formattable();
00070
00077 Formattable(UDate d, ISDATE flag);
00078
00084 Formattable(double d);
00085
00091 Formattable(int32_t l);
00092
00098 Formattable(int64_t ll);
00099
00100 #if !UCONFIG_NO_CONVERSION
00101
00107 Formattable(const char* strToCopy);
00108 #endif
00109
00123 Formattable(const StringPiece &number, UErrorCode &status);
00124
00130 Formattable(const UnicodeString& strToCopy);
00131
00137 Formattable(UnicodeString* strToAdopt);
00138
00145 Formattable(const Formattable* arrayToCopy, int32_t count);
00146
00152 Formattable(UObject* objectToAdopt);
00153
00158 Formattable(const Formattable&);
00159
00165 Formattable& operator=(const Formattable &rhs);
00166
00173 UBool operator==(const Formattable &other) const;
00174
00181 UBool operator!=(const Formattable& other) const
00182 { return !operator==(other); }
00183
00188 virtual ~Formattable();
00189
00201 Formattable *clone() const;
00202
00209 enum Type {
00215 kDate,
00216
00222 kDouble,
00223
00229 kLong,
00230
00236 kString,
00237
00243 kArray,
00244
00250 kInt64,
00251
00257 kObject
00258 };
00259
00265 Type getType(void) const;
00266
00273 UBool isNumeric() const;
00274
00281 double getDouble(void) const { return fValue.fDouble; }
00282
00295 double getDouble(UErrorCode& status) const;
00296
00303 int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
00304
00321 int32_t getLong(UErrorCode& status) const;
00322
00329 int64_t getInt64(void) const { return fValue.fInt64; }
00330
00346 int64_t getInt64(UErrorCode& status) const;
00347
00354 UDate getDate() const { return fValue.fDate; }
00355
00364 UDate getDate(UErrorCode& status) const;
00365
00373 UnicodeString& getString(UnicodeString& result) const
00374 { result=*fValue.fString; return result; }
00375
00385 UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
00386
00394 inline const UnicodeString& getString(void) const;
00395
00404 const UnicodeString& getString(UErrorCode& status) const;
00405
00412 inline UnicodeString& getString(void);
00413
00422 UnicodeString& getString(UErrorCode& status);
00423
00431 const Formattable* getArray(int32_t& count) const
00432 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00433
00443 const Formattable* getArray(int32_t& count, UErrorCode& status) const;
00444
00453 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00454
00461 const UObject* getObject() const;
00462
00481 StringPiece getDecimalNumber(UErrorCode &status);
00482
00489 void setDouble(double d);
00490
00497 void setLong(int32_t l);
00498
00505 void setInt64(int64_t ll);
00506
00513 void setDate(UDate d);
00514
00521 void setString(const UnicodeString& stringToCopy);
00522
00530 void setArray(const Formattable* array, int32_t count);
00531
00538 void adoptString(UnicodeString* stringToAdopt);
00539
00545 void adoptArray(Formattable* array, int32_t count);
00546
00554 void adoptObject(UObject* objectToAdopt);
00555
00570 void setDecimalNumber(const StringPiece &numberString,
00571 UErrorCode &status);
00572
00578 virtual UClassID getDynamicClassID() const;
00579
00585 static UClassID U_EXPORT2 getStaticClassID();
00586
00593 inline int32_t getLong(UErrorCode* status) const;
00594
00603 DigitList *getDigitList() const { return fDecimalNum;};
00604
00612 void adoptDigitList(DigitList *dl);
00613
00614 private:
00619 void dispose(void);
00620
00624 void init();
00625
00626 UnicodeString* getBogus() const;
00627
00628 union {
00629 UObject* fObject;
00630 UnicodeString* fString;
00631 double fDouble;
00632 int64_t fInt64;
00633 UDate fDate;
00634 struct {
00635 Formattable* fArray;
00636 int32_t fCount;
00637 } fArrayAndCount;
00638 } fValue;
00639
00640 DecimalNumberString *fDecimalStr;
00641 DigitList *fDecimalNum;
00642
00643 Type fType;
00644 UnicodeString fBogus;
00645 };
00646
00647 inline UDate Formattable::getDate(UErrorCode& status) const {
00648 if (fType != kDate) {
00649 if (U_SUCCESS(status)) {
00650 status = U_INVALID_FORMAT_ERROR;
00651 }
00652 return 0;
00653 }
00654 return fValue.fDate;
00655 }
00656
00657 inline const UnicodeString& Formattable::getString(void) const {
00658 return *fValue.fString;
00659 }
00660
00661 inline UnicodeString& Formattable::getString(void) {
00662 return *fValue.fString;
00663 }
00664
00665 inline int32_t Formattable::getLong(UErrorCode* status) const {
00666 return getLong(*status);
00667 }
00668
00669 U_NAMESPACE_END
00670
00671 #endif
00672
00673 #endif //_FMTABLE
00674
00675