ICU 49.1.2
49.1.2
|
00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-2012, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ******************************************************************************** 00006 * 00007 * File FMTABLE.H 00008 * 00009 * Modification History: 00010 * 00011 * Date Name Description 00012 * 02/29/97 aliu Creation. 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 00052 class U_I18N_API Formattable : public UObject { 00053 public: 00063 enum ISDATE { kIsDate }; 00064 00069 Formattable(); // Type kLong, value 0 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 00587 #ifndef U_HIDE_DEPRECATED_API 00588 00594 inline int32_t getLong(UErrorCode* status) const; 00595 #endif /* U_HIDE_DEPRECATED_API */ 00596 00597 #ifndef U_HIDE_INTERNAL_API 00598 00606 DigitList *getDigitList() const { return fDecimalNum;} 00607 00608 #if UCONFIG_INTERNAL_DIGITLIST 00609 00612 DigitList *getInternalDigitList(); 00613 #endif 00614 00615 00622 void adoptDigitList(DigitList *dl); 00623 #endif /* U_HIDE_INTERNAL_API */ 00624 00625 private: 00630 void dispose(void); 00631 00635 void init(); 00636 00637 UnicodeString* getBogus() const; 00638 00639 union { 00640 UObject* fObject; 00641 UnicodeString* fString; 00642 double fDouble; 00643 int64_t fInt64; 00644 UDate fDate; 00645 struct { 00646 Formattable* fArray; 00647 int32_t fCount; 00648 } fArrayAndCount; 00649 } fValue; 00650 00651 CharString *fDecimalStr; 00652 00653 DigitList *fDecimalNum; 00654 00655 #if UCONFIG_INTERNAL_DIGITLIST 00656 char fStackData[128]; // must be big enough for DigitList 00657 #endif 00658 00659 Type fType; 00660 UnicodeString fBogus; // Bogus string when it's needed. 00661 }; 00662 00663 inline UDate Formattable::getDate(UErrorCode& status) const { 00664 if (fType != kDate) { 00665 if (U_SUCCESS(status)) { 00666 status = U_INVALID_FORMAT_ERROR; 00667 } 00668 return 0; 00669 } 00670 return fValue.fDate; 00671 } 00672 00673 inline const UnicodeString& Formattable::getString(void) const { 00674 return *fValue.fString; 00675 } 00676 00677 inline UnicodeString& Formattable::getString(void) { 00678 return *fValue.fString; 00679 } 00680 00681 #ifndef U_HIDE_DEPRECATED_API 00682 inline int32_t Formattable::getLong(UErrorCode* status) const { 00683 return getLong(*status); 00684 } 00685 #endif 00686 00687 00688 U_NAMESPACE_END 00689 00690 #endif /* #if !UCONFIG_NO_FORMATTING */ 00691 00692 #endif //_FMTABLE 00693 //eof