ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fmtable.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
6 *
7 * File FMTABLE.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 02/29/97 aliu Creation.
13 ********************************************************************************
14 */
15 #ifndef FMTABLE_H
16 #define FMTABLE_H
17 
18 #include "unicode/utypes.h"
19 #include "unicode/unistr.h"
20 #include "unicode/stringpiece.h"
21 
27 #if !UCONFIG_NO_FORMATTING
28 
30 
31 class CharString;
32 class DigitList;
33 
52 class U_I18N_API Formattable : public UObject {
53 public:
63  enum ISDATE { kIsDate };
64 
69  Formattable(); // Type kLong, value 0
70 
77  Formattable(UDate d, ISDATE flag);
78 
84  Formattable(double d);
85 
91  Formattable(int32_t l);
92 
98  Formattable(int64_t ll);
99 
100 #if !UCONFIG_NO_CONVERSION
101 
107  Formattable(const char* strToCopy);
108 #endif
109 
123  Formattable(const StringPiece &number, UErrorCode &status);
124 
130  Formattable(const UnicodeString& strToCopy);
131 
137  Formattable(UnicodeString* strToAdopt);
138 
145  Formattable(const Formattable* arrayToCopy, int32_t count);
146 
152  Formattable(UObject* objectToAdopt);
153 
158  Formattable(const Formattable&);
159 
165  Formattable& operator=(const Formattable &rhs);
166 
173  UBool operator==(const Formattable &other) const;
174 
181  UBool operator!=(const Formattable& other) const
182  { return !operator==(other); }
183 
188  virtual ~Formattable();
189 
201  Formattable *clone() const;
202 
209  enum Type {
216 
223 
230 
237 
244 
251 
257  kObject
258  };
259 
265  Type getType(void) const;
266 
273  UBool isNumeric() const;
274 
281  double getDouble(void) const { return fValue.fDouble; }
282 
295  double getDouble(UErrorCode& status) const;
296 
303  int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
304 
321  int32_t getLong(UErrorCode& status) const;
322 
329  int64_t getInt64(void) const { return fValue.fInt64; }
330 
346  int64_t getInt64(UErrorCode& status) const;
347 
354  UDate getDate() const { return fValue.fDate; }
355 
364  UDate getDate(UErrorCode& status) const;
365 
373  UnicodeString& getString(UnicodeString& result) const
374  { result=*fValue.fString; return result; }
375 
385  UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
386 
394  inline const UnicodeString& getString(void) const;
395 
404  const UnicodeString& getString(UErrorCode& status) const;
405 
412  inline UnicodeString& getString(void);
413 
422  UnicodeString& getString(UErrorCode& status);
423 
431  const Formattable* getArray(int32_t& count) const
432  { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
433 
443  const Formattable* getArray(int32_t& count, UErrorCode& status) const;
444 
453  Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
454 
461  const UObject* getObject() const;
462 
481  StringPiece getDecimalNumber(UErrorCode &status);
482 
489  void setDouble(double d);
490 
497  void setLong(int32_t l);
498 
505  void setInt64(int64_t ll);
506 
513  void setDate(UDate d);
514 
521  void setString(const UnicodeString& stringToCopy);
522 
530  void setArray(const Formattable* array, int32_t count);
531 
538  void adoptString(UnicodeString* stringToAdopt);
539 
545  void adoptArray(Formattable* array, int32_t count);
546 
554  void adoptObject(UObject* objectToAdopt);
555 
570  void setDecimalNumber(const StringPiece &numberString,
571  UErrorCode &status);
572 
578  virtual UClassID getDynamicClassID() const;
579 
585  static UClassID U_EXPORT2 getStaticClassID();
586 
593  inline int32_t getLong(UErrorCode* status) const;
594 
603  DigitList *getDigitList() const { return fDecimalNum;}
604 
611  void adoptDigitList(DigitList *dl);
612 
613 private:
618  void dispose(void);
619 
623  void init();
624 
625  UnicodeString* getBogus() const;
626 
627  union {
628  UObject* fObject;
629  UnicodeString* fString;
630  double fDouble;
631  int64_t fInt64;
632  UDate fDate;
633  struct {
634  Formattable* fArray;
635  int32_t fCount;
636  } fArrayAndCount;
637  } fValue;
638 
639  CharString *fDecimalStr;
640  DigitList *fDecimalNum;
641 
642  Type fType;
643  UnicodeString fBogus; // Bogus string when it's needed.
644 };
645 
646 inline UDate Formattable::getDate(UErrorCode& status) const {
647  if (fType != kDate) {
648  if (U_SUCCESS(status)) {
649  status = U_INVALID_FORMAT_ERROR;
650  }
651  return 0;
652  }
653  return fValue.fDate;
654 }
655 
656 inline const UnicodeString& Formattable::getString(void) const {
657  return *fValue.fString;
658 }
659 
661  return *fValue.fString;
662 }
663 
664 inline int32_t Formattable::getLong(UErrorCode* status) const {
665  return getLong(*status);
666 }
667 
669 
670 #endif /* #if !UCONFIG_NO_FORMATTING */
671 
672 #endif //_FMTABLE
673 //eof