ICU 4.8.1.1
4.8.1.1
|
00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-2011, 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 00593 inline int32_t getLong(UErrorCode* status) const; 00594 00603 DigitList *getDigitList() const { return fDecimalNum;} 00604 00611 void adoptDigitList(DigitList *dl); 00612 00613 private: 00618 void dispose(void); 00619 00623 void init(); 00624 00625 UnicodeString* getBogus() const; 00626 00627 union { 00628 UObject* fObject; 00629 UnicodeString* fString; 00630 double fDouble; 00631 int64_t fInt64; 00632 UDate fDate; 00633 struct { 00634 Formattable* fArray; 00635 int32_t fCount; 00636 } fArrayAndCount; 00637 } fValue; 00638 00639 CharString *fDecimalStr; 00640 DigitList *fDecimalNum; 00641 00642 Type fType; 00643 UnicodeString fBogus; // Bogus string when it's needed. 00644 }; 00645 00646 inline UDate Formattable::getDate(UErrorCode& status) const { 00647 if (fType != kDate) { 00648 if (U_SUCCESS(status)) { 00649 status = U_INVALID_FORMAT_ERROR; 00650 } 00651 return 0; 00652 } 00653 return fValue.fDate; 00654 } 00655 00656 inline const UnicodeString& Formattable::getString(void) const { 00657 return *fValue.fString; 00658 } 00659 00660 inline UnicodeString& Formattable::getString(void) { 00661 return *fValue.fString; 00662 } 00663 00664 inline int32_t Formattable::getLong(UErrorCode* status) const { 00665 return getLong(*status); 00666 } 00667 00668 U_NAMESPACE_END 00669 00670 #endif /* #if !UCONFIG_NO_FORMATTING */ 00671 00672 #endif //_FMTABLE 00673 //eof