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
00038 class U_I18N_API Formattable {
00039 public:
00048 enum ISDATE { kIsDate };
00049
00050 Formattable();
00057 Formattable(UDate d, ISDATE);
00063 Formattable(double d);
00069 Formattable(int32_t l);
00076 Formattable(const char* strToCopy);
00082 Formattable(const UnicodeString& stringToCopy);
00088 Formattable(UnicodeString* stringToAdopt);
00095 Formattable(const Formattable* arrayToCopy, int32_t count);
00096
00101 Formattable(const Formattable&);
00106 Formattable& operator=(const Formattable&);
00111 UBool operator==(const Formattable&) const;
00112 UBool operator!=(const Formattable& other) const
00113 { return !operator==(other); }
00114
00119 virtual ~Formattable();
00120
00124 enum Type {
00125 kDate,
00126 kDouble,
00127 kLong,
00128 kString,
00129 kArray
00130 };
00131
00136 Type getType(void) const;
00137
00142 double getDouble(void) const { return fValue.fDouble; }
00147 int32_t getLong(void) const { return fValue.fLong; }
00152 UDate getDate(void) const { return fValue.fDate; }
00153
00158 UnicodeString& getString(UnicodeString& result) const
00159 { result=*fValue.fString; return result; }
00160
00165 inline const UnicodeString& getString(void) const;
00166
00171 inline UnicodeString& getString(void);
00172
00177 const Formattable* getArray(int32_t& count) const
00178 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00179
00186 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00187
00192 void setDouble(double d);
00197 void setLong(int32_t l);
00202 void setDate(UDate d);
00207 void setString(const UnicodeString& stringToCopy);
00212 void setArray(const Formattable* array, int32_t count);
00217 void adoptString(UnicodeString* stringToAdopt);
00222 void adoptArray(Formattable* array, int32_t count);
00223
00224 private:
00229 void dispose(void);
00230
00238 static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00239
00240
00241
00242
00243 union {
00244 UnicodeString* fString;
00245 double fDouble;
00246 int32_t fLong;
00247 UDate fDate;
00248 struct
00249 {
00250 Formattable* fArray;
00251 int32_t fCount;
00252 } fArrayAndCount;
00253 } fValue;
00254
00255 Type fType;
00256 };
00257
00258 inline Formattable*
00259 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00260 {
00261 Formattable *result = new Formattable[count];
00262 for (int32_t i=0; i<count; ++i) result[i] = array[i];
00263 return result;
00264 }
00265
00266 inline const UnicodeString& Formattable::getString(void) const {
00267 return *fValue.fString;
00268 }
00269
00270 inline UnicodeString& Formattable::getString(void) {
00271 return *fValue.fString;
00272 }
00273
00274 #endif //_FMTABLE
00275
00276