00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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();
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,
00178 kDouble,
00180 kLong,
00182 kString,
00184 kArray,
00186 kInt64
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
00437
00438
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;
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];
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
00482
00483
#endif //_FMTABLE
00484
00485