- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- Search for |

- File List
- Globals

# fmtable.h

Go to the documentation of this file.

    00001 /*
    00002 ********************************************************************************
    00003 *   Copyright (C) 1997-2006, 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"
    00025 #if !UCONFIG_NO_FORMATTING
    00026
    00027 U_NAMESPACE_BEGIN
    00028
    00047 class U_I18N_API Formattable : public UObject {
    00048 public:
    00058     enum ISDATE { kIsDate };
    00059
    00064     Formattable(); // Type kLong, value 0
    00065
    00072     Formattable(UDate d, ISDATE flag);
    00073
    00079     Formattable(double d);
    00080
    00086     Formattable(int32_t l);
    00087
    00093     Formattable(int64_t ll);
    00094
    00095 #if !UCONFIG_NO_CONVERSION
    00096
    00102     Formattable(const char* strToCopy);
    00103 #endif
    00104
    00110     Formattable(const UnicodeString& strToCopy);
    00111
    00117     Formattable(UnicodeString* strToAdopt);
    00118
    00125     Formattable(const Formattable* arrayToCopy, int32_t count);
    00126
    00132     Formattable(UObject* objectToAdopt);
    00133
    00138     Formattable(const Formattable&);
    00139
    00145     Formattable&    operator=(const Formattable &rhs);
    00146
    00153     UBool          operator==(const Formattable &other) const;
    00154
    00161     UBool          operator!=(const Formattable& other) const
    00162       { return !operator==(other); }
    00163
    00168     virtual         ~Formattable();
    00169
    00181     Formattable *clone() const;
    00182
    00189     enum Type {
    00195         kDate,
    00196
    00202         kDouble,
    00203
    00209         kLong,
    00210
    00216         kString,
    00217
    00223         kArray,
    00224
    00230         kInt64,
    00231
    00237         kObject
    00238    };
    00239
    00245     Type            getType(void) const;
    00246
    00253     UBool           isNumeric() const;
    00254
    00261     double          getDouble(void) const { return fValue.fDouble; }
    00262
    00275     double          getDouble(UErrorCode& status) const;
    00276
    00283     int32_t         getLong(void) const { return (int32_t)fValue.fInt64; }
    00284
    00301     int32_t         getLong(UErrorCode& status) const;
    00302
    00309     int64_t         getInt64(void) const { return fValue.fInt64; }
    00310
    00326     int64_t         getInt64(UErrorCode& status) const;
    00327
    00334     UDate           getDate() const { return fValue.fDate; }
    00335
    00344      UDate          getDate(UErrorCode& status) const;
    00345
    00353     UnicodeString&  getString(UnicodeString& result) const
    00354       { result=*fValue.fString; return result; }
    00355
    00365     UnicodeString&  getString(UnicodeString& result, UErrorCode& status) const;
    00366
    00374     inline const UnicodeString& getString(void) const;
    00375
    00384     const UnicodeString& getString(UErrorCode& status) const;
    00385
    00392     inline UnicodeString& getString(void);
    00393
    00402     UnicodeString& getString(UErrorCode& status);
    00403
    00411     const Formattable* getArray(int32_t& count) const
    00412       { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
    00413
    00423     const Formattable* getArray(int32_t& count, UErrorCode& status) const;
    00424
    00433     Formattable&    operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
    00434
    00441     const UObject*  getObject() const;
    00442
    00449     void            setDouble(double d);
    00450
    00457     void            setLong(int32_t l);
    00458
    00465     void            setInt64(int64_t ll);
    00466
    00473     void            setDate(UDate d);
    00474
    00481     void            setString(const UnicodeString& stringToCopy);
    00482
    00490     void            setArray(const Formattable* array, int32_t count);
    00491
    00498     void            adoptString(UnicodeString* stringToAdopt);
    00499
    00505     void            adoptArray(Formattable* array, int32_t count);
    00506
    00514     void            adoptObject(UObject* objectToAdopt);
    00515
    00521     virtual UClassID getDynamicClassID() const;
    00522
    00528     static UClassID U_EXPORT2 getStaticClassID();
    00529
    00536     inline int32_t getLong(UErrorCode* status) const;
    00537
    00538 private:
    00543     void            dispose(void);
    00544
    00545     UnicodeString* getBogus() const;
    00546
    00547     union {
    00548         UObject*        fObject;
    00549         UnicodeString*  fString;
    00550         double          fDouble;
    00551         int64_t         fInt64;
    00552         UDate           fDate;
    00553         struct {
    00554           Formattable*  fArray;
    00555           int32_t       fCount;
    00556         }               fArrayAndCount;
    00557     } fValue;
    00558
    00559     Type                fType;
    00560     UnicodeString       fBogus; // Bogus string when it's needed.
    00561 };
    00562
    00563 inline UDate Formattable::getDate(UErrorCode& status) const {
    00564     if (fType != kDate) {
    00565         if (U_SUCCESS(status)) {
    00566             status = U_INVALID_FORMAT_ERROR;
    00567         }
    00568         return 0;
    00569     }
    00570     return fValue.fDate;
    00571 }
    00572
    00573 inline const UnicodeString& Formattable::getString(void) const {
    00574     return *fValue.fString;
    00575 }
    00576
    00577 inline UnicodeString& Formattable::getString(void) {
    00578     return *fValue.fString;
    00579 }
    00580
    00581 inline int32_t Formattable::getLong(UErrorCode* status) const {
    00582     return getLong(*status);
    00583 }
    00584
    00585 U_NAMESPACE_END
    00586
    00587 #endif /* #if !UCONFIG_NO_FORMATTING */
    00588
    00589 #endif //_FMTABLE
    00590 //eof
    00591