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 
00021 #if !UCONFIG_NO_FORMATTING
00022 
00023 #include "unicode/uobject.h"
00024 #include "unicode/unistr.h"
00025 
00026 U_NAMESPACE_BEGIN
00027 
00044 class U_I18N_API Formattable : public UObject {
00045 public:
00055                     enum ISDATE { kIsDate };
00056 
00061                     Formattable(); // Type kLong, value 0
00068                     Formattable(UDate d, ISDATE);
00074                     Formattable(double d);
00080                     Formattable(int32_t l);
00087                     Formattable(const char* strToCopy);
00093                     Formattable(const UnicodeString& stringToCopy);
00099                     Formattable(UnicodeString* stringToAdopt);
00106                     Formattable(const Formattable* arrayToCopy, int32_t count);
00107 
00112                     Formattable(const Formattable&);
00117     Formattable&    operator=(const Formattable&);
00124     UBool          operator==(const Formattable&) const;
00125     
00132     UBool          operator!=(const Formattable& other) const
00133       { return !operator==(other); }
00134 
00139     virtual         ~Formattable();
00140 
00145     enum Type {
00146         kDate,      // Date
00147         kDouble,    // double
00148         kLong,      // long
00149         kString,    // UnicodeString
00150         kArray      // Formattable[]
00151     };
00152 
00158     Type            getType(void) const;
00159     
00165     double          getDouble(void) const { return fValue.fDouble; }
00171     int32_t            getLong(void) const { return fValue.fLong; }
00177     UDate            getDate(void) const { return fValue.fDate; }
00178 
00185     UnicodeString&  getString(UnicodeString& result) const
00186       { result=*fValue.fString; return result; }
00187 
00193     inline const UnicodeString& getString(void) const;
00194 
00200     inline UnicodeString& getString(void);
00201 
00208     const Formattable* getArray(int32_t& count) const
00209       { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00210 
00217     Formattable&    operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00218 
00224     void            setDouble(double d);
00230     void            setLong(int32_t l);
00236     void            setDate(UDate d);
00242     void            setString(const UnicodeString& stringToCopy);
00249     void            setArray(const Formattable* array, int32_t count);
00255     void            adoptString(UnicodeString* stringToAdopt);
00260     void            adoptArray(Formattable* array, int32_t count);
00261         
00267     virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
00268 
00274     static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
00275 
00276 private:
00281     void            dispose(void);
00282 
00290     static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00291 
00292     // Note: For now, we do not handle unsigned long and unsigned
00293     // double types.  Smaller unsigned types, such as unsigned
00294     // short, can fit within a long.
00295     union {
00296         UnicodeString*  fString;
00297         double          fDouble;
00298         int32_t            fLong;
00299         UDate            fDate;
00300         struct
00301         {
00302           Formattable*  fArray;
00303           int32_t          fCount;
00304         }               fArrayAndCount;
00305     }                   fValue;
00306 
00307     Type                fType;
00308 
00313     static const char fgClassID;
00314 };
00315 
00316 inline Formattable*
00317 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00318 {
00319     Formattable *result = new Formattable[count];
00320     for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy!
00321     return result;
00322 }
00323 
00324 inline const UnicodeString& Formattable::getString(void) const {
00325     return *fValue.fString;
00326 }
00327 
00328 inline UnicodeString& Formattable::getString(void) {
00329     return *fValue.fString;
00330 }
00331 
00332 U_NAMESPACE_END
00333 
00334 #endif /* #if !UCONFIG_NO_FORMATTING */
00335 
00336 #endif //_FMTABLE
00337 //eof
00338      

Generated on Wed Dec 18 16:49:34 2002 for ICU 2.4 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001