ICU 50.2 50.2
fmtable.h
Go to the documentation of this file.
1/*
2********************************************************************************
3* Copyright (C) 1997-2012, 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
26
27#if !UCONFIG_NO_FORMATTING
28
30
31class CharString;
32class DigitList;
33
38#if U_PLATFORM == U_PF_OS400
39#define UNUM_INTERNAL_STACKARRAY_SIZE 144
40#else
41#define UNUM_INTERNAL_STACKARRAY_SIZE 128
42#endif
43
63public:
73 enum ISDATE { kIsDate };
74
79 Formattable(); // Type kLong, value 0
80
88
94 Formattable(double d);
95
101 Formattable(int32_t l);
102
108 Formattable(int64_t ll);
109
110#if !UCONFIG_NO_CONVERSION
117 Formattable(const char* strToCopy);
118#endif
119
133 Formattable(const StringPiece &number, UErrorCode &status);
134
140 Formattable(const UnicodeString& strToCopy);
141
148
155 Formattable(const Formattable* arrayToCopy, int32_t count);
156
162 Formattable(UObject* objectToAdopt);
163
169
176
183 UBool operator==(const Formattable &other) const;
184
191 UBool operator!=(const Formattable& other) const
192 { return !operator==(other); }
193
198 virtual ~Formattable();
199
212
219 enum Type {
226
233
240
247
254
261
268 };
269
275 Type getType(void) const;
276
284
291 double getDouble(void) const { return fValue.fDouble; }
292
305 double getDouble(UErrorCode& status) const;
306
313 int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
314
331 int32_t getLong(UErrorCode& status) const;
332
339 int64_t getInt64(void) const { return fValue.fInt64; }
340
356 int64_t getInt64(UErrorCode& status) const;
357
364 UDate getDate() const { return fValue.fDate; }
365
374 UDate getDate(UErrorCode& status) const;
375
384 { result=*fValue.fString; return result; }
385
396
404 inline const UnicodeString& getString(void) const;
405
414 const UnicodeString& getString(UErrorCode& status) const;
415
422 inline UnicodeString& getString(void);
423
433
441 const Formattable* getArray(int32_t& count) const
442 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
443
453 const Formattable* getArray(int32_t& count, UErrorCode& status) const;
454
463 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
464
471 const UObject* getObject() const;
472
492
499 void setDouble(double d);
500
507 void setLong(int32_t l);
508
515 void setInt64(int64_t ll);
516
523 void setDate(UDate d);
524
531 void setString(const UnicodeString& stringToCopy);
532
540 void setArray(const Formattable* array, int32_t count);
541
548 void adoptString(UnicodeString* stringToAdopt);
549
555 void adoptArray(Formattable* array, int32_t count);
556
564 void adoptObject(UObject* objectToAdopt);
565
580 void setDecimalNumber(const StringPiece &numberString,
581 UErrorCode &status);
582
589
595 static UClassID U_EXPORT2 getStaticClassID();
596
597#ifndef U_HIDE_DEPRECATED_API
604 inline int32_t getLong(UErrorCode* status) const;
605#endif /* U_HIDE_DEPRECATED_API */
606
607#ifndef U_HIDE_INTERNAL_API
616 DigitList *getDigitList() const { return fDecimalNum;}
617
622
629 void adoptDigitList(DigitList *dl);
630#endif /* U_HIDE_INTERNAL_API */
631
632private:
637 void dispose(void);
638
642 void init();
643
644 UnicodeString* getBogus() const;
645
646 union {
647 UObject* fObject;
648 UnicodeString* fString;
649 double fDouble;
650 int64_t fInt64;
651 UDate fDate;
652 struct {
653 Formattable* fArray;
654 int32_t fCount;
655 } fArrayAndCount;
656 } fValue;
657
658 CharString *fDecimalStr;
659
660 DigitList *fDecimalNum;
661
662 char fStackData[UNUM_INTERNAL_STACKARRAY_SIZE]; // must be big enough for DigitList
663
664 Type fType;
665 UnicodeString fBogus; // Bogus string when it's needed.
666};
667
668inline UDate Formattable::getDate(UErrorCode& status) const {
669 if (fType != kDate) {
670 if (U_SUCCESS(status)) {
671 status = U_INVALID_FORMAT_ERROR;
672 }
673 return 0;
674 }
675 return fValue.fDate;
676}
677
678inline const UnicodeString& Formattable::getString(void) const {
679 return *fValue.fString;
680}
681
683 return *fValue.fString;
684}
685
686#ifndef U_HIDE_DEPRECATED_API
687inline int32_t Formattable::getLong(UErrorCode* status) const {
688 return getLong(*status);
689}
690#endif
691
692
694
695#endif /* #if !UCONFIG_NO_FORMATTING */
696
697#endif //_FMTABLE
698//eof
ISDATE
This enum is only used to let callers distinguish between the Formattable(UDate) constructor and the ...
Definition fmtable.h:73
Formattable(const char *strToCopy)
Creates a Formattable object with a char string pointer.
Formattable(int64_t ll)
Creates a Formattable object with an int64_t number.
UBool operator==(const Formattable &other) const
Equality comparison.
void adoptString(UnicodeString *stringToAdopt)
Sets and adopts the string value and count of this object and changes the type to kArray.
Formattable(UnicodeString *strToAdopt)
Creates a Formattable object with a UnicodeString object to adopt from.
UDate getDate() const
Gets the Date value of this object.
Definition fmtable.h:364
const Formattable * getArray(int32_t &count, UErrorCode &status) const
Gets the array value and count of this object.
Formattable()
Default constructor.
Formattable * clone() const
Clone this object.
Formattable(UObject *objectToAdopt)
Creates a Formattable object that adopts the given UObject.
int64_t getInt64(UErrorCode &status) const
Gets the int64 value of this object.
Formattable(const StringPiece &number, UErrorCode &status)
Creates a Formattable object of an appropriate numeric type from a a decimal number in string form.
Formattable & operator[](int32_t index)
Accesses the specified element in the array value of this Formattable object.
Definition fmtable.h:463
int32_t getLong(void) const
Gets the long value of this object.
Definition fmtable.h:313
void setArray(const Formattable *array, int32_t count)
Sets the array value and count of this object and changes the type to kArray.
Formattable(const UnicodeString &strToCopy)
Creates a Formattable object with a UnicodeString object to copy from.
UnicodeString & getString(UErrorCode &status)
Gets a reference to the string value of this object.
const UObject * getObject() const
Returns a pointer to the UObject contained within this formattable, or NULL if this object does not c...
Formattable(const Formattable &)
Copy constructor.
void adoptArray(Formattable *array, int32_t count)
Sets and adopts the array value and count of this object and changes the type to kArray.
StringPiece getDecimalNumber(UErrorCode &status)
Returns a numeric string representation of the number contained within this formattable,...
Formattable(double d)
Creates a Formattable object with a double number.
void setString(const UnicodeString &stringToCopy)
Sets the string value of this object and changes the type to kString.
UnicodeString & getString(UnicodeString &result) const
Gets the string value of this object.
Definition fmtable.h:383
Type getType(void) const
Gets the data type of this Formattable object.
Type
Selector for flavor of data type contained within a Formattable object.
Definition fmtable.h:219
@ kString
Selector indicating a UnicodeString value.
Definition fmtable.h:246
@ kDouble
Selector indicating a double value.
Definition fmtable.h:232
@ kDate
Selector indicating a UDate value.
Definition fmtable.h:225
@ kArray
Selector indicating an array of Formattables.
Definition fmtable.h:253
@ kObject
Selector indicating a UObject value.
Definition fmtable.h:267
@ kLong
Selector indicating a 32-bit integer value.
Definition fmtable.h:239
@ kInt64
Selector indicating a 64-bit integer value.
Definition fmtable.h:260
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
Formattable(UDate d, ISDATE flag)
Creates a Formattable object with a UDate instance.
void setDecimalNumber(const StringPiece &numberString, UErrorCode &status)
Sets the the numeric value from a decimal number string, and changes the type to to a numeric type ap...
Formattable & operator=(const Formattable &rhs)
Assignment operator.
int32_t getLong(UErrorCode &status) const
Gets the long value of this object.
void setInt64(int64_t ll)
Sets the int64 value of this object and changes the type to kInt64.
Formattable(const Formattable *arrayToCopy, int32_t count)
Creates a Formattable object with an array of Formattable objects.
const Formattable * getArray(int32_t &count) const
Gets the array value and count of this object.
Definition fmtable.h:441
DigitList * getInternalDigitList()
void setDate(UDate d)
Sets the Date value of this object and changes the type to kDate.
const UnicodeString & getString(UErrorCode &status) const
Gets a const reference to the string value of this object.
UnicodeString & getString(UnicodeString &result, UErrorCode &status) const
Gets the string value of this object.
void adoptObject(UObject *objectToAdopt)
Sets and adopts the UObject value of this object and changes the type to kObject.
Formattable(int32_t l)
Creates a Formattable object with a long number.
UBool operator!=(const Formattable &other) const
Equality operator.
Definition fmtable.h:191
void adoptDigitList(DigitList *dl)
Adopt, and set value from, a DigitList Internal Function, do not use.
void setLong(int32_t l)
Sets the long value of this object and changes the type to kLong.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
DigitList * getDigitList() const
Internal function, do not use.
Definition fmtable.h:616
int64_t getInt64(void) const
Gets the int64 value of this object.
Definition fmtable.h:339
void setDouble(double d)
Sets the double value of this object and changes the type to kDouble.
UBool isNumeric() const
Returns TRUE if the data type of this Formattable object is kDouble, kLong, kInt64 or kDecimalNumber.
double getDouble(void) const
Gets the double value of this object.
Definition fmtable.h:291
double getDouble(UErrorCode &status) const
Gets the double value of this object.
const UnicodeString & getString(void) const
Gets a const reference to the string value of this object.
Definition fmtable.h:678
virtual ~Formattable()
Destructor.
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:52
UObject is the common ICU "boilerplate" class.
Definition uobject.h:229
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
#define UNUM_INTERNAL_STACKARRAY_SIZE
Definition fmtable.h:39
C++ API: StringPiece: Read-only byte string wrapper class.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
@ U_INVALID_FORMAT_ERROR
Data format is not what is expected.
Definition utypes.h:509
#define U_SUCCESS(x)
Does the error code indicate success?
Definition utypes.h:705
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
double UDate
Date and Time data type.
Definition utypes.h:201
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129