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 
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
int32_t getLong(void) const
Gets the long value of this object.
Definition: fmtable.h:303
#define U_SUCCESS(x)
Does the error code indicate success?
Definition: utypes.h:868
Selector indicating a UnicodeString value.
Definition: fmtable.h:236
ISDATE
This enum is only used to let callers distinguish between the Formattable(UDate) constructor and the ...
Definition: fmtable.h:63
double UDate
Date and Time data type.
Definition: utypes.h:314
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
C++ API: Unicode String.
const UnicodeString & getString(void) const
Gets a const reference to the string value of this object.
Definition: fmtable.h:656
Selector indicating a UDate value.
Definition: fmtable.h:215
int64_t getInt64(void) const
Gets the int64 value of this object.
Definition: fmtable.h:329
UDate getDate() const
Gets the Date value of this object.
Definition: fmtable.h:354
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
Selector indicating an array of Formattables.
Definition: fmtable.h:243
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:521
C++ API: StringPiece: Read-only byte string wrapper class.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
Type
Selector for flavor of data type contained within a Formattable object.
Definition: fmtable.h:209
Data format is not what is expected.
Definition: utypes.h:672
Selector indicating a double value.
Definition: fmtable.h:222
double getDouble(void) const
Gets the double value of this object.
Definition: fmtable.h:281
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:188
#define U_EXPORT2
Definition: platform.h:314
DigitList * getDigitList() const
Internal function, do not use.
Definition: fmtable.h:603
Selector indicating a 64-bit integer value.
Definition: fmtable.h:250
UBool operator!=(const Formattable &other) const
Equality operator.
Definition: fmtable.h:181
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:215
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:52
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:385
Selector indicating a 32-bit integer value.
Definition: fmtable.h:229
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:639
const Formattable * getArray(int32_t &count) const
Gets the array value and count of this object.
Definition: fmtable.h:431
Basic definitions for ICU, for both C and C++ APIs.
Formattable & operator[](int32_t index)
Accesses the specified element in the array value of this Formattable object.
Definition: fmtable.h:453
UnicodeString & getString(UnicodeString &result) const
Gets the string value of this object.
Definition: fmtable.h:373
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:228