1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/fmtable.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,764 @@ 1.4 +/* 1.5 +******************************************************************************** 1.6 +* Copyright (C) 1997-2013, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +******************************************************************************** 1.9 +* 1.10 +* File FMTABLE.H 1.11 +* 1.12 +* Modification History: 1.13 +* 1.14 +* Date Name Description 1.15 +* 02/29/97 aliu Creation. 1.16 +******************************************************************************** 1.17 +*/ 1.18 +#ifndef FMTABLE_H 1.19 +#define FMTABLE_H 1.20 + 1.21 +#include "unicode/utypes.h" 1.22 + 1.23 +/** 1.24 + * \file 1.25 + * \brief C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing 1.26 + */ 1.27 + 1.28 +#if !UCONFIG_NO_FORMATTING 1.29 + 1.30 +#include "unicode/unistr.h" 1.31 +#include "unicode/stringpiece.h" 1.32 +#include "unicode/uformattable.h" 1.33 + 1.34 +U_NAMESPACE_BEGIN 1.35 + 1.36 +class CharString; 1.37 +class DigitList; 1.38 + 1.39 +/** 1.40 + * \def UNUM_INTERNAL_STACKARRAY_SIZE 1.41 + * @internal 1.42 + */ 1.43 +#if U_PLATFORM == U_PF_OS400 1.44 +#define UNUM_INTERNAL_STACKARRAY_SIZE 144 1.45 +#else 1.46 +#define UNUM_INTERNAL_STACKARRAY_SIZE 128 1.47 +#endif 1.48 + 1.49 +/** 1.50 + * Formattable objects can be passed to the Format class or 1.51 + * its subclasses for formatting. Formattable is a thin wrapper 1.52 + * class which interconverts between the primitive numeric types 1.53 + * (double, long, etc.) as well as UDate and UnicodeString. 1.54 + * 1.55 + * <p>Internally, a Formattable object is a union of primitive types. 1.56 + * As such, it can only store one flavor of data at a time. To 1.57 + * determine what flavor of data it contains, use the getType method. 1.58 + * 1.59 + * <p>As of ICU 3.0, Formattable may also wrap a UObject pointer, 1.60 + * which it owns. This allows an instance of any ICU class to be 1.61 + * encapsulated in a Formattable. For legacy reasons and for 1.62 + * efficiency, primitive numeric types are still stored directly 1.63 + * within a Formattable. 1.64 + * 1.65 + * <p>The Formattable class is not suitable for subclassing. 1.66 + * 1.67 + * <p>See UFormattable for a C wrapper. 1.68 + */ 1.69 +class U_I18N_API Formattable : public UObject { 1.70 +public: 1.71 + /** 1.72 + * This enum is only used to let callers distinguish between 1.73 + * the Formattable(UDate) constructor and the Formattable(double) 1.74 + * constructor; the compiler cannot distinguish the signatures, 1.75 + * since UDate is currently typedefed to be either double or long. 1.76 + * If UDate is changed later to be a bonafide class 1.77 + * or struct, then we no longer need this enum. 1.78 + * @stable ICU 2.4 1.79 + */ 1.80 + enum ISDATE { kIsDate }; 1.81 + 1.82 + /** 1.83 + * Default constructor 1.84 + * @stable ICU 2.4 1.85 + */ 1.86 + Formattable(); // Type kLong, value 0 1.87 + 1.88 + /** 1.89 + * Creates a Formattable object with a UDate instance. 1.90 + * @param d the UDate instance. 1.91 + * @param flag the flag to indicate this is a date. Always set it to kIsDate 1.92 + * @stable ICU 2.0 1.93 + */ 1.94 + Formattable(UDate d, ISDATE flag); 1.95 + 1.96 + /** 1.97 + * Creates a Formattable object with a double number. 1.98 + * @param d the double number. 1.99 + * @stable ICU 2.0 1.100 + */ 1.101 + Formattable(double d); 1.102 + 1.103 + /** 1.104 + * Creates a Formattable object with a long number. 1.105 + * @param l the long number. 1.106 + * @stable ICU 2.0 1.107 + */ 1.108 + Formattable(int32_t l); 1.109 + 1.110 + /** 1.111 + * Creates a Formattable object with an int64_t number 1.112 + * @param ll the int64_t number. 1.113 + * @stable ICU 2.8 1.114 + */ 1.115 + Formattable(int64_t ll); 1.116 + 1.117 +#if !UCONFIG_NO_CONVERSION 1.118 + /** 1.119 + * Creates a Formattable object with a char string pointer. 1.120 + * Assumes that the char string is null terminated. 1.121 + * @param strToCopy the char string. 1.122 + * @stable ICU 2.0 1.123 + */ 1.124 + Formattable(const char* strToCopy); 1.125 +#endif 1.126 + 1.127 + /** 1.128 + * Creates a Formattable object of an appropriate numeric type from a 1.129 + * a decimal number in string form. The Formattable will retain the 1.130 + * full precision of the input in decimal format, even when it exceeds 1.131 + * what can be represented by a double or int64_t. 1.132 + * 1.133 + * @param number the unformatted (not localized) string representation 1.134 + * of the Decimal number. 1.135 + * @param status the error code. Possible errors include U_INVALID_FORMAT_ERROR 1.136 + * if the format of the string does not conform to that of a 1.137 + * decimal number. 1.138 + * @stable ICU 4.4 1.139 + */ 1.140 + Formattable(const StringPiece &number, UErrorCode &status); 1.141 + 1.142 + /** 1.143 + * Creates a Formattable object with a UnicodeString object to copy from. 1.144 + * @param strToCopy the UnicodeString string. 1.145 + * @stable ICU 2.0 1.146 + */ 1.147 + Formattable(const UnicodeString& strToCopy); 1.148 + 1.149 + /** 1.150 + * Creates a Formattable object with a UnicodeString object to adopt from. 1.151 + * @param strToAdopt the UnicodeString string. 1.152 + * @stable ICU 2.0 1.153 + */ 1.154 + Formattable(UnicodeString* strToAdopt); 1.155 + 1.156 + /** 1.157 + * Creates a Formattable object with an array of Formattable objects. 1.158 + * @param arrayToCopy the Formattable object array. 1.159 + * @param count the array count. 1.160 + * @stable ICU 2.0 1.161 + */ 1.162 + Formattable(const Formattable* arrayToCopy, int32_t count); 1.163 + 1.164 + /** 1.165 + * Creates a Formattable object that adopts the given UObject. 1.166 + * @param objectToAdopt the UObject to set this object to 1.167 + * @stable ICU 3.0 1.168 + */ 1.169 + Formattable(UObject* objectToAdopt); 1.170 + 1.171 + /** 1.172 + * Copy constructor. 1.173 + * @stable ICU 2.0 1.174 + */ 1.175 + Formattable(const Formattable&); 1.176 + 1.177 + /** 1.178 + * Assignment operator. 1.179 + * @param rhs The Formattable object to copy into this object. 1.180 + * @stable ICU 2.0 1.181 + */ 1.182 + Formattable& operator=(const Formattable &rhs); 1.183 + 1.184 + /** 1.185 + * Equality comparison. 1.186 + * @param other the object to be compared with. 1.187 + * @return TRUE if other are equal to this, FALSE otherwise. 1.188 + * @stable ICU 2.0 1.189 + */ 1.190 + UBool operator==(const Formattable &other) const; 1.191 + 1.192 + /** 1.193 + * Equality operator. 1.194 + * @param other the object to be compared with. 1.195 + * @return TRUE if other are unequal to this, FALSE otherwise. 1.196 + * @stable ICU 2.0 1.197 + */ 1.198 + UBool operator!=(const Formattable& other) const 1.199 + { return !operator==(other); } 1.200 + 1.201 + /** 1.202 + * Destructor. 1.203 + * @stable ICU 2.0 1.204 + */ 1.205 + virtual ~Formattable(); 1.206 + 1.207 + /** 1.208 + * Clone this object. 1.209 + * Clones can be used concurrently in multiple threads. 1.210 + * If an error occurs, then NULL is returned. 1.211 + * The caller must delete the clone. 1.212 + * 1.213 + * @return a clone of this object 1.214 + * 1.215 + * @see getDynamicClassID 1.216 + * @stable ICU 2.8 1.217 + */ 1.218 + Formattable *clone() const; 1.219 + 1.220 + /** 1.221 + * Selector for flavor of data type contained within a 1.222 + * Formattable object. Formattable is a union of several 1.223 + * different types, and at any time contains exactly one type. 1.224 + * @stable ICU 2.4 1.225 + */ 1.226 + enum Type { 1.227 + /** 1.228 + * Selector indicating a UDate value. Use getDate to retrieve 1.229 + * the value. 1.230 + * @stable ICU 2.4 1.231 + */ 1.232 + kDate, 1.233 + 1.234 + /** 1.235 + * Selector indicating a double value. Use getDouble to 1.236 + * retrieve the value. 1.237 + * @stable ICU 2.4 1.238 + */ 1.239 + kDouble, 1.240 + 1.241 + /** 1.242 + * Selector indicating a 32-bit integer value. Use getLong to 1.243 + * retrieve the value. 1.244 + * @stable ICU 2.4 1.245 + */ 1.246 + kLong, 1.247 + 1.248 + /** 1.249 + * Selector indicating a UnicodeString value. Use getString 1.250 + * to retrieve the value. 1.251 + * @stable ICU 2.4 1.252 + */ 1.253 + kString, 1.254 + 1.255 + /** 1.256 + * Selector indicating an array of Formattables. Use getArray 1.257 + * to retrieve the value. 1.258 + * @stable ICU 2.4 1.259 + */ 1.260 + kArray, 1.261 + 1.262 + /** 1.263 + * Selector indicating a 64-bit integer value. Use getInt64 1.264 + * to retrieve the value. 1.265 + * @stable ICU 2.8 1.266 + */ 1.267 + kInt64, 1.268 + 1.269 + /** 1.270 + * Selector indicating a UObject value. Use getObject to 1.271 + * retrieve the value. 1.272 + * @stable ICU 3.0 1.273 + */ 1.274 + kObject 1.275 + }; 1.276 + 1.277 + /** 1.278 + * Gets the data type of this Formattable object. 1.279 + * @return the data type of this Formattable object. 1.280 + * @stable ICU 2.0 1.281 + */ 1.282 + Type getType(void) const; 1.283 + 1.284 + /** 1.285 + * Returns TRUE if the data type of this Formattable object 1.286 + * is kDouble, kLong, or kInt64 1.287 + * @return TRUE if this is a pure numeric object 1.288 + * @stable ICU 3.0 1.289 + */ 1.290 + UBool isNumeric() const; 1.291 + 1.292 + /** 1.293 + * Gets the double value of this object. If this object is not of type 1.294 + * kDouble then the result is undefined. 1.295 + * @return the double value of this object. 1.296 + * @stable ICU 2.0 1.297 + */ 1.298 + double getDouble(void) const { return fValue.fDouble; } 1.299 + 1.300 + /** 1.301 + * Gets the double value of this object. If this object is of type 1.302 + * long, int64 or Decimal Number then a conversion is peformed, with 1.303 + * possible loss of precision. If the type is kObject and the 1.304 + * object is a Measure, then the result of 1.305 + * getNumber().getDouble(status) is returned. If this object is 1.306 + * neither a numeric type nor a Measure, then 0 is returned and 1.307 + * the status is set to U_INVALID_FORMAT_ERROR. 1.308 + * @param status the error code 1.309 + * @return the double value of this object. 1.310 + * @stable ICU 3.0 1.311 + */ 1.312 + double getDouble(UErrorCode& status) const; 1.313 + 1.314 + /** 1.315 + * Gets the long value of this object. If this object is not of type 1.316 + * kLong then the result is undefined. 1.317 + * @return the long value of this object. 1.318 + * @stable ICU 2.0 1.319 + */ 1.320 + int32_t getLong(void) const { return (int32_t)fValue.fInt64; } 1.321 + 1.322 + /** 1.323 + * Gets the long value of this object. If the magnitude is too 1.324 + * large to fit in a long, then the maximum or minimum long value, 1.325 + * as appropriate, is returned and the status is set to 1.326 + * U_INVALID_FORMAT_ERROR. If this object is of type kInt64 and 1.327 + * it fits within a long, then no precision is lost. If it is of 1.328 + * type kDouble, then a conversion is peformed, with 1.329 + * truncation of any fractional part. If the type is kObject and 1.330 + * the object is a Measure, then the result of 1.331 + * getNumber().getLong(status) is returned. If this object is 1.332 + * neither a numeric type nor a Measure, then 0 is returned and 1.333 + * the status is set to U_INVALID_FORMAT_ERROR. 1.334 + * @param status the error code 1.335 + * @return the long value of this object. 1.336 + * @stable ICU 3.0 1.337 + */ 1.338 + int32_t getLong(UErrorCode& status) const; 1.339 + 1.340 + /** 1.341 + * Gets the int64 value of this object. If this object is not of type 1.342 + * kInt64 then the result is undefined. 1.343 + * @return the int64 value of this object. 1.344 + * @stable ICU 2.8 1.345 + */ 1.346 + int64_t getInt64(void) const { return fValue.fInt64; } 1.347 + 1.348 + /** 1.349 + * Gets the int64 value of this object. If this object is of a numeric 1.350 + * type and the magnitude is too large to fit in an int64, then 1.351 + * the maximum or minimum int64 value, as appropriate, is returned 1.352 + * and the status is set to U_INVALID_FORMAT_ERROR. If the 1.353 + * magnitude fits in an int64, then a casting conversion is 1.354 + * peformed, with truncation of any fractional part. If the type 1.355 + * is kObject and the object is a Measure, then the result of 1.356 + * getNumber().getDouble(status) is returned. If this object is 1.357 + * neither a numeric type nor a Measure, then 0 is returned and 1.358 + * the status is set to U_INVALID_FORMAT_ERROR. 1.359 + * @param status the error code 1.360 + * @return the int64 value of this object. 1.361 + * @stable ICU 3.0 1.362 + */ 1.363 + int64_t getInt64(UErrorCode& status) const; 1.364 + 1.365 + /** 1.366 + * Gets the Date value of this object. If this object is not of type 1.367 + * kDate then the result is undefined. 1.368 + * @return the Date value of this object. 1.369 + * @stable ICU 2.0 1.370 + */ 1.371 + UDate getDate() const { return fValue.fDate; } 1.372 + 1.373 + /** 1.374 + * Gets the Date value of this object. If the type is not a date, 1.375 + * status is set to U_INVALID_FORMAT_ERROR and the return value is 1.376 + * undefined. 1.377 + * @param status the error code. 1.378 + * @return the Date value of this object. 1.379 + * @stable ICU 3.0 1.380 + */ 1.381 + UDate getDate(UErrorCode& status) const; 1.382 + 1.383 + /** 1.384 + * Gets the string value of this object. If this object is not of type 1.385 + * kString then the result is undefined. 1.386 + * @param result Output param to receive the Date value of this object. 1.387 + * @return A reference to 'result'. 1.388 + * @stable ICU 2.0 1.389 + */ 1.390 + UnicodeString& getString(UnicodeString& result) const 1.391 + { result=*fValue.fString; return result; } 1.392 + 1.393 + /** 1.394 + * Gets the string value of this object. If the type is not a 1.395 + * string, status is set to U_INVALID_FORMAT_ERROR and a bogus 1.396 + * string is returned. 1.397 + * @param result Output param to receive the Date value of this object. 1.398 + * @param status the error code. 1.399 + * @return A reference to 'result'. 1.400 + * @stable ICU 3.0 1.401 + */ 1.402 + UnicodeString& getString(UnicodeString& result, UErrorCode& status) const; 1.403 + 1.404 + /** 1.405 + * Gets a const reference to the string value of this object. If 1.406 + * this object is not of type kString then the result is 1.407 + * undefined. 1.408 + * @return a const reference to the string value of this object. 1.409 + * @stable ICU 2.0 1.410 + */ 1.411 + inline const UnicodeString& getString(void) const; 1.412 + 1.413 + /** 1.414 + * Gets a const reference to the string value of this object. If 1.415 + * the type is not a string, status is set to 1.416 + * U_INVALID_FORMAT_ERROR and the result is a bogus string. 1.417 + * @param status the error code. 1.418 + * @return a const reference to the string value of this object. 1.419 + * @stable ICU 3.0 1.420 + */ 1.421 + const UnicodeString& getString(UErrorCode& status) const; 1.422 + 1.423 + /** 1.424 + * Gets a reference to the string value of this object. If this 1.425 + * object is not of type kString then the result is undefined. 1.426 + * @return a reference to the string value of this object. 1.427 + * @stable ICU 2.0 1.428 + */ 1.429 + inline UnicodeString& getString(void); 1.430 + 1.431 + /** 1.432 + * Gets a reference to the string value of this object. If the 1.433 + * type is not a string, status is set to U_INVALID_FORMAT_ERROR 1.434 + * and the result is a bogus string. 1.435 + * @param status the error code. 1.436 + * @return a reference to the string value of this object. 1.437 + * @stable ICU 3.0 1.438 + */ 1.439 + UnicodeString& getString(UErrorCode& status); 1.440 + 1.441 + /** 1.442 + * Gets the array value and count of this object. If this object 1.443 + * is not of type kArray then the result is undefined. 1.444 + * @param count fill-in with the count of this object. 1.445 + * @return the array value of this object. 1.446 + * @stable ICU 2.0 1.447 + */ 1.448 + const Formattable* getArray(int32_t& count) const 1.449 + { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; } 1.450 + 1.451 + /** 1.452 + * Gets the array value and count of this object. If the type is 1.453 + * not an array, status is set to U_INVALID_FORMAT_ERROR, count is 1.454 + * set to 0, and the result is NULL. 1.455 + * @param count fill-in with the count of this object. 1.456 + * @param status the error code. 1.457 + * @return the array value of this object. 1.458 + * @stable ICU 3.0 1.459 + */ 1.460 + const Formattable* getArray(int32_t& count, UErrorCode& status) const; 1.461 + 1.462 + /** 1.463 + * Accesses the specified element in the array value of this 1.464 + * Formattable object. If this object is not of type kArray then 1.465 + * the result is undefined. 1.466 + * @param index the specified index. 1.467 + * @return the accessed element in the array. 1.468 + * @stable ICU 2.0 1.469 + */ 1.470 + Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; } 1.471 + 1.472 + /** 1.473 + * Returns a pointer to the UObject contained within this 1.474 + * formattable, or NULL if this object does not contain a UObject. 1.475 + * @return a UObject pointer, or NULL 1.476 + * @stable ICU 3.0 1.477 + */ 1.478 + const UObject* getObject() const; 1.479 + 1.480 + /** 1.481 + * Returns a numeric string representation of the number contained within this 1.482 + * formattable, or NULL if this object does not contain numeric type. 1.483 + * For values obtained by parsing, the returned decimal number retains 1.484 + * the full precision and range of the original input, unconstrained by 1.485 + * the limits of a double floating point or a 64 bit int. 1.486 + * 1.487 + * This function is not thread safe, and therfore is not declared const, 1.488 + * even though it is logically const. 1.489 + * 1.490 + * Possible errors include U_MEMORY_ALLOCATION_ERROR, and 1.491 + * U_INVALID_STATE if the formattable object has not been set to 1.492 + * a numeric type. 1.493 + * 1.494 + * @param status the error code. 1.495 + * @return the unformatted string representation of a number. 1.496 + * @stable ICU 4.4 1.497 + */ 1.498 + StringPiece getDecimalNumber(UErrorCode &status); 1.499 + 1.500 + /** 1.501 + * Sets the double value of this object and changes the type to 1.502 + * kDouble. 1.503 + * @param d the new double value to be set. 1.504 + * @stable ICU 2.0 1.505 + */ 1.506 + void setDouble(double d); 1.507 + 1.508 + /** 1.509 + * Sets the long value of this object and changes the type to 1.510 + * kLong. 1.511 + * @param l the new long value to be set. 1.512 + * @stable ICU 2.0 1.513 + */ 1.514 + void setLong(int32_t l); 1.515 + 1.516 + /** 1.517 + * Sets the int64 value of this object and changes the type to 1.518 + * kInt64. 1.519 + * @param ll the new int64 value to be set. 1.520 + * @stable ICU 2.8 1.521 + */ 1.522 + void setInt64(int64_t ll); 1.523 + 1.524 + /** 1.525 + * Sets the Date value of this object and changes the type to 1.526 + * kDate. 1.527 + * @param d the new Date value to be set. 1.528 + * @stable ICU 2.0 1.529 + */ 1.530 + void setDate(UDate d); 1.531 + 1.532 + /** 1.533 + * Sets the string value of this object and changes the type to 1.534 + * kString. 1.535 + * @param stringToCopy the new string value to be set. 1.536 + * @stable ICU 2.0 1.537 + */ 1.538 + void setString(const UnicodeString& stringToCopy); 1.539 + 1.540 + /** 1.541 + * Sets the array value and count of this object and changes the 1.542 + * type to kArray. 1.543 + * @param array the array value. 1.544 + * @param count the number of array elements to be copied. 1.545 + * @stable ICU 2.0 1.546 + */ 1.547 + void setArray(const Formattable* array, int32_t count); 1.548 + 1.549 + /** 1.550 + * Sets and adopts the string value and count of this object and 1.551 + * changes the type to kArray. 1.552 + * @param stringToAdopt the new string value to be adopted. 1.553 + * @stable ICU 2.0 1.554 + */ 1.555 + void adoptString(UnicodeString* stringToAdopt); 1.556 + 1.557 + /** 1.558 + * Sets and adopts the array value and count of this object and 1.559 + * changes the type to kArray. 1.560 + * @stable ICU 2.0 1.561 + */ 1.562 + void adoptArray(Formattable* array, int32_t count); 1.563 + 1.564 + /** 1.565 + * Sets and adopts the UObject value of this object and changes 1.566 + * the type to kObject. After this call, the caller must not 1.567 + * delete the given object. 1.568 + * @param objectToAdopt the UObject value to be adopted 1.569 + * @stable ICU 3.0 1.570 + */ 1.571 + void adoptObject(UObject* objectToAdopt); 1.572 + 1.573 + /** 1.574 + * Sets the the numeric value from a decimal number string, and changes 1.575 + * the type to to a numeric type appropriate for the number. 1.576 + * The syntax of the number is a "numeric string" 1.577 + * as defined in the Decimal Arithmetic Specification, available at 1.578 + * http://speleotrove.com/decimal 1.579 + * The full precision and range of the input number will be retained, 1.580 + * even when it exceeds what can be represented by a double or an int64. 1.581 + * 1.582 + * @param numberString a string representation of the unformatted decimal number. 1.583 + * @param status the error code. Set to U_INVALID_FORMAT_ERROR if the 1.584 + * incoming string is not a valid decimal number. 1.585 + * @stable ICU 4.4 1.586 + */ 1.587 + void setDecimalNumber(const StringPiece &numberString, 1.588 + UErrorCode &status); 1.589 + 1.590 + /** 1.591 + * ICU "poor man's RTTI", returns a UClassID for the actual class. 1.592 + * 1.593 + * @stable ICU 2.2 1.594 + */ 1.595 + virtual UClassID getDynamicClassID() const; 1.596 + 1.597 + /** 1.598 + * ICU "poor man's RTTI", returns a UClassID for this class. 1.599 + * 1.600 + * @stable ICU 2.2 1.601 + */ 1.602 + static UClassID U_EXPORT2 getStaticClassID(); 1.603 + 1.604 +#ifndef U_HIDE_DRAFT_API 1.605 + /** 1.606 + * Convert the UFormattable to a Formattable. Internally, this is a reinterpret_cast. 1.607 + * @param fmt a valid UFormattable 1.608 + * @return the UFormattable as a Formattable object pointer. This is an alias to the original 1.609 + * UFormattable, and so is only valid while the original argument remains in scope. 1.610 + * @draft ICU 52 1.611 + */ 1.612 + static inline Formattable *fromUFormattable(UFormattable *fmt); 1.613 + 1.614 + /** 1.615 + * Convert the const UFormattable to a const Formattable. Internally, this is a reinterpret_cast. 1.616 + * @param fmt a valid UFormattable 1.617 + * @return the UFormattable as a Formattable object pointer. This is an alias to the original 1.618 + * UFormattable, and so is only valid while the original argument remains in scope. 1.619 + * @draft ICU 52 1.620 + */ 1.621 + static inline const Formattable *fromUFormattable(const UFormattable *fmt); 1.622 + 1.623 + /** 1.624 + * Convert this object pointer to a UFormattable. 1.625 + * @return this object as a UFormattable pointer. This is an alias to this object, 1.626 + * and so is only valid while this object remains in scope. 1.627 + * @draft ICU 52 1.628 + */ 1.629 + inline UFormattable *toUFormattable(); 1.630 + 1.631 + /** 1.632 + * Convert this object pointer to a UFormattable. 1.633 + * @return this object as a UFormattable pointer. This is an alias to this object, 1.634 + * and so is only valid while this object remains in scope. 1.635 + * @draft ICU 52 1.636 + */ 1.637 + inline const UFormattable *toUFormattable() const; 1.638 +#endif /* U_HIDE_DRAFT_API */ 1.639 + 1.640 +#ifndef U_HIDE_DEPRECATED_API 1.641 + /** 1.642 + * Deprecated variant of getLong(UErrorCode&). 1.643 + * @param status the error code 1.644 + * @return the long value of this object. 1.645 + * @deprecated ICU 3.0 use getLong(UErrorCode&) instead 1.646 + */ 1.647 + inline int32_t getLong(UErrorCode* status) const; 1.648 +#endif /* U_HIDE_DEPRECATED_API */ 1.649 + 1.650 +#ifndef U_HIDE_INTERNAL_API 1.651 + /** 1.652 + * Internal function, do not use. 1.653 + * TODO: figure out how to make this be non-public. 1.654 + * NumberFormat::format(Formattable, ... 1.655 + * needs to get at the DigitList, if it exists, for 1.656 + * big decimal formatting. 1.657 + * @internal 1.658 + */ 1.659 + DigitList *getDigitList() const { return fDecimalNum;} 1.660 + 1.661 + /** 1.662 + * @internal 1.663 + */ 1.664 + DigitList *getInternalDigitList(); 1.665 + 1.666 + /** 1.667 + * Adopt, and set value from, a DigitList 1.668 + * Internal Function, do not use. 1.669 + * @param dl the Digit List to be adopted 1.670 + * @internal 1.671 + */ 1.672 + void adoptDigitList(DigitList *dl); 1.673 + 1.674 + /** 1.675 + * Internal function to return the CharString pointer. 1.676 + * @param status error code 1.677 + * @return pointer to the CharString - may become invalid if the object is modified 1.678 + * @internal 1.679 + */ 1.680 + CharString *internalGetCharString(UErrorCode &status); 1.681 + 1.682 +#endif /* U_HIDE_INTERNAL_API */ 1.683 + 1.684 +private: 1.685 + /** 1.686 + * Cleans up the memory for unwanted values. For example, the adopted 1.687 + * string or array objects. 1.688 + */ 1.689 + void dispose(void); 1.690 + 1.691 + /** 1.692 + * Common initialization, for use by constructors. 1.693 + */ 1.694 + void init(); 1.695 + 1.696 + UnicodeString* getBogus() const; 1.697 + 1.698 + union { 1.699 + UObject* fObject; 1.700 + UnicodeString* fString; 1.701 + double fDouble; 1.702 + int64_t fInt64; 1.703 + UDate fDate; 1.704 + struct { 1.705 + Formattable* fArray; 1.706 + int32_t fCount; 1.707 + } fArrayAndCount; 1.708 + } fValue; 1.709 + 1.710 + CharString *fDecimalStr; 1.711 + 1.712 + DigitList *fDecimalNum; 1.713 + 1.714 + char fStackData[UNUM_INTERNAL_STACKARRAY_SIZE]; // must be big enough for DigitList 1.715 + 1.716 + Type fType; 1.717 + UnicodeString fBogus; // Bogus string when it's needed. 1.718 +}; 1.719 + 1.720 +inline UDate Formattable::getDate(UErrorCode& status) const { 1.721 + if (fType != kDate) { 1.722 + if (U_SUCCESS(status)) { 1.723 + status = U_INVALID_FORMAT_ERROR; 1.724 + } 1.725 + return 0; 1.726 + } 1.727 + return fValue.fDate; 1.728 +} 1.729 + 1.730 +inline const UnicodeString& Formattable::getString(void) const { 1.731 + return *fValue.fString; 1.732 +} 1.733 + 1.734 +inline UnicodeString& Formattable::getString(void) { 1.735 + return *fValue.fString; 1.736 +} 1.737 + 1.738 +#ifndef U_HIDE_DEPRECATED_API 1.739 +inline int32_t Formattable::getLong(UErrorCode* status) const { 1.740 + return getLong(*status); 1.741 +} 1.742 +#endif /* U_HIDE_DEPRECATED_API */ 1.743 + 1.744 +#ifndef U_HIDE_DRAFT_API 1.745 +inline UFormattable* Formattable::toUFormattable() { 1.746 + return reinterpret_cast<UFormattable*>(this); 1.747 +} 1.748 + 1.749 +inline const UFormattable* Formattable::toUFormattable() const { 1.750 + return reinterpret_cast<const UFormattable*>(this); 1.751 +} 1.752 + 1.753 +inline Formattable* Formattable::fromUFormattable(UFormattable *fmt) { 1.754 + return reinterpret_cast<Formattable *>(fmt); 1.755 +} 1.756 + 1.757 +inline const Formattable* Formattable::fromUFormattable(const UFormattable *fmt) { 1.758 + return reinterpret_cast<const Formattable *>(fmt); 1.759 +} 1.760 +#endif /* U_HIDE_DRAFT_API */ 1.761 + 1.762 +U_NAMESPACE_END 1.763 + 1.764 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.765 + 1.766 +#endif //_FMTABLE 1.767 +//eof