ICU 4.2.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-2006, 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"
25 #if !UCONFIG_NO_FORMATTING
26 
28 
47 class U_I18N_API Formattable : public UObject {
48 public:
58  enum ISDATE { kIsDate };
59 
64  Formattable(); // Type kLong, value 0
65 
72  Formattable(UDate d, ISDATE flag);
73 
79  Formattable(double d);
80 
87 
93  Formattable(int64_t ll);
94 
95 #if !UCONFIG_NO_CONVERSION
96 
102  Formattable(const char* strToCopy);
103 #endif
104 
110  Formattable(const UnicodeString& strToCopy);
111 
117  Formattable(UnicodeString* strToAdopt);
118 
125  Formattable(const Formattable* arrayToCopy, int32_t count);
126 
132  Formattable(UObject* objectToAdopt);
133 
138  Formattable(const Formattable&);
139 
145  Formattable& operator=(const Formattable &rhs);
146 
153  UBool operator==(const Formattable &other) const;
154 
161  UBool operator!=(const Formattable& other) const
162  { return !operator==(other); }
163 
168  virtual ~Formattable();
169 
181  Formattable *clone() const;
182 
189  enum Type {
196 
203 
210 
217 
224 
231 
237  kObject
238  };
239 
245  Type getType(void) const;
246 
253  UBool isNumeric() const;
254 
261  double getDouble(void) const { return fValue.fDouble; }
262 
275  double getDouble(UErrorCode& status) const;
276 
283  int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
284 
301  int32_t getLong(UErrorCode& status) const;
302 
309  int64_t getInt64(void) const { return fValue.fInt64; }
310 
326  int64_t getInt64(UErrorCode& status) const;
327 
334  UDate getDate() const { return fValue.fDate; }
335 
344  UDate getDate(UErrorCode& status) const;
345 
354  { result=*fValue.fString; return result; }
355 
365  UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
366 
374  inline const UnicodeString& getString(void) const;
375 
384  const UnicodeString& getString(UErrorCode& status) const;
385 
392  inline UnicodeString& getString(void);
393 
402  UnicodeString& getString(UErrorCode& status);
403 
411  const Formattable* getArray(int32_t& count) const
412  { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
413 
423  const Formattable* getArray(int32_t& count, UErrorCode& status) const;
424 
433  Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
434 
441  const UObject* getObject() const;
442 
449  void setDouble(double d);
450 
457  void setLong(int32_t l);
458 
465  void setInt64(int64_t ll);
466 
473  void setDate(UDate d);
474 
481  void setString(const UnicodeString& stringToCopy);
482 
490  void setArray(const Formattable* array, int32_t count);
491 
498  void adoptString(UnicodeString* stringToAdopt);
499 
505  void adoptArray(Formattable* array, int32_t count);
506 
514  void adoptObject(UObject* objectToAdopt);
515 
521  virtual UClassID getDynamicClassID() const;
522 
528  static UClassID U_EXPORT2 getStaticClassID();
529 
536  inline int32_t getLong(UErrorCode* status) const;
537 
538 private:
543  void dispose(void);
544 
545  UnicodeString* getBogus() const;
546 
547  union {
548  UObject* fObject;
549  UnicodeString* fString;
550  double fDouble;
551  int64_t fInt64;
552  UDate fDate;
553  struct {
554  Formattable* fArray;
555  int32_t fCount;
556  } fArrayAndCount;
557  } fValue;
558 
559  Type fType;
560  UnicodeString fBogus; // Bogus string when it's needed.
561 };
562 
563 inline UDate Formattable::getDate(UErrorCode& status) const {
564  if (fType != kDate) {
565  if (U_SUCCESS(status)) {
566  status = U_INVALID_FORMAT_ERROR;
567  }
568  return 0;
569  }
570  return fValue.fDate;
571 }
572 
573 inline const UnicodeString& Formattable::getString(void) const {
574  return *fValue.fString;
575 }
576 
578  return *fValue.fString;
579 }
580 
581 inline int32_t Formattable::getLong(UErrorCode* status) const {
582  return getLong(*status);
583 }
584 
586 
587 #endif /* #if !UCONFIG_NO_FORMATTING */
588 
589 #endif //_FMTABLE
590 //eof
591 
int32_t getLong(void) const
Gets the long value of this object.
Definition: fmtable.h:283
#define U_SUCCESS(x)
Does the error code indicate success?
Definition: utypes.h:811
Selector indicating a UnicodeString value.
Definition: fmtable.h:216
ISDATE
This enum is only used to let callers distinguish between the Formattable(UDate) constructor and the ...
Definition: fmtable.h:58
double UDate
Date and Time data type.
Definition: utypes.h:281
C++ API: Unicode String.
const UnicodeString & getString(void) const
Gets a const reference to the string value of this object.
Definition: fmtable.h:573
Selector indicating a UDate value.
Definition: fmtable.h:195
int64_t getInt64(void) const
Gets the int64 value of this object.
Definition: fmtable.h:309
UDate getDate() const
Gets the Date value of this object.
Definition: fmtable.h:334
Selector indicating an array of Formattables.
Definition: fmtable.h:223
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:475
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:183
Type
Selector for flavor of data type contained within a Formattable object.
Definition: fmtable.h:189
Data format is not what is expected.
Definition: utypes.h:624
Selector indicating a double value.
Definition: fmtable.h:202
double getDouble(void) const
Gets the double value of this object.
Definition: fmtable.h:261
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:187
#define U_EXPORT2
Definition: platform.h:338
Selector indicating a 64-bit integer value.
Definition: fmtable.h:230
UBool operator!=(const Formattable &other) const
Equality operator.
Definition: fmtable.h:161
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:212
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:47
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:339
Selector indicating a 32-bit integer value.
Definition: fmtable.h:209
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:593
signed long long int64_t
Define 64 bit limits.
Definition: pwin32.h:152
const Formattable * getArray(int32_t &count) const
Gets the array value and count of this object.
Definition: fmtable.h:411
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:433
UnicodeString & getString(UnicodeString &result) const
Gets the string value of this object.
Definition: fmtable.h:353
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
signed int int32_t
Define 64 bit limits.
Definition: pwin32.h:143
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208