fmtable.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*
  2. ********************************************************************************
  3. * Copyright (C) 1997-2014, 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. #include "unicode/utypes.h"
  18. /**
  19. * \file
  20. * \brief C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing
  21. */
  22. #if !UCONFIG_NO_FORMATTING
  23. #include "unicode/unistr.h"
  24. #include "unicode/stringpiece.h"
  25. #include "unicode/uformattable.h"
  26. U_NAMESPACE_BEGIN
  27. class CharString;
  28. class DigitList;
  29. /**
  30. * \def UNUM_INTERNAL_STACKARRAY_SIZE
  31. * @internal
  32. */
  33. #if U_PLATFORM == U_PF_OS400
  34. #define UNUM_INTERNAL_STACKARRAY_SIZE 144
  35. #else
  36. #define UNUM_INTERNAL_STACKARRAY_SIZE 128
  37. #endif
  38. /**
  39. * Formattable objects can be passed to the Format class or
  40. * its subclasses for formatting. Formattable is a thin wrapper
  41. * class which interconverts between the primitive numeric types
  42. * (double, long, etc.) as well as UDate and UnicodeString.
  43. *
  44. * <p>Internally, a Formattable object is a union of primitive types.
  45. * As such, it can only store one flavor of data at a time. To
  46. * determine what flavor of data it contains, use the getType method.
  47. *
  48. * <p>As of ICU 3.0, Formattable may also wrap a UObject pointer,
  49. * which it owns. This allows an instance of any ICU class to be
  50. * encapsulated in a Formattable. For legacy reasons and for
  51. * efficiency, primitive numeric types are still stored directly
  52. * within a Formattable.
  53. *
  54. * <p>The Formattable class is not suitable for subclassing.
  55. *
  56. * <p>See UFormattable for a C wrapper.
  57. */
  58. class U_I18N_API Formattable : public UObject {
  59. public:
  60. /**
  61. * This enum is only used to let callers distinguish between
  62. * the Formattable(UDate) constructor and the Formattable(double)
  63. * constructor; the compiler cannot distinguish the signatures,
  64. * since UDate is currently typedefed to be either double or long.
  65. * If UDate is changed later to be a bonafide class
  66. * or struct, then we no longer need this enum.
  67. * @stable ICU 2.4
  68. */
  69. enum ISDATE { kIsDate };
  70. /**
  71. * Default constructor
  72. * @stable ICU 2.4
  73. */
  74. Formattable(); // Type kLong, value 0
  75. /**
  76. * Creates a Formattable object with a UDate instance.
  77. * @param d the UDate instance.
  78. * @param flag the flag to indicate this is a date. Always set it to kIsDate
  79. * @stable ICU 2.0
  80. */
  81. Formattable(UDate d, ISDATE flag);
  82. /**
  83. * Creates a Formattable object with a double number.
  84. * @param d the double number.
  85. * @stable ICU 2.0
  86. */
  87. Formattable(double d);
  88. /**
  89. * Creates a Formattable object with a long number.
  90. * @param l the long number.
  91. * @stable ICU 2.0
  92. */
  93. Formattable(int32_t l);
  94. /**
  95. * Creates a Formattable object with an int64_t number
  96. * @param ll the int64_t number.
  97. * @stable ICU 2.8
  98. */
  99. Formattable(int64_t ll);
  100. #if !UCONFIG_NO_CONVERSION
  101. /**
  102. * Creates a Formattable object with a char string pointer.
  103. * Assumes that the char string is null terminated.
  104. * @param strToCopy the char string.
  105. * @stable ICU 2.0
  106. */
  107. Formattable(const char* strToCopy);
  108. #endif
  109. /**
  110. * Creates a Formattable object of an appropriate numeric type from a
  111. * a decimal number in string form. The Formattable will retain the
  112. * full precision of the input in decimal format, even when it exceeds
  113. * what can be represented by a double or int64_t.
  114. *
  115. * @param number the unformatted (not localized) string representation
  116. * of the Decimal number.
  117. * @param status the error code. Possible errors include U_INVALID_FORMAT_ERROR
  118. * if the format of the string does not conform to that of a
  119. * decimal number.
  120. * @stable ICU 4.4
  121. */
  122. Formattable(const StringPiece &number, UErrorCode &status);
  123. /**
  124. * Creates a Formattable object with a UnicodeString object to copy from.
  125. * @param strToCopy the UnicodeString string.
  126. * @stable ICU 2.0
  127. */
  128. Formattable(const UnicodeString& strToCopy);
  129. /**
  130. * Creates a Formattable object with a UnicodeString object to adopt from.
  131. * @param strToAdopt the UnicodeString string.
  132. * @stable ICU 2.0
  133. */
  134. Formattable(UnicodeString* strToAdopt);
  135. /**
  136. * Creates a Formattable object with an array of Formattable objects.
  137. * @param arrayToCopy the Formattable object array.
  138. * @param count the array count.
  139. * @stable ICU 2.0
  140. */
  141. Formattable(const Formattable* arrayToCopy, int32_t count);
  142. /**
  143. * Creates a Formattable object that adopts the given UObject.
  144. * @param objectToAdopt the UObject to set this object to
  145. * @stable ICU 3.0
  146. */
  147. Formattable(UObject* objectToAdopt);
  148. /**
  149. * Copy constructor.
  150. * @stable ICU 2.0
  151. */
  152. Formattable(const Formattable&);
  153. /**
  154. * Assignment operator.
  155. * @param rhs The Formattable object to copy into this object.
  156. * @stable ICU 2.0
  157. */
  158. Formattable& operator=(const Formattable &rhs);
  159. /**
  160. * Equality comparison.
  161. * @param other the object to be compared with.
  162. * @return TRUE if other are equal to this, FALSE otherwise.
  163. * @stable ICU 2.0
  164. */
  165. UBool operator==(const Formattable &other) const;
  166. /**
  167. * Equality operator.
  168. * @param other the object to be compared with.
  169. * @return TRUE if other are unequal to this, FALSE otherwise.
  170. * @stable ICU 2.0
  171. */
  172. UBool operator!=(const Formattable& other) const
  173. { return !operator==(other); }
  174. /**
  175. * Destructor.
  176. * @stable ICU 2.0
  177. */
  178. virtual ~Formattable();
  179. /**
  180. * Clone this object.
  181. * Clones can be used concurrently in multiple threads.
  182. * If an error occurs, then NULL is returned.
  183. * The caller must delete the clone.
  184. *
  185. * @return a clone of this object
  186. *
  187. * @see getDynamicClassID
  188. * @stable ICU 2.8
  189. */
  190. Formattable *clone() const;
  191. /**
  192. * Selector for flavor of data type contained within a
  193. * Formattable object. Formattable is a union of several
  194. * different types, and at any time contains exactly one type.
  195. * @stable ICU 2.4
  196. */
  197. enum Type {
  198. /**
  199. * Selector indicating a UDate value. Use getDate to retrieve
  200. * the value.
  201. * @stable ICU 2.4
  202. */
  203. kDate,
  204. /**
  205. * Selector indicating a double value. Use getDouble to
  206. * retrieve the value.
  207. * @stable ICU 2.4
  208. */
  209. kDouble,
  210. /**
  211. * Selector indicating a 32-bit integer value. Use getLong to
  212. * retrieve the value.
  213. * @stable ICU 2.4
  214. */
  215. kLong,
  216. /**
  217. * Selector indicating a UnicodeString value. Use getString
  218. * to retrieve the value.
  219. * @stable ICU 2.4
  220. */
  221. kString,
  222. /**
  223. * Selector indicating an array of Formattables. Use getArray
  224. * to retrieve the value.
  225. * @stable ICU 2.4
  226. */
  227. kArray,
  228. /**
  229. * Selector indicating a 64-bit integer value. Use getInt64
  230. * to retrieve the value.
  231. * @stable ICU 2.8
  232. */
  233. kInt64,
  234. /**
  235. * Selector indicating a UObject value. Use getObject to
  236. * retrieve the value.
  237. * @stable ICU 3.0
  238. */
  239. kObject
  240. };
  241. /**
  242. * Gets the data type of this Formattable object.
  243. * @return the data type of this Formattable object.
  244. * @stable ICU 2.0
  245. */
  246. Type getType(void) const;
  247. /**
  248. * Returns TRUE if the data type of this Formattable object
  249. * is kDouble, kLong, or kInt64
  250. * @return TRUE if this is a pure numeric object
  251. * @stable ICU 3.0
  252. */
  253. UBool isNumeric() const;
  254. /**
  255. * Gets the double value of this object. If this object is not of type
  256. * kDouble then the result is undefined.
  257. * @return the double value of this object.
  258. * @stable ICU 2.0
  259. */
  260. double getDouble(void) const { return fValue.fDouble; }
  261. /**
  262. * Gets the double value of this object. If this object is of type
  263. * long, int64 or Decimal Number then a conversion is peformed, with
  264. * possible loss of precision. If the type is kObject and the
  265. * object is a Measure, then the result of
  266. * getNumber().getDouble(status) is returned. If this object is
  267. * neither a numeric type nor a Measure, then 0 is returned and
  268. * the status is set to U_INVALID_FORMAT_ERROR.
  269. * @param status the error code
  270. * @return the double value of this object.
  271. * @stable ICU 3.0
  272. */
  273. double getDouble(UErrorCode& status) const;
  274. /**
  275. * Gets the long value of this object. If this object is not of type
  276. * kLong then the result is undefined.
  277. * @return the long value of this object.
  278. * @stable ICU 2.0
  279. */
  280. int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
  281. /**
  282. * Gets the long value of this object. If the magnitude is too
  283. * large to fit in a long, then the maximum or minimum long value,
  284. * as appropriate, is returned and the status is set to
  285. * U_INVALID_FORMAT_ERROR. If this object is of type kInt64 and
  286. * it fits within a long, then no precision is lost. If it is of
  287. * type kDouble, then a conversion is peformed, with
  288. * truncation of any fractional part. If the type is kObject and
  289. * the object is a Measure, then the result of
  290. * getNumber().getLong(status) is returned. If this object is
  291. * neither a numeric type nor a Measure, then 0 is returned and
  292. * the status is set to U_INVALID_FORMAT_ERROR.
  293. * @param status the error code
  294. * @return the long value of this object.
  295. * @stable ICU 3.0
  296. */
  297. int32_t getLong(UErrorCode& status) const;
  298. /**
  299. * Gets the int64 value of this object. If this object is not of type
  300. * kInt64 then the result is undefined.
  301. * @return the int64 value of this object.
  302. * @stable ICU 2.8
  303. */
  304. int64_t getInt64(void) const { return fValue.fInt64; }
  305. /**
  306. * Gets the int64 value of this object. If this object is of a numeric
  307. * type and the magnitude is too large to fit in an int64, then
  308. * the maximum or minimum int64 value, as appropriate, is returned
  309. * and the status is set to U_INVALID_FORMAT_ERROR. If the
  310. * magnitude fits in an int64, then a casting conversion is
  311. * peformed, with truncation of any fractional part. If the type
  312. * is kObject and the object is a Measure, then the result of
  313. * getNumber().getDouble(status) is returned. If this object is
  314. * neither a numeric type nor a Measure, then 0 is returned and
  315. * the status is set to U_INVALID_FORMAT_ERROR.
  316. * @param status the error code
  317. * @return the int64 value of this object.
  318. * @stable ICU 3.0
  319. */
  320. int64_t getInt64(UErrorCode& status) const;
  321. /**
  322. * Gets the Date value of this object. If this object is not of type
  323. * kDate then the result is undefined.
  324. * @return the Date value of this object.
  325. * @stable ICU 2.0
  326. */
  327. UDate getDate() const { return fValue.fDate; }
  328. /**
  329. * Gets the Date value of this object. If the type is not a date,
  330. * status is set to U_INVALID_FORMAT_ERROR and the return value is
  331. * undefined.
  332. * @param status the error code.
  333. * @return the Date value of this object.
  334. * @stable ICU 3.0
  335. */
  336. UDate getDate(UErrorCode& status) const;
  337. /**
  338. * Gets the string value of this object. If this object is not of type
  339. * kString then the result is undefined.
  340. * @param result Output param to receive the Date value of this object.
  341. * @return A reference to 'result'.
  342. * @stable ICU 2.0
  343. */
  344. UnicodeString& getString(UnicodeString& result) const
  345. { result=*fValue.fString; return result; }
  346. /**
  347. * Gets the string value of this object. If the type is not a
  348. * string, status is set to U_INVALID_FORMAT_ERROR and a bogus
  349. * string is returned.
  350. * @param result Output param to receive the Date value of this object.
  351. * @param status the error code.
  352. * @return A reference to 'result'.
  353. * @stable ICU 3.0
  354. */
  355. UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
  356. /**
  357. * Gets a const reference to the string value of this object. If
  358. * this object is not of type kString then the result is
  359. * undefined.
  360. * @return a const reference to the string value of this object.
  361. * @stable ICU 2.0
  362. */
  363. inline const UnicodeString& getString(void) const;
  364. /**
  365. * Gets a const reference to the string value of this object. If
  366. * the type is not a string, status is set to
  367. * U_INVALID_FORMAT_ERROR and the result is a bogus string.
  368. * @param status the error code.
  369. * @return a const reference to the string value of this object.
  370. * @stable ICU 3.0
  371. */
  372. const UnicodeString& getString(UErrorCode& status) const;
  373. /**
  374. * Gets a reference to the string value of this object. If this
  375. * object is not of type kString then the result is undefined.
  376. * @return a reference to the string value of this object.
  377. * @stable ICU 2.0
  378. */
  379. inline UnicodeString& getString(void);
  380. /**
  381. * Gets a reference to the string value of this object. If the
  382. * type is not a string, status is set to U_INVALID_FORMAT_ERROR
  383. * and the result is a bogus string.
  384. * @param status the error code.
  385. * @return a reference to the string value of this object.
  386. * @stable ICU 3.0
  387. */
  388. UnicodeString& getString(UErrorCode& status);
  389. /**
  390. * Gets the array value and count of this object. If this object
  391. * is not of type kArray then the result is undefined.
  392. * @param count fill-in with the count of this object.
  393. * @return the array value of this object.
  394. * @stable ICU 2.0
  395. */
  396. const Formattable* getArray(int32_t& count) const
  397. { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
  398. /**
  399. * Gets the array value and count of this object. If the type is
  400. * not an array, status is set to U_INVALID_FORMAT_ERROR, count is
  401. * set to 0, and the result is NULL.
  402. * @param count fill-in with the count of this object.
  403. * @param status the error code.
  404. * @return the array value of this object.
  405. * @stable ICU 3.0
  406. */
  407. const Formattable* getArray(int32_t& count, UErrorCode& status) const;
  408. /**
  409. * Accesses the specified element in the array value of this
  410. * Formattable object. If this object is not of type kArray then
  411. * the result is undefined.
  412. * @param index the specified index.
  413. * @return the accessed element in the array.
  414. * @stable ICU 2.0
  415. */
  416. Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
  417. /**
  418. * Returns a pointer to the UObject contained within this
  419. * formattable, or NULL if this object does not contain a UObject.
  420. * @return a UObject pointer, or NULL
  421. * @stable ICU 3.0
  422. */
  423. const UObject* getObject() const;
  424. /**
  425. * Returns a numeric string representation of the number contained within this
  426. * formattable, or NULL if this object does not contain numeric type.
  427. * For values obtained by parsing, the returned decimal number retains
  428. * the full precision and range of the original input, unconstrained by
  429. * the limits of a double floating point or a 64 bit int.
  430. *
  431. * This function is not thread safe, and therfore is not declared const,
  432. * even though it is logically const.
  433. *
  434. * Possible errors include U_MEMORY_ALLOCATION_ERROR, and
  435. * U_INVALID_STATE if the formattable object has not been set to
  436. * a numeric type.
  437. *
  438. * @param status the error code.
  439. * @return the unformatted string representation of a number.
  440. * @stable ICU 4.4
  441. */
  442. StringPiece getDecimalNumber(UErrorCode &status);
  443. /**
  444. * Sets the double value of this object and changes the type to
  445. * kDouble.
  446. * @param d the new double value to be set.
  447. * @stable ICU 2.0
  448. */
  449. void setDouble(double d);
  450. /**
  451. * Sets the long value of this object and changes the type to
  452. * kLong.
  453. * @param l the new long value to be set.
  454. * @stable ICU 2.0
  455. */
  456. void setLong(int32_t l);
  457. /**
  458. * Sets the int64 value of this object and changes the type to
  459. * kInt64.
  460. * @param ll the new int64 value to be set.
  461. * @stable ICU 2.8
  462. */
  463. void setInt64(int64_t ll);
  464. /**
  465. * Sets the Date value of this object and changes the type to
  466. * kDate.
  467. * @param d the new Date value to be set.
  468. * @stable ICU 2.0
  469. */
  470. void setDate(UDate d);
  471. /**
  472. * Sets the string value of this object and changes the type to
  473. * kString.
  474. * @param stringToCopy the new string value to be set.
  475. * @stable ICU 2.0
  476. */
  477. void setString(const UnicodeString& stringToCopy);
  478. /**
  479. * Sets the array value and count of this object and changes the
  480. * type to kArray.
  481. * @param array the array value.
  482. * @param count the number of array elements to be copied.
  483. * @stable ICU 2.0
  484. */
  485. void setArray(const Formattable* array, int32_t count);
  486. /**
  487. * Sets and adopts the string value and count of this object and
  488. * changes the type to kArray.
  489. * @param stringToAdopt the new string value to be adopted.
  490. * @stable ICU 2.0
  491. */
  492. void adoptString(UnicodeString* stringToAdopt);
  493. /**
  494. * Sets and adopts the array value and count of this object and
  495. * changes the type to kArray.
  496. * @stable ICU 2.0
  497. */
  498. void adoptArray(Formattable* array, int32_t count);
  499. /**
  500. * Sets and adopts the UObject value of this object and changes
  501. * the type to kObject. After this call, the caller must not
  502. * delete the given object.
  503. * @param objectToAdopt the UObject value to be adopted
  504. * @stable ICU 3.0
  505. */
  506. void adoptObject(UObject* objectToAdopt);
  507. /**
  508. * Sets the the numeric value from a decimal number string, and changes
  509. * the type to to a numeric type appropriate for the number.
  510. * The syntax of the number is a "numeric string"
  511. * as defined in the Decimal Arithmetic Specification, available at
  512. * http://speleotrove.com/decimal
  513. * The full precision and range of the input number will be retained,
  514. * even when it exceeds what can be represented by a double or an int64.
  515. *
  516. * @param numberString a string representation of the unformatted decimal number.
  517. * @param status the error code. Set to U_INVALID_FORMAT_ERROR if the
  518. * incoming string is not a valid decimal number.
  519. * @stable ICU 4.4
  520. */
  521. void setDecimalNumber(const StringPiece &numberString,
  522. UErrorCode &status);
  523. /**
  524. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  525. *
  526. * @stable ICU 2.2
  527. */
  528. virtual UClassID getDynamicClassID() const;
  529. /**
  530. * ICU "poor man's RTTI", returns a UClassID for this class.
  531. *
  532. * @stable ICU 2.2
  533. */
  534. static UClassID U_EXPORT2 getStaticClassID();
  535. /**
  536. * Convert the UFormattable to a Formattable. Internally, this is a reinterpret_cast.
  537. * @param fmt a valid UFormattable
  538. * @return the UFormattable as a Formattable object pointer. This is an alias to the original
  539. * UFormattable, and so is only valid while the original argument remains in scope.
  540. * @stable ICU 52
  541. */
  542. static inline Formattable *fromUFormattable(UFormattable *fmt);
  543. /**
  544. * Convert the const UFormattable to a const Formattable. Internally, this is a reinterpret_cast.
  545. * @param fmt a valid UFormattable
  546. * @return the UFormattable as a Formattable object pointer. This is an alias to the original
  547. * UFormattable, and so is only valid while the original argument remains in scope.
  548. * @stable ICU 52
  549. */
  550. static inline const Formattable *fromUFormattable(const UFormattable *fmt);
  551. /**
  552. * Convert this object pointer to a UFormattable.
  553. * @return this object as a UFormattable pointer. This is an alias to this object,
  554. * and so is only valid while this object remains in scope.
  555. * @stable ICU 52
  556. */
  557. inline UFormattable *toUFormattable();
  558. /**
  559. * Convert this object pointer to a UFormattable.
  560. * @return this object as a UFormattable pointer. This is an alias to this object,
  561. * and so is only valid while this object remains in scope.
  562. * @stable ICU 52
  563. */
  564. inline const UFormattable *toUFormattable() const;
  565. #ifndef U_HIDE_DEPRECATED_API
  566. /**
  567. * Deprecated variant of getLong(UErrorCode&).
  568. * @param status the error code
  569. * @return the long value of this object.
  570. * @deprecated ICU 3.0 use getLong(UErrorCode&) instead
  571. */
  572. inline int32_t getLong(UErrorCode* status) const;
  573. #endif /* U_HIDE_DEPRECATED_API */
  574. #ifndef U_HIDE_INTERNAL_API
  575. /**
  576. * Internal function, do not use.
  577. * TODO: figure out how to make this be non-public.
  578. * NumberFormat::format(Formattable, ...
  579. * needs to get at the DigitList, if it exists, for
  580. * big decimal formatting.
  581. * @internal
  582. */
  583. DigitList *getDigitList() const { return fDecimalNum;}
  584. /**
  585. * @internal
  586. */
  587. DigitList *getInternalDigitList();
  588. /**
  589. * Adopt, and set value from, a DigitList
  590. * Internal Function, do not use.
  591. * @param dl the Digit List to be adopted
  592. * @internal
  593. */
  594. void adoptDigitList(DigitList *dl);
  595. /**
  596. * Internal function to return the CharString pointer.
  597. * @param status error code
  598. * @return pointer to the CharString - may become invalid if the object is modified
  599. * @internal
  600. */
  601. CharString *internalGetCharString(UErrorCode &status);
  602. #endif /* U_HIDE_INTERNAL_API */
  603. private:
  604. /**
  605. * Cleans up the memory for unwanted values. For example, the adopted
  606. * string or array objects.
  607. */
  608. void dispose(void);
  609. /**
  610. * Common initialization, for use by constructors.
  611. */
  612. void init();
  613. UnicodeString* getBogus() const;
  614. union {
  615. UObject* fObject;
  616. UnicodeString* fString;
  617. double fDouble;
  618. int64_t fInt64;
  619. UDate fDate;
  620. struct {
  621. Formattable* fArray;
  622. int32_t fCount;
  623. } fArrayAndCount;
  624. } fValue;
  625. CharString *fDecimalStr;
  626. DigitList *fDecimalNum;
  627. char fStackData[UNUM_INTERNAL_STACKARRAY_SIZE]; // must be big enough for DigitList
  628. Type fType;
  629. UnicodeString fBogus; // Bogus string when it's needed.
  630. };
  631. inline UDate Formattable::getDate(UErrorCode& status) const {
  632. if (fType != kDate) {
  633. if (U_SUCCESS(status)) {
  634. status = U_INVALID_FORMAT_ERROR;
  635. }
  636. return 0;
  637. }
  638. return fValue.fDate;
  639. }
  640. inline const UnicodeString& Formattable::getString(void) const {
  641. return *fValue.fString;
  642. }
  643. inline UnicodeString& Formattable::getString(void) {
  644. return *fValue.fString;
  645. }
  646. #ifndef U_HIDE_DEPRECATED_API
  647. inline int32_t Formattable::getLong(UErrorCode* status) const {
  648. return getLong(*status);
  649. }
  650. #endif /* U_HIDE_DEPRECATED_API */
  651. inline UFormattable* Formattable::toUFormattable() {
  652. return reinterpret_cast<UFormattable*>(this);
  653. }
  654. inline const UFormattable* Formattable::toUFormattable() const {
  655. return reinterpret_cast<const UFormattable*>(this);
  656. }
  657. inline Formattable* Formattable::fromUFormattable(UFormattable *fmt) {
  658. return reinterpret_cast<Formattable *>(fmt);
  659. }
  660. inline const Formattable* Formattable::fromUFormattable(const UFormattable *fmt) {
  661. return reinterpret_cast<const Formattable *>(fmt);
  662. }
  663. U_NAMESPACE_END
  664. #endif /* #if !UCONFIG_NO_FORMATTING */
  665. #endif //_FMTABLE
  666. //eof