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-1999, 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 #include "unicode/utypes.h"
00020 #include "unicode/uobject.h"
00021 #include "unicode/unistr.h"
00022 
00023 U_NAMESPACE_BEGIN
00024 
00041 class U_I18N_API Formattable : public UObject {
00042 public:
00051                     enum ISDATE { kIsDate };
00052 
00053                     Formattable(); // Type kLong, value 0
00060                     Formattable(UDate d, ISDATE);
00066                     Formattable(double d);
00072                     Formattable(int32_t l);
00079                     Formattable(const char* strToCopy);
00085                     Formattable(const UnicodeString& stringToCopy);
00091                     Formattable(UnicodeString* stringToAdopt);
00098                     Formattable(const Formattable* arrayToCopy, int32_t count);
00099 
00104                     Formattable(const Formattable&);
00109     Formattable&    operator=(const Formattable&);
00116     UBool          operator==(const Formattable&) const;
00117     
00124     UBool          operator!=(const Formattable& other) const
00125       { return !operator==(other); }
00126 
00131     virtual         ~Formattable();
00132 
00136     enum Type {
00137         kDate,      // Date
00138         kDouble,    // double
00139         kLong,      // long
00140         kString,    // UnicodeString
00141         kArray      // Formattable[]
00142     };
00143 
00149     Type            getType(void) const;
00150     
00156     double          getDouble(void) const { return fValue.fDouble; }
00162     int32_t            getLong(void) const { return fValue.fLong; }
00168     UDate            getDate(void) const { return fValue.fDate; }
00169 
00176     UnicodeString&  getString(UnicodeString& result) const
00177       { result=*fValue.fString; return result; }
00178 
00184     inline const UnicodeString& getString(void) const;
00185 
00191     inline UnicodeString& getString(void);
00192 
00199     const Formattable* getArray(int32_t& count) const
00200       { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00201 
00208     Formattable&    operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00209 
00215     void            setDouble(double d);
00221     void            setLong(int32_t l);
00227     void            setDate(UDate d);
00233     void            setString(const UnicodeString& stringToCopy);
00240     void            setArray(const Formattable* array, int32_t count);
00246     void            adoptString(UnicodeString* stringToAdopt);
00251     void            adoptArray(Formattable* array, int32_t count);
00252         
00258     virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
00259 
00265     static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
00266 
00267 private:
00272     void            dispose(void);
00273 
00281     static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00282 
00283     // Note: For now, we do not handle unsigned long and unsigned
00284     // double types.  Smaller unsigned types, such as unsigned
00285     // short, can fit within a long.
00286     union {
00287         UnicodeString*  fString;
00288         double          fDouble;
00289         int32_t            fLong;
00290         UDate            fDate;
00291         struct
00292         {
00293           Formattable*  fArray;
00294           int32_t          fCount;
00295         }               fArrayAndCount;
00296     }                   fValue;
00297 
00298     Type                fType;
00299 
00304     static const char fgClassID;
00305 };
00306 
00307 inline Formattable*
00308 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00309 {
00310     Formattable *result = new Formattable[count];
00311     for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy!
00312     return result;
00313 }
00314 
00315 inline const UnicodeString& Formattable::getString(void) const {
00316     return *fValue.fString;
00317 }
00318 
00319 inline UnicodeString& Formattable::getString(void) {
00320     return *fValue.fString;
00321 }
00322 
00323 U_NAMESPACE_END
00324 
00325 #endif //_FMTABLE
00326 //eof
00327      

Generated on Thu Aug 15 14:13:25 2002 for ICU 2.2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001