intl/icu/source/i18n/unicode/fmtable.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial