Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

fmtable.h

00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-2003, 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 00021 #if !UCONFIG_NO_FORMATTING 00022 00023 U_NAMESPACE_BEGIN 00024 00043 class U_I18N_API Formattable : public UObject { 00044 public: 00054 enum ISDATE { kIsDate }; 00055 00060 Formattable(); // Type kLong, value 0 00061 00068 Formattable(UDate d, ISDATE flag); 00069 00075 Formattable(double d); 00076 00082 Formattable(int32_t l); 00083 00089 Formattable(int64_t ll); 00090 00097 Formattable(const char* strToCopy); 00098 00104 Formattable(const UnicodeString& strToCopy); 00105 00111 Formattable(UnicodeString* strToAdopt); 00112 00119 Formattable(const Formattable* arrayToCopy, int32_t count); 00120 00125 Formattable(const Formattable&); 00126 00132 Formattable& operator=(const Formattable &rhs); 00133 00140 UBool operator==(const Formattable &other) const; 00141 00148 UBool operator!=(const Formattable& other) const 00149 { return !operator==(other); } 00150 00155 virtual ~Formattable(); 00156 00168 Formattable *clone() const; 00169 00174 enum Type { 00176 kDate, // Date 00178 kDouble, // double 00180 kLong, // long 00182 kString, // UnicodeString 00184 kArray, // Formattable[] 00186 kInt64 // int64 00187 }; 00188 00194 Type getType(void) const; 00195 00201 double getDouble(void) const { return fValue.fDouble; } 00202 00212 double getDouble(UErrorCode* status) const; 00213 00219 int32_t getLong(void) const { return (int32_t)fValue.fInt64; } 00220 00232 int32_t getLong(UErrorCode* status) const; 00233 00239 int64_t getInt64(void) const { return fValue.fInt64; } 00240 00252 int64_t getInt64(UErrorCode* status) const; 00253 00259 UDate getDate() const { return fValue.fDate; } 00260 00268 UDate getDate(UErrorCode* status) const; 00269 00276 UnicodeString& getString(UnicodeString& result) const 00277 { result=*fValue.fString; return result; } 00278 00287 UnicodeString& getString(UnicodeString& result, UErrorCode* status) const; 00288 00294 inline const UnicodeString& getString(void) const; 00295 00303 const UnicodeString& getString(UErrorCode* status) const; 00304 00310 inline UnicodeString& getString(void); 00311 00319 UnicodeString& getString(UErrorCode* status); 00320 00327 const Formattable* getArray(int32_t& count) const 00328 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; } 00329 00338 const Formattable* getArray(int32_t& count, UErrorCode* status) const; 00339 00346 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; } 00347 00353 void setDouble(double d); 00354 00360 void setLong(int32_t l); 00361 00367 void setInt64(int64_t ll); 00368 00374 void setDate(UDate d); 00375 00381 void setString(const UnicodeString& stringToCopy); 00382 00389 void setArray(const Formattable* array, int32_t count); 00390 00396 void adoptString(UnicodeString* stringToAdopt); 00397 00402 void adoptArray(Formattable* array, int32_t count); 00403 00409 virtual UClassID getDynamicClassID() const; 00410 00416 static UClassID getStaticClassID(); 00417 00418 private: 00423 void dispose(void); 00424 00432 static Formattable* createArrayCopy(const Formattable* array, int32_t count); 00433 00434 UnicodeString* getBogus() const; 00435 00436 // Note: For now, we do not handle unsigned long and unsigned 00437 // double types. Smaller unsigned types, such as unsigned 00438 // short, can fit within a long. 00439 union { 00440 UnicodeString* fString; 00441 double fDouble; 00442 int64_t fInt64; 00443 UDate fDate; 00444 struct 00445 { 00446 Formattable* fArray; 00447 int32_t fCount; 00448 } fArrayAndCount; 00449 } fValue; 00450 00451 Type fType; 00452 UnicodeString fBogus; // Bogus string when it's needed. 00453 }; 00454 00455 inline Formattable* 00456 Formattable::createArrayCopy(const Formattable* array, int32_t count) 00457 { 00458 Formattable *result = new Formattable[count]; 00459 for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy! 00460 return result; 00461 } 00462 00463 inline UDate Formattable::getDate(UErrorCode* status) const { 00464 if (status && U_SUCCESS(*status) && fType != kDate) { 00465 *status = U_INVALID_FORMAT_ERROR; 00466 return 0; 00467 } 00468 return fValue.fDate; 00469 } 00470 00471 inline const UnicodeString& Formattable::getString(void) const { 00472 return *fValue.fString; 00473 } 00474 00475 inline UnicodeString& Formattable::getString(void) { 00476 return *fValue.fString; 00477 } 00478 00479 U_NAMESPACE_END 00480 00481 #endif /* #if !UCONFIG_NO_FORMATTING */ 00482 00483 #endif //_FMTABLE 00484 //eof 00485

Generated on Wed Sep 15 17:18:09 2004 for ICU 2.8 by doxygen 1.3.8