Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

fmtable.h

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 #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 flag);
00074     Formattable(double d);
00080     Formattable(int32_t l);
00087     Formattable(const char* strToCopy);
00093     Formattable(const UnicodeString& strToCopy);
00099     Formattable(UnicodeString* strToAdopt);
00106     Formattable(const Formattable* arrayToCopy, int32_t count);
00107 
00112     Formattable(const Formattable&);
00118     Formattable&    operator=(const Formattable &rhs);
00125     UBool          operator==(const Formattable &other) const;
00126     
00133     UBool          operator!=(const Formattable& other) const
00134       { return !operator==(other); }
00135 
00140     virtual         ~Formattable();
00141 
00146     enum Type {
00147         kDate,      // Date
00148         kDouble,    // double
00149         kLong,      // long
00150         kString,    // UnicodeString
00151         kArray      // Formattable[]
00152     };
00153 
00159     Type            getType(void) const;
00160     
00166     double          getDouble(void) const { return fValue.fDouble; }
00172     int32_t            getLong(void) const { return fValue.fLong; }
00178     UDate            getDate(void) const { return fValue.fDate; }
00179 
00186     UnicodeString&  getString(UnicodeString& result) const
00187       { result=*fValue.fString; return result; }
00188 
00194     inline const UnicodeString& getString(void) const;
00195 
00201     inline UnicodeString& getString(void);
00202 
00209     const Formattable* getArray(int32_t& count) const
00210       { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
00211 
00218     Formattable&    operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
00219 
00225     void            setDouble(double d);
00231     void            setLong(int32_t l);
00237     void            setDate(UDate d);
00243     void            setString(const UnicodeString& stringToCopy);
00250     void            setArray(const Formattable* array, int32_t count);
00256     void            adoptString(UnicodeString* stringToAdopt);
00261     void            adoptArray(Formattable* array, int32_t count);
00262         
00268     virtual inline UClassID getDynamicClassID() const;
00269 
00275     static inline UClassID getStaticClassID();
00276 
00277 private:
00282     void            dispose(void);
00283 
00291     static Formattable* createArrayCopy(const Formattable* array, int32_t count);
00292 
00293     // Note: For now, we do not handle unsigned long and unsigned
00294     // double types.  Smaller unsigned types, such as unsigned
00295     // short, can fit within a long.
00296     union {
00297         UnicodeString*  fString;
00298         double          fDouble;
00299         int32_t            fLong;
00300         UDate            fDate;
00301         struct
00302         {
00303           Formattable*  fArray;
00304           int32_t          fCount;
00305         }               fArrayAndCount;
00306     }                   fValue;
00307 
00308     Type                fType;
00309 
00314     static const char fgClassID;
00315 };
00316 
00317 inline UClassID Formattable::getStaticClassID()
00318 { return (UClassID)&fgClassID; }
00319         
00320 inline UClassID Formattable::getDynamicClassID() const
00321 { return Formattable::getStaticClassID(); }
00322 
00323 inline Formattable*
00324 Formattable::createArrayCopy(const Formattable* array, int32_t count)
00325 {
00326     Formattable *result = new Formattable[count];
00327     for (int32_t i=0; i<count; ++i) result[i] = array[i]; // Don't memcpy!
00328     return result;
00329 }
00330 
00331 inline const UnicodeString& Formattable::getString(void) const {
00332     return *fValue.fString;
00333 }
00334 
00335 inline UnicodeString& Formattable::getString(void) {
00336     return *fValue.fString;
00337 }
00338 
00339 U_NAMESPACE_END
00340 
00341 #endif /* #if !UCONFIG_NO_FORMATTING */
00342 
00343 #endif //_FMTABLE
00344 //eof
00345      

Generated on Wed Sep 3 17:47:08 2003 for ICU 2.6 by doxygen 1.3.2