Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

fmtable.h

Go to the documentation of this file.
00001 /*
00002 ********************************************************************************
00003 *   Copyright (C) 1997-2003, 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 #if !UCONFIG_NO_FORMATTING
00020 
00021 #include "unicode/unistr.h"
00022 #include "unicode/utypes.h"
00023 
00024 U_NAMESPACE_BEGIN
00025 
00044 class U_I18N_API Formattable : public UObject {
00045 public:
00055     enum ISDATE { kIsDate };
00056 
00061     Formattable(); // Type kLong, value 0
00062 
00069     Formattable(UDate d, ISDATE flag);
00070 
00076     Formattable(double d);
00077 
00083     Formattable(int32_t l);
00084 
00090     Formattable(int64_t ll);
00091 
00098     Formattable(const char* strToCopy);
00099 
00105     Formattable(const UnicodeString& strToCopy);
00106 
00112     Formattable(UnicodeString* strToAdopt);
00113 
00120     Formattable(const Formattable* arrayToCopy, int32_t count);
00121 
00126     Formattable(const Formattable&);
00127 
00133     Formattable&    operator=(const Formattable &rhs);
00134 
00141     UBool          operator==(const Formattable &other) const;
00142     
00149     UBool          operator!=(const Formattable& other) const
00150       { return !operator==(other); }
00151 
00156     virtual         ~Formattable();
00157 
00169     Formattable *clone() const;
00170 
00175     enum Type {
00177         kDate,      // Date
00179         kDouble,    // double
00181         kLong,      // long
00183         kString,    // UnicodeString
00185         kArray,     // Formattable[]
00187                 kInt64      // int64
00188    };
00189 
00195     Type            getType(void) const;
00196     
00202     double          getDouble(void) const { return fValue.fDouble; }
00203 
00213     double          getDouble(UErrorCode* status) const;
00214 
00220     int32_t         getLong(void) const { return (int32_t)fValue.fInt64; }
00221 
00233     int32_t         getLong(UErrorCode* status) const;
00234 
00240     int64_t         getInt64(void) const { return fValue.fInt64; }
00241 
00253     int64_t         getInt64(UErrorCode* status) const;
00254 
00260     UDate           getDate() const { return fValue.fDate; }
00261 
00269      UDate          getDate(UErrorCode* status) const;
00270 
00277     UnicodeString&  getString(UnicodeString& result) const
00278       { result=*fValue.fString; return result; }
00279 
00288     UnicodeString&  getString(UnicodeString& result, UErrorCode* status) const;
00289 
00295     inline const UnicodeString& getString(void) const;
00296 
00304     const UnicodeString& getString(UErrorCode* status) const;
00305 
00311     inline UnicodeString& getString(void);
00312 
00320     UnicodeString& getString(UErrorCode* status);
00321 
00328     const Formattable* getArray(int32_t& count) const
00329       { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00330 
00339     const Formattable* getArray(int32_t& count, UErrorCode* status) const;
00340 
00347     Formattable&    operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00348 
00354     void            setDouble(double d);
00355 
00361     void            setLong(int32_t l);
00362 
00368     void            setInt64(int64_t ll);
00369 
00375     void            setDate(UDate d);
00376 
00382     void            setString(const UnicodeString& stringToCopy);
00383 
00390     void            setArray(const Formattable* array, int32_t count);
00391 
00397     void            adoptString(UnicodeString* stringToAdopt);
00398 
00403     void            adoptArray(Formattable* array, int32_t count);
00404         
00410     virtual UClassID getDynamicClassID() const;
00411 
00417     static UClassID getStaticClassID();
00418 
00419 private:
00424     void            dispose(void);
00425 
00433     static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00434 
00435     static UnicodeString* gBogus;
00436     static UnicodeString* getBogus();
00437 
00438     // Note: For now, we do not handle unsigned long and unsigned
00439     // double types.  Smaller unsigned types, such as unsigned
00440     // short, can fit within a long.
00441     union {
00442         UnicodeString*  fString;
00443         double          fDouble;
00444         int64_t         fInt64;
00445         UDate           fDate;
00446         struct
00447         {
00448           Formattable*  fArray;
00449           int32_t       fCount;
00450         }               fArrayAndCount;
00451     }                   fValue;
00452 
00453     Type                fType;
00454 };
00455 
00456 inline Formattable*
00457 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00458 {
00459     Formattable *result = new Formattable[count];
00460     for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy!
00461     return result;
00462 }
00463 
00464 inline UDate Formattable::getDate(UErrorCode* status) const {
00465     if (status && U_SUCCESS(*status) && fType != kDate) {
00466       *status = U_INVALID_FORMAT_ERROR;
00467       return 0;
00468     }
00469     return fValue.fDate;
00470 }
00471 
00472 inline const UnicodeString& Formattable::getString(void) const {
00473     return *fValue.fString;
00474 }
00475 
00476 inline UnicodeString& Formattable::getString(void) {
00477     return *fValue.fString;
00478 }
00479 
00480 U_NAMESPACE_END
00481 
00482 #endif /* #if !UCONFIG_NO_FORMATTING */
00483 
00484 #endif //_FMTABLE
00485 //eof
00486      

Generated on Mon Nov 24 14:35:31 2003 for ICU 2.8 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001