ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

fmtable.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************************
5 * Copyright (C) 1997-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
8 *
9 * File FMTABLE.H
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 02/29/97 aliu Creation.
15 ********************************************************************************
16 */
17 #ifndef FMTABLE_H
18 #define FMTABLE_H
19
20 #include "unicode/utypes.h"
21
27 #if !UCONFIG_NO_FORMATTING
28
29 #include "unicode/unistr.h"
30 #include "unicode/stringpiece.h"
31 #include "unicode/uformattable.h"
32
33 U_NAMESPACE_BEGIN
34
35 class CharString;
36 class DigitList;
37
42 #if U_PLATFORM == U_PF_OS400
43 #define UNUM_INTERNAL_STACKARRAY_SIZE 144
44 #else
45 #define UNUM_INTERNAL_STACKARRAY_SIZE 128
46 #endif
47
68 class U_I18N_API Formattable : public UObject {
69 public:
79 enum ISDATE { kIsDate };
80
85 Formattable(); // Type kLong, value 0
86
93 Formattable(UDate d, ISDATE flag);
94
100 Formattable(double d);
101
107 Formattable(int32_t l);
108
114 Formattable(int64_t ll);
115
116 #if !UCONFIG_NO_CONVERSION
117
123 Formattable(const char* strToCopy);
124 #endif
125
139 Formattable(StringPiece number, UErrorCode &status);
140
146 Formattable(const UnicodeString& strToCopy);
147
153 Formattable(UnicodeString* strToAdopt);
154
161 Formattable(const Formattable* arrayToCopy, int32_t count);
162
168 Formattable(UObject* objectToAdopt);
169
174 Formattable(const Formattable&);
175
181 Formattable& operator=(const Formattable &rhs);
182
189 UBool operator==(const Formattable &other) const;
190
197 UBool operator!=(const Formattable& other) const
198 { return !operator==(other); }
199
204 virtual ~Formattable();
205
217 Formattable *clone() const;
218
225 enum Type {
231 kDate,
232
238 kDouble,
239
245 kLong,
246
252 kString,
253
259 kArray,
260
266 kInt64,
267
273 kObject
274 };
275
281 Type getType(void) const;
282
289 UBool isNumeric() const;
290
297 double getDouble(void) const { return fValue.fDouble; }
298
311 double getDouble(UErrorCode& status) const;
312
319 int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
320
337 int32_t getLong(UErrorCode& status) const;
338
345 int64_t getInt64(void) const { return fValue.fInt64; }
346
362 int64_t getInt64(UErrorCode& status) const;
363
370 UDate getDate() const { return fValue.fDate; }
371
380 UDate getDate(UErrorCode& status) const;
381
389 UnicodeString& getString(UnicodeString& result) const
390 { result=*fValue.fString; return result; }
391
401 UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
402
410 inline const UnicodeString& getString(void) const;
411
420 const UnicodeString& getString(UErrorCode& status) const;
421
428 inline UnicodeString& getString(void);
429
438 UnicodeString& getString(UErrorCode& status);
439
447 const Formattable* getArray(int32_t& count) const
448 { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
449
459 const Formattable* getArray(int32_t& count, UErrorCode& status) const;
460
469 Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
470
477 const UObject* getObject() const;
478
497 StringPiece getDecimalNumber(UErrorCode &status);
498
505 void setDouble(double d);
506
513 void setLong(int32_t l);
514
521 void setInt64(int64_t ll);
522
529 void setDate(UDate d);
530
537 void setString(const UnicodeString& stringToCopy);
538
546 void setArray(const Formattable* array, int32_t count);
547
554 void adoptString(UnicodeString* stringToAdopt);
555
561 void adoptArray(Formattable* array, int32_t count);
562
570 void adoptObject(UObject* objectToAdopt);
571
586 void setDecimalNumber(StringPiece numberString,
587 UErrorCode &status);
588
594 virtual UClassID getDynamicClassID() const;
595
601 static UClassID U_EXPORT2 getStaticClassID();
602
610 static inline Formattable *fromUFormattable(UFormattable *fmt);
611
619 static inline const Formattable *fromUFormattable(const UFormattable *fmt);
620
627 inline UFormattable *toUFormattable();
628
635 inline const UFormattable *toUFormattable() const;
636
637 #ifndef U_HIDE_DEPRECATED_API
638
644 inline int32_t getLong(UErrorCode* status) const;
645 #endif /* U_HIDE_DEPRECATED_API */
646
647 #ifndef U_HIDE_INTERNAL_API
648
656 DigitList *getDigitList() const { return fDecimalNum;}
657
661 DigitList *getInternalDigitList();
662
669 void adoptDigitList(DigitList *dl);
670
677 CharString *internalGetCharString(UErrorCode &status);
678
679 #endif /* U_HIDE_INTERNAL_API */
680
681 private:
686 void dispose(void);
687
691 void init();
692
693 UnicodeString* getBogus() const;
694
695 union {
696 UObject* fObject;
697 UnicodeString* fString;
698 double fDouble;
699 int64_t fInt64;
700 UDate fDate;
701 struct {
702 Formattable* fArray;
703 int32_t fCount;
704 } fArrayAndCount;
705 } fValue;
706
707 CharString *fDecimalStr;
708
709 DigitList *fDecimalNum;
710
711 char fStackData[UNUM_INTERNAL_STACKARRAY_SIZE]; // must be big enough for DigitList
712
713 Type fType;
714 UnicodeString fBogus; // Bogus string when it's needed.
715 };
716
717 inline UDate Formattable::getDate(UErrorCode& status) const {
718 if (fType != kDate) {
719 if (U_SUCCESS(status)) {
720 status = U_INVALID_FORMAT_ERROR;
721 }
722 return 0;
723 }
724 return fValue.fDate;
725 }
726
727 inline const UnicodeString& Formattable::getString(void) const {
728 return *fValue.fString;
729 }
730
731 inline UnicodeString& Formattable::getString(void) {
732 return *fValue.fString;
733 }
734
735 #ifndef U_HIDE_DEPRECATED_API
736 inline int32_t Formattable::getLong(UErrorCode* status) const {
737 return getLong(*status);
738 }
739 #endif /* U_HIDE_DEPRECATED_API */
740
741 inline UFormattable* Formattable::toUFormattable() {
742 return reinterpret_cast<UFormattable*>(this);
743 }
744
745 inline const UFormattable* Formattable::toUFormattable() const {
746 return reinterpret_cast<const UFormattable*>(this);
747 }
748
749 inline Formattable* Formattable::fromUFormattable(UFormattable *fmt) {
750 return reinterpret_cast<Formattable *>(fmt);
751 }
752
753 inline const Formattable* Formattable::fromUFormattable(const UFormattable *fmt) {
754 return reinterpret_cast<const Formattable *>(fmt);
755 }
756
757 U_NAMESPACE_END
758
759 #endif /* #if !UCONFIG_NO_FORMATTING */
760
761 #endif //_FMTABLE
762 //eof
icu::Formattable::getArray
const Formattable * getArray(int32_t &count) const
Gets the array value and count of this object.
Definition: fmtable.h:447
uformattable.h
C API: UFormattable is a thin wrapper for primitive types used for formatting and parsing...
icu::Formattable::getString
const UnicodeString & getString(void) const
Gets a const reference to the string value of this object.
Definition: fmtable.h:727
U_SUCCESS
#define U_SUCCESS(x)
Does the error code indicate success?
Definition: utypes.h:683
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
unistr.h
C++ API: Unicode String.
icu::Formattable::getDouble
double getDouble(void) const
Gets the double value of this object.
Definition: fmtable.h:297
icu::Formattable::Type
Type
Selector for flavor of data type contained within a Formattable object.
Definition: fmtable.h:225
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
icu::Formattable::getDate
UDate getDate() const
Gets the Date value of this object.
Definition: fmtable.h:370
icu::Formattable::toUFormattable
UFormattable * toUFormattable()
Convert this object pointer to a UFormattable.
Definition: fmtable.h:741
UNUM_INTERNAL_STACKARRAY_SIZE
#define UNUM_INTERNAL_STACKARRAY_SIZE
Definition: fmtable.h:43
icu::Formattable::kArray
Selector indicating an array of Formattables.
Definition: fmtable.h:259
icu::Formattable::fromUFormattable
static Formattable * fromUFormattable(UFormattable *fmt)
Convert the UFormattable to a Formattable.
Definition: fmtable.h:749
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::Formattable::kDouble
Selector indicating a double value.
Definition: fmtable.h:238
icu::Formattable::getLong
int32_t getLong(void) const
Gets the long value of this object.
Definition: fmtable.h:319
icu::Formattable::operator[]
Formattable & operator[](int32_t index)
Accesses the specified element in the array value of this Formattable object.
Definition: fmtable.h:469
icu::Formattable::getInt64
int64_t getInt64(void) const
Gets the int64 value of this object.
Definition: fmtable.h:345
U_INVALID_FORMAT_ERROR
Data format is not what is expected.
Definition: utypes.h:434
icu::Formattable::getDigitList
DigitList * getDigitList() const
Internal function, do not use.
Definition: fmtable.h:656
icu::Formattable::ISDATE
ISDATE
This enum is only used to let callers distinguish between the Formattable(UDate) constructor and the ...
Definition: fmtable.h:79
icu::Formattable::getString
UnicodeString & getString(UnicodeString &result) const
Gets the string value of this object.
Definition: fmtable.h:389
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
icu::Formattable::kString
Selector indicating a UnicodeString value.
Definition: fmtable.h:252
icu::Formattable::kDate
Selector indicating a UDate value.
Definition: fmtable.h:231
icu::Formattable::operator!=
UBool operator!=(const Formattable &other) const
Equality operator.
Definition: fmtable.h:197
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
icu::Formattable::kLong
Selector indicating a 32-bit integer value.
Definition: fmtable.h:245
UFormattable
void * UFormattable
Opaque type representing various types of data which may be used for formatting and parsing operation...
Definition: uformattable.h:70
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:54
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
icu::Formattable::kInt64
Selector indicating a 64-bit integer value.
Definition: fmtable.h:266