ICU 49.1.1  49.1.1
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 
587 #ifndef U_HIDE_DEPRECATED_API
588 
594  inline int32_t getLong(UErrorCode* status) const;
595 #endif /* U_HIDE_DEPRECATED_API */
596 
597 #ifndef U_HIDE_INTERNAL_API
598 
606  DigitList *getDigitList() const { return fDecimalNum;}
607 
614  void adoptDigitList(DigitList *dl);
615 #endif /* U_HIDE_INTERNAL_API */
616 
617 private:
622  void dispose(void);
623 
627  void init();
628 
629  UnicodeString* getBogus() const;
630 
631  union {
632  UObject* fObject;
633  UnicodeString* fString;
634  double fDouble;
635  int64_t fInt64;
636  UDate fDate;
637  struct {
638  Formattable* fArray;
639  int32_t fCount;
640  } fArrayAndCount;
641  } fValue;
642 
643  CharString *fDecimalStr;
644  DigitList *fDecimalNum;
645 
646  Type fType;
647  UnicodeString fBogus; // Bogus string when it's needed.
648 };
649 
650 inline UDate Formattable::getDate(UErrorCode& status) const {
651  if (fType != kDate) {
652  if (U_SUCCESS(status)) {
653  status = U_INVALID_FORMAT_ERROR;
654  }
655  return 0;
656  }
657  return fValue.fDate;
658 }
659 
660 inline const UnicodeString& Formattable::getString(void) const {
661  return *fValue.fString;
662 }
663 
665  return *fValue.fString;
666 }
667 
668 #ifndef U_HIDE_DEPRECATED_API
669 inline int32_t Formattable::getLong(UErrorCode* status) const {
670  return getLong(*status);
671 }
672 #endif
673 
674 
676 
677 #endif /* #if !UCONFIG_NO_FORMATTING */
678 
679 #endif //_FMTABLE
680 //eof