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

fmtable.h

00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-1999, 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 00019 #include "unicode/utypes.h" 00020 #include "unicode/unistr.h" 00021 00022 U_NAMESPACE_BEGIN 00023 00040 class U_I18N_API Formattable { 00041 public: 00050 enum ISDATE { kIsDate }; 00051 00052 Formattable(); // Type kLong, value 0 00059 Formattable(UDate d, ISDATE); 00065 Formattable(double d); 00071 Formattable(int32_t l); 00078 Formattable(const char* strToCopy); 00084 Formattable(const UnicodeString& stringToCopy); 00090 Formattable(UnicodeString* stringToAdopt); 00097 Formattable(const Formattable* arrayToCopy, int32_t count); 00098 00103 Formattable(const Formattable&); 00108 Formattable& operator=(const Formattable&); 00113 UBool operator==(const Formattable&) const; 00114 UBool operator!=(const Formattable& other) const 00115 { return !operator==(other); } 00116 00121 virtual ~Formattable(); 00122 00126 enum Type { 00127 kDate, // Date 00128 kDouble, // double 00129 kLong, // long 00130 kString, // UnicodeString 00131 kArray // Formattable[] 00132 }; 00133 00138 Type getType(void) const; 00139 00144 double getDouble(void) const { return fValue.fDouble; } 00149 int32_t getLong(void) const { return fValue.fLong; } 00154 UDate getDate(void) const { return fValue.fDate; } 00155 00160 UnicodeString& getString(UnicodeString& result) const 00161 { result=*fValue.fString; return result; } 00162 00167 inline const UnicodeString& getString(void) const; 00168 00173 inline UnicodeString& getString(void); 00174 00179 const Formattable* getArray(int32_t& count) const 00180 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; } 00181 00188 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; } 00189 00194 void setDouble(double d); 00199 void setLong(int32_t l); 00204 void setDate(UDate d); 00209 void setString(const UnicodeString& stringToCopy); 00214 void setArray(const Formattable* array, int32_t count); 00219 void adoptString(UnicodeString* stringToAdopt); 00224 void adoptArray(Formattable* array, int32_t count); 00225 00226 private: 00231 void dispose(void); 00232 00240 static Formattable* createArrayCopy(const Formattable* array, int32_t count); 00241 00242 // Note: For now, we do not handle unsigned long and unsigned 00243 // double types. Smaller unsigned types, such as unsigned 00244 // short, can fit within a long. 00245 union { 00246 UnicodeString* fString; 00247 double fDouble; 00248 int32_t fLong; 00249 UDate fDate; 00250 struct 00251 { 00252 Formattable* fArray; 00253 int32_t fCount; 00254 } fArrayAndCount; 00255 } fValue; 00256 00257 Type fType; 00258 }; 00259 00260 inline Formattable* 00261 Formattable::createArrayCopy(const Formattable* array, int32_t count) 00262 { 00263 Formattable *result = new Formattable[count]; 00264 for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy! 00265 return result; 00266 } 00267 00268 inline const UnicodeString& Formattable::getString(void) const { 00269 return *fValue.fString; 00270 } 00271 00272 inline UnicodeString& Formattable::getString(void) { 00273 return *fValue.fString; 00274 } 00275 00276 U_NAMESPACE_END 00277 00278 #endif //_FMTABLE 00279 //eof 00280

Generated on Fri Aug 13 09:53:50 2004 for ICU 2.1 by doxygen 1.3.7