00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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();
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,
00128 kDouble,
00129 kLong,
00130 kString,
00131 kArray
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
00243
00244
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];
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
00280