Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************** |
michael@0 | 3 | * Copyright (C) 2013, International Business Machines Corporation and others. |
michael@0 | 4 | * All Rights Reserved. |
michael@0 | 5 | ******************************************************************************** |
michael@0 | 6 | * |
michael@0 | 7 | * File UFORMATTABLE.H |
michael@0 | 8 | * |
michael@0 | 9 | * Modification History: |
michael@0 | 10 | * |
michael@0 | 11 | * Date Name Description |
michael@0 | 12 | * 2013 Jun 7 srl New |
michael@0 | 13 | ******************************************************************************** |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * \file |
michael@0 | 18 | * \brief C API: UFormattable is a thin wrapper for primitive types used for formatting and parsing. |
michael@0 | 19 | * |
michael@0 | 20 | * This is a C interface to the icu::Formattable class. Static functions on this class convert |
michael@0 | 21 | * to and from this interface (via reinterpret_cast). Note that Formattables (and thus UFormattables) |
michael@0 | 22 | * are mutable, and many operations (even getters) may actually modify the internal state. For this |
michael@0 | 23 | * reason, UFormattables are not thread safe, and should not be shared between threads. |
michael@0 | 24 | * |
michael@0 | 25 | * See {@link unum_parseToUFormattable} for example code. |
michael@0 | 26 | */ |
michael@0 | 27 | |
michael@0 | 28 | #ifndef UFORMATTABLE_H |
michael@0 | 29 | #define UFORMATTABLE_H |
michael@0 | 30 | |
michael@0 | 31 | #include "unicode/utypes.h" |
michael@0 | 32 | |
michael@0 | 33 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 34 | |
michael@0 | 35 | #ifndef U_HIDE_DRAFT_API |
michael@0 | 36 | |
michael@0 | 37 | #include "unicode/localpointer.h" |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * Enum designating the type of a UFormattable instance. |
michael@0 | 41 | * Practically, this indicates which of the getters would return without conversion |
michael@0 | 42 | * or error. |
michael@0 | 43 | * @see icu::Formattable::Type |
michael@0 | 44 | * @draft ICU 52 |
michael@0 | 45 | */ |
michael@0 | 46 | typedef enum UFormattableType { |
michael@0 | 47 | UFMT_DATE = 0, /**< ufmt_getDate() will return without conversion. @see ufmt_getDate*/ |
michael@0 | 48 | UFMT_DOUBLE, /**< ufmt_getDouble() will return without conversion. @see ufmt_getDouble*/ |
michael@0 | 49 | UFMT_LONG, /**< ufmt_getLong() will return without conversion. @see ufmt_getLong */ |
michael@0 | 50 | UFMT_STRING, /**< ufmt_getUChars() will return without conversion. @see ufmt_getUChars*/ |
michael@0 | 51 | UFMT_ARRAY, /**< ufmt_countArray() and ufmt_getArray() will return the value. @see ufmt_getArrayItemByIndex */ |
michael@0 | 52 | UFMT_INT64, /**< ufmt_getInt64() will return without conversion. @see ufmt_getInt64 */ |
michael@0 | 53 | UFMT_OBJECT, /**< ufmt_getObject() will return without conversion. @see ufmt_getObject*/ |
michael@0 | 54 | UFMT_COUNT /**< Count of defined UFormattableType values */ |
michael@0 | 55 | } UFormattableType; |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Opaque type representing various types of data which may be used for formatting |
michael@0 | 60 | * and parsing operations. |
michael@0 | 61 | * @see icu::Formattable |
michael@0 | 62 | * @draft ICU 52 |
michael@0 | 63 | */ |
michael@0 | 64 | typedef void *UFormattable; |
michael@0 | 65 | |
michael@0 | 66 | /** |
michael@0 | 67 | * Initialize a UFormattable, to type UNUM_LONG, value 0 |
michael@0 | 68 | * may return error if memory allocation failed. |
michael@0 | 69 | * parameter status error code. |
michael@0 | 70 | * See {@link unum_parseToUFormattable} for example code. |
michael@0 | 71 | * @draft ICU 52 |
michael@0 | 72 | * @return the new UFormattable |
michael@0 | 73 | * @see ufmt_close |
michael@0 | 74 | * @see icu::Formattable::Formattable() |
michael@0 | 75 | */ |
michael@0 | 76 | U_DRAFT UFormattable* U_EXPORT2 |
michael@0 | 77 | ufmt_open(UErrorCode* status); |
michael@0 | 78 | |
michael@0 | 79 | /** |
michael@0 | 80 | * Cleanup any additional memory allocated by this UFormattable. |
michael@0 | 81 | * @param fmt the formatter |
michael@0 | 82 | * @draft ICU 52 |
michael@0 | 83 | * @see ufmt_open |
michael@0 | 84 | */ |
michael@0 | 85 | U_DRAFT void U_EXPORT2 |
michael@0 | 86 | ufmt_close(UFormattable* fmt); |
michael@0 | 87 | |
michael@0 | 88 | #if U_SHOW_CPLUSPLUS_API |
michael@0 | 89 | |
michael@0 | 90 | U_NAMESPACE_BEGIN |
michael@0 | 91 | |
michael@0 | 92 | /** |
michael@0 | 93 | * \class LocalUFormattablePointer |
michael@0 | 94 | * "Smart pointer" class, closes a UFormattable via ufmt_close(). |
michael@0 | 95 | * For most methods see the LocalPointerBase base class. |
michael@0 | 96 | * |
michael@0 | 97 | * @see LocalPointerBase |
michael@0 | 98 | * @see LocalPointer |
michael@0 | 99 | * @draft ICU 52 |
michael@0 | 100 | */ |
michael@0 | 101 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattablePointer, UFormattable, ufmt_close); |
michael@0 | 102 | |
michael@0 | 103 | U_NAMESPACE_END |
michael@0 | 104 | |
michael@0 | 105 | #endif |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Return the type of this object |
michael@0 | 109 | * @param fmt the UFormattable object |
michael@0 | 110 | * @param status status code - U_ILLEGAL_ARGUMENT_ERROR is returned if the UFormattable contains data not supported by |
michael@0 | 111 | * the API |
michael@0 | 112 | * @return the value as a UFormattableType |
michael@0 | 113 | * @see ufmt_isNumeric |
michael@0 | 114 | * @see icu::Formattable::getType() const |
michael@0 | 115 | * @draft ICU 52 |
michael@0 | 116 | */ |
michael@0 | 117 | U_DRAFT UFormattableType U_EXPORT2 |
michael@0 | 118 | ufmt_getType(const UFormattable* fmt, UErrorCode *status); |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * Return whether the object is numeric. |
michael@0 | 122 | * @param fmt the UFormattable object |
michael@0 | 123 | * @return true if the object is a double, long, or int64 value, else false. |
michael@0 | 124 | * @see ufmt_getType |
michael@0 | 125 | * @see icu::Formattable::isNumeric() const |
michael@0 | 126 | * @draft ICU 52 |
michael@0 | 127 | */ |
michael@0 | 128 | U_DRAFT UBool U_EXPORT2 |
michael@0 | 129 | ufmt_isNumeric(const UFormattable* fmt); |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Gets the UDate value of this object. If the type is not of type UFMT_DATE, |
michael@0 | 133 | * status is set to U_INVALID_FORMAT_ERROR and the return value is |
michael@0 | 134 | * undefined. |
michael@0 | 135 | * @param fmt the UFormattable object |
michael@0 | 136 | * @param status the error code - any conversion or format errors |
michael@0 | 137 | * @return the value |
michael@0 | 138 | * @draft ICU 52 |
michael@0 | 139 | * @see icu::Formattable::getDate(UErrorCode&) const |
michael@0 | 140 | */ |
michael@0 | 141 | U_DRAFT UDate U_EXPORT2 |
michael@0 | 142 | ufmt_getDate(const UFormattable* fmt, UErrorCode *status); |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Gets the double value of this object. If the type is not a UFMT_DOUBLE, or |
michael@0 | 146 | * if there are additional significant digits than fit in a double type, |
michael@0 | 147 | * a conversion is performed with possible loss of precision. |
michael@0 | 148 | * If the type is UFMT_OBJECT and the |
michael@0 | 149 | * object is a Measure, then the result of |
michael@0 | 150 | * getNumber().getDouble(status) is returned. If this object is |
michael@0 | 151 | * neither a numeric type nor a Measure, then 0 is returned and |
michael@0 | 152 | * the status is set to U_INVALID_FORMAT_ERROR. |
michael@0 | 153 | * @param fmt the UFormattable object |
michael@0 | 154 | * @param status the error code - any conversion or format errors |
michael@0 | 155 | * @return the value |
michael@0 | 156 | * @draft ICU 52 |
michael@0 | 157 | * @see icu::Formattable::getDouble(UErrorCode&) const |
michael@0 | 158 | */ |
michael@0 | 159 | U_DRAFT double U_EXPORT2 |
michael@0 | 160 | ufmt_getDouble(UFormattable* fmt, UErrorCode *status); |
michael@0 | 161 | |
michael@0 | 162 | /** |
michael@0 | 163 | * Gets the long (int32_t) value of this object. If the magnitude is too |
michael@0 | 164 | * large to fit in a long, then the maximum or minimum long value, |
michael@0 | 165 | * as appropriate, is returned and the status is set to |
michael@0 | 166 | * U_INVALID_FORMAT_ERROR. If this object is of type UFMT_INT64 and |
michael@0 | 167 | * it fits within a long, then no precision is lost. If it is of |
michael@0 | 168 | * type kDouble or kDecimalNumber, then a conversion is peformed, with |
michael@0 | 169 | * truncation of any fractional part. If the type is UFMT_OBJECT and |
michael@0 | 170 | * the object is a Measure, then the result of |
michael@0 | 171 | * getNumber().getLong(status) is returned. If this object is |
michael@0 | 172 | * neither a numeric type nor a Measure, then 0 is returned and |
michael@0 | 173 | * the status is set to U_INVALID_FORMAT_ERROR. |
michael@0 | 174 | * @param fmt the UFormattable object |
michael@0 | 175 | * @param status the error code - any conversion or format errors |
michael@0 | 176 | * @return the value |
michael@0 | 177 | * @draft ICU 52 |
michael@0 | 178 | * @see icu::Formattable::getLong(UErrorCode&) const |
michael@0 | 179 | */ |
michael@0 | 180 | U_DRAFT int32_t U_EXPORT2 |
michael@0 | 181 | ufmt_getLong(UFormattable* fmt, UErrorCode *status); |
michael@0 | 182 | |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * Gets the int64_t value of this object. If this object is of a numeric |
michael@0 | 186 | * type and the magnitude is too large to fit in an int64, then |
michael@0 | 187 | * the maximum or minimum int64 value, as appropriate, is returned |
michael@0 | 188 | * and the status is set to U_INVALID_FORMAT_ERROR. If the |
michael@0 | 189 | * magnitude fits in an int64, then a casting conversion is |
michael@0 | 190 | * peformed, with truncation of any fractional part. If the type |
michael@0 | 191 | * is UFMT_OBJECT and the object is a Measure, then the result of |
michael@0 | 192 | * getNumber().getDouble(status) is returned. If this object is |
michael@0 | 193 | * neither a numeric type nor a Measure, then 0 is returned and |
michael@0 | 194 | * the status is set to U_INVALID_FORMAT_ERROR. |
michael@0 | 195 | * @param fmt the UFormattable object |
michael@0 | 196 | * @param status the error code - any conversion or format errors |
michael@0 | 197 | * @return the value |
michael@0 | 198 | * @draft ICU 52 |
michael@0 | 199 | * @see icu::Formattable::getInt64(UErrorCode&) const |
michael@0 | 200 | */ |
michael@0 | 201 | U_DRAFT int64_t U_EXPORT2 |
michael@0 | 202 | ufmt_getInt64(UFormattable* fmt, UErrorCode *status); |
michael@0 | 203 | |
michael@0 | 204 | /** |
michael@0 | 205 | * Returns a pointer to the UObject contained within this |
michael@0 | 206 | * formattable (as a const void*), or NULL if this object |
michael@0 | 207 | * is not of type UFMT_OBJECT. |
michael@0 | 208 | * @param fmt the UFormattable object |
michael@0 | 209 | * @param status the error code - any conversion or format errors |
michael@0 | 210 | * @return the value as a const void*. It is a polymorphic C++ object. |
michael@0 | 211 | * @draft ICU 52 |
michael@0 | 212 | * @see icu::Formattable::getObject() const |
michael@0 | 213 | */ |
michael@0 | 214 | U_DRAFT const void *U_EXPORT2 |
michael@0 | 215 | ufmt_getObject(const UFormattable* fmt, UErrorCode *status); |
michael@0 | 216 | |
michael@0 | 217 | /** |
michael@0 | 218 | * Gets the string value of this object as a UChar string. If the type is not a |
michael@0 | 219 | * string, status is set to U_INVALID_FORMAT_ERROR and a NULL pointer is returned. |
michael@0 | 220 | * This function is not thread safe and may modify the UFormattable if need be to terminate the string. |
michael@0 | 221 | * The returned pointer is not valid if any other functions are called on this UFormattable, or if the UFormattable is closed. |
michael@0 | 222 | * @param fmt the UFormattable object |
michael@0 | 223 | * @param status the error code - any conversion or format errors |
michael@0 | 224 | * @param len if non null, contains the string length on return |
michael@0 | 225 | * @return the null terminated string value - must not be referenced after any other functions are called on this UFormattable. |
michael@0 | 226 | * @draft ICU 52 |
michael@0 | 227 | * @see icu::Formattable::getString(UnicodeString&)const |
michael@0 | 228 | */ |
michael@0 | 229 | U_DRAFT const UChar* U_EXPORT2 |
michael@0 | 230 | ufmt_getUChars(UFormattable* fmt, int32_t *len, UErrorCode *status); |
michael@0 | 231 | |
michael@0 | 232 | /** |
michael@0 | 233 | * Get the number of array objects contained, if an array type UFMT_ARRAY |
michael@0 | 234 | * @param fmt the UFormattable object |
michael@0 | 235 | * @param status the error code - any conversion or format errors. U_ILLEGAL_ARGUMENT_ERROR if not an array type. |
michael@0 | 236 | * @return the number of array objects or undefined if not an array type |
michael@0 | 237 | * @draft ICU 52 |
michael@0 | 238 | * @see ufmt_getArrayItemByIndex |
michael@0 | 239 | */ |
michael@0 | 240 | U_DRAFT int32_t U_EXPORT2 |
michael@0 | 241 | ufmt_getArrayLength(const UFormattable* fmt, UErrorCode *status); |
michael@0 | 242 | |
michael@0 | 243 | /** |
michael@0 | 244 | * Get the specified value from the array of UFormattables. Invalid if the object is not an array type UFMT_ARRAY |
michael@0 | 245 | * @param fmt the UFormattable object |
michael@0 | 246 | * @param n the number of the array to return (0 based). |
michael@0 | 247 | * @param status the error code - any conversion or format errors. Returns an error if n is out of bounds. |
michael@0 | 248 | * @return the nth array value, only valid while the containing UFormattable is valid. NULL if not an array. |
michael@0 | 249 | * @draft ICU 52 |
michael@0 | 250 | * @see icu::Formattable::getArray(int32_t&, UErrorCode&) const |
michael@0 | 251 | */ |
michael@0 | 252 | U_DRAFT UFormattable * U_EXPORT2 |
michael@0 | 253 | ufmt_getArrayItemByIndex(UFormattable* fmt, int32_t n, UErrorCode *status); |
michael@0 | 254 | |
michael@0 | 255 | /** |
michael@0 | 256 | * Returns a numeric string representation of the number contained within this |
michael@0 | 257 | * formattable, or NULL if this object does not contain numeric type. |
michael@0 | 258 | * For values obtained by parsing, the returned decimal number retains |
michael@0 | 259 | * the full precision and range of the original input, unconstrained by |
michael@0 | 260 | * the limits of a double floating point or a 64 bit int. |
michael@0 | 261 | * |
michael@0 | 262 | * This function is not thread safe, and therfore is not declared const, |
michael@0 | 263 | * even though it is logically const. |
michael@0 | 264 | * The resulting buffer is owned by the UFormattable and is invalid if any other functions are |
michael@0 | 265 | * called on the UFormattable. |
michael@0 | 266 | * |
michael@0 | 267 | * Possible errors include U_MEMORY_ALLOCATION_ERROR, and |
michael@0 | 268 | * U_INVALID_STATE if the formattable object has not been set to |
michael@0 | 269 | * a numeric type. |
michael@0 | 270 | * @param fmt the UFormattable object |
michael@0 | 271 | * @param len if non-null, on exit contains the string length (not including the terminating null) |
michael@0 | 272 | * @param status the error code |
michael@0 | 273 | * @return the character buffer as a NULL terminated string, which is owned by the object and must not be accessed if any other functions are called on this object. |
michael@0 | 274 | * @draft ICU 52 |
michael@0 | 275 | * @see icu::Formattable::getDecimalNumber(UErrorCode&) |
michael@0 | 276 | */ |
michael@0 | 277 | U_DRAFT const char * U_EXPORT2 |
michael@0 | 278 | ufmt_getDecNumChars(UFormattable *fmt, int32_t *len, UErrorCode *status); |
michael@0 | 279 | #endif /* U_HIDE_DRAFT_API */ |
michael@0 | 280 | |
michael@0 | 281 | #endif |
michael@0 | 282 | |
michael@0 | 283 | #endif |