intl/icu/source/i18n/unicode/fieldpos.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-2006, International Business Machines
michael@0 4 * Corporation and others. All Rights Reserved.
michael@0 5 ********************************************************************************
michael@0 6 *
michael@0 7 * File FIELDPOS.H
michael@0 8 *
michael@0 9 * Modification History:
michael@0 10 *
michael@0 11 * Date Name Description
michael@0 12 * 02/25/97 aliu Converted from java.
michael@0 13 * 03/17/97 clhuang Updated per Format implementation.
michael@0 14 * 07/17/98 stephen Added default/copy ctors, and operators =, ==, !=
michael@0 15 ********************************************************************************
michael@0 16 */
michael@0 17
michael@0 18 // *****************************************************************************
michael@0 19 // This file was generated from the java source file FieldPosition.java
michael@0 20 // *****************************************************************************
michael@0 21
michael@0 22 #ifndef FIELDPOS_H
michael@0 23 #define FIELDPOS_H
michael@0 24
michael@0 25 #include "unicode/utypes.h"
michael@0 26
michael@0 27 /**
michael@0 28 * \file
michael@0 29 * \brief C++ API: FieldPosition identifies the fields in a formatted output.
michael@0 30 */
michael@0 31
michael@0 32 #if !UCONFIG_NO_FORMATTING
michael@0 33
michael@0 34 #include "unicode/uobject.h"
michael@0 35
michael@0 36 U_NAMESPACE_BEGIN
michael@0 37
michael@0 38 /**
michael@0 39 * <code>FieldPosition</code> is a simple class used by <code>Format</code>
michael@0 40 * and its subclasses to identify fields in formatted output. Fields are
michael@0 41 * identified by constants, whose names typically end with <code>_FIELD</code>,
michael@0 42 * defined in the various subclasses of <code>Format</code>. See
michael@0 43 * <code>ERA_FIELD</code> and its friends in <code>DateFormat</code> for
michael@0 44 * an example.
michael@0 45 *
michael@0 46 * <p>
michael@0 47 * <code>FieldPosition</code> keeps track of the position of the
michael@0 48 * field within the formatted output with two indices: the index
michael@0 49 * of the first character of the field and the index of the last
michael@0 50 * character of the field.
michael@0 51 *
michael@0 52 * <p>
michael@0 53 * One version of the <code>format</code> method in the various
michael@0 54 * <code>Format</code> classes requires a <code>FieldPosition</code>
michael@0 55 * object as an argument. You use this <code>format</code> method
michael@0 56 * to perform partial formatting or to get information about the
michael@0 57 * formatted output (such as the position of a field).
michael@0 58 *
michael@0 59 * The FieldPosition class is not suitable for subclassing.
michael@0 60 *
michael@0 61 * <p>
michael@0 62 * Below is an example of using <code>FieldPosition</code> to aid
michael@0 63 * alignment of an array of formatted floating-point numbers on
michael@0 64 * their decimal points:
michael@0 65 * <pre>
michael@0 66 * \code
michael@0 67 * double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789,
michael@0 68 * 12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
michael@0 69 * int dNumSize = (int)(sizeof(doubleNum)/sizeof(double));
michael@0 70 *
michael@0 71 * UErrorCode status = U_ZERO_ERROR;
michael@0 72 * DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
michael@0 73 * fmt->setDecimalSeparatorAlwaysShown(true);
michael@0 74 *
michael@0 75 * const int tempLen = 20;
michael@0 76 * char temp[tempLen];
michael@0 77 *
michael@0 78 * for (int i=0; i<dNumSize; i++) {
michael@0 79 * FieldPosition pos(NumberFormat::INTEGER_FIELD);
michael@0 80 * UnicodeString buf;
michael@0 81 * char fmtText[tempLen];
michael@0 82 * ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);
michael@0 83 * for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces
michael@0 84 * temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0';
michael@0 85 * cout << temp << fmtText << endl;
michael@0 86 * }
michael@0 87 * delete fmt;
michael@0 88 * \endcode
michael@0 89 * </pre>
michael@0 90 * <p>
michael@0 91 * The code will generate the following output:
michael@0 92 * <pre>
michael@0 93 * \code
michael@0 94 * 123,456,789.000
michael@0 95 * -12,345,678.900
michael@0 96 * 1,234,567.880
michael@0 97 * -123,456.789
michael@0 98 * 12,345.678
michael@0 99 * -1,234.567
michael@0 100 * 123.456
michael@0 101 * -12.345
michael@0 102 * 1.234
michael@0 103 * \endcode
michael@0 104 * </pre>
michael@0 105 */
michael@0 106 class U_I18N_API FieldPosition : public UObject {
michael@0 107 public:
michael@0 108 /**
michael@0 109 * DONT_CARE may be specified as the field to indicate that the
michael@0 110 * caller doesn't need to specify a field. Do not subclass.
michael@0 111 */
michael@0 112 enum { DONT_CARE = -1 };
michael@0 113
michael@0 114 /**
michael@0 115 * Creates a FieldPosition object with a non-specified field.
michael@0 116 * @stable ICU 2.0
michael@0 117 */
michael@0 118 FieldPosition()
michael@0 119 : UObject(), fField(DONT_CARE), fBeginIndex(0), fEndIndex(0) {}
michael@0 120
michael@0 121 /**
michael@0 122 * Creates a FieldPosition object for the given field. Fields are
michael@0 123 * identified by constants, whose names typically end with _FIELD,
michael@0 124 * in the various subclasses of Format.
michael@0 125 *
michael@0 126 * @see NumberFormat#INTEGER_FIELD
michael@0 127 * @see NumberFormat#FRACTION_FIELD
michael@0 128 * @see DateFormat#YEAR_FIELD
michael@0 129 * @see DateFormat#MONTH_FIELD
michael@0 130 * @stable ICU 2.0
michael@0 131 */
michael@0 132 FieldPosition(int32_t field)
michael@0 133 : UObject(), fField(field), fBeginIndex(0), fEndIndex(0) {}
michael@0 134
michael@0 135 /**
michael@0 136 * Copy constructor
michael@0 137 * @param copy the object to be copied from.
michael@0 138 * @stable ICU 2.0
michael@0 139 */
michael@0 140 FieldPosition(const FieldPosition& copy)
michael@0 141 : UObject(copy), fField(copy.fField), fBeginIndex(copy.fBeginIndex), fEndIndex(copy.fEndIndex) {}
michael@0 142
michael@0 143 /**
michael@0 144 * Destructor
michael@0 145 * @stable ICU 2.0
michael@0 146 */
michael@0 147 virtual ~FieldPosition();
michael@0 148
michael@0 149 /**
michael@0 150 * Assignment operator
michael@0 151 * @param copy the object to be copied from.
michael@0 152 * @stable ICU 2.0
michael@0 153 */
michael@0 154 FieldPosition& operator=(const FieldPosition& copy);
michael@0 155
michael@0 156 /**
michael@0 157 * Equality operator.
michael@0 158 * @param that the object to be compared with.
michael@0 159 * @return TRUE if the two field positions are equal, FALSE otherwise.
michael@0 160 * @stable ICU 2.0
michael@0 161 */
michael@0 162 UBool operator==(const FieldPosition& that) const;
michael@0 163
michael@0 164 /**
michael@0 165 * Equality operator.
michael@0 166 * @param that the object to be compared with.
michael@0 167 * @return TRUE if the two field positions are not equal, FALSE otherwise.
michael@0 168 * @stable ICU 2.0
michael@0 169 */
michael@0 170 UBool operator!=(const FieldPosition& that) const;
michael@0 171
michael@0 172 /**
michael@0 173 * Clone this object.
michael@0 174 * Clones can be used concurrently in multiple threads.
michael@0 175 * If an error occurs, then NULL is returned.
michael@0 176 * The caller must delete the clone.
michael@0 177 *
michael@0 178 * @return a clone of this object
michael@0 179 *
michael@0 180 * @see getDynamicClassID
michael@0 181 * @stable ICU 2.8
michael@0 182 */
michael@0 183 FieldPosition *clone() const;
michael@0 184
michael@0 185 /**
michael@0 186 * Retrieve the field identifier.
michael@0 187 * @return the field identifier.
michael@0 188 * @stable ICU 2.0
michael@0 189 */
michael@0 190 int32_t getField(void) const { return fField; }
michael@0 191
michael@0 192 /**
michael@0 193 * Retrieve the index of the first character in the requested field.
michael@0 194 * @return the index of the first character in the requested field.
michael@0 195 * @stable ICU 2.0
michael@0 196 */
michael@0 197 int32_t getBeginIndex(void) const { return fBeginIndex; }
michael@0 198
michael@0 199 /**
michael@0 200 * Retrieve the index of the character following the last character in the
michael@0 201 * requested field.
michael@0 202 * @return the index of the character following the last character in the
michael@0 203 * requested field.
michael@0 204 * @stable ICU 2.0
michael@0 205 */
michael@0 206 int32_t getEndIndex(void) const { return fEndIndex; }
michael@0 207
michael@0 208 /**
michael@0 209 * Set the field.
michael@0 210 * @param f the new value of the field.
michael@0 211 * @stable ICU 2.0
michael@0 212 */
michael@0 213 void setField(int32_t f) { fField = f; }
michael@0 214
michael@0 215 /**
michael@0 216 * Set the begin index. For use by subclasses of Format.
michael@0 217 * @param bi the new value of the begin index
michael@0 218 * @stable ICU 2.0
michael@0 219 */
michael@0 220 void setBeginIndex(int32_t bi) { fBeginIndex = bi; }
michael@0 221
michael@0 222 /**
michael@0 223 * Set the end index. For use by subclasses of Format.
michael@0 224 * @param ei the new value of the end index
michael@0 225 * @stable ICU 2.0
michael@0 226 */
michael@0 227 void setEndIndex(int32_t ei) { fEndIndex = ei; }
michael@0 228
michael@0 229 /**
michael@0 230 * ICU "poor man's RTTI", returns a UClassID for the actual class.
michael@0 231 *
michael@0 232 * @stable ICU 2.2
michael@0 233 */
michael@0 234 virtual UClassID getDynamicClassID() const;
michael@0 235
michael@0 236 /**
michael@0 237 * ICU "poor man's RTTI", returns a UClassID for this class.
michael@0 238 *
michael@0 239 * @stable ICU 2.2
michael@0 240 */
michael@0 241 static UClassID U_EXPORT2 getStaticClassID();
michael@0 242
michael@0 243 private:
michael@0 244 /**
michael@0 245 * Input: Desired field to determine start and end offsets for.
michael@0 246 * The meaning depends on the subclass of Format.
michael@0 247 */
michael@0 248 int32_t fField;
michael@0 249
michael@0 250 /**
michael@0 251 * Output: Start offset of field in text.
michael@0 252 * If the field does not occur in the text, 0 is returned.
michael@0 253 */
michael@0 254 int32_t fBeginIndex;
michael@0 255
michael@0 256 /**
michael@0 257 * Output: End offset of field in text.
michael@0 258 * If the field does not occur in the text, 0 is returned.
michael@0 259 */
michael@0 260 int32_t fEndIndex;
michael@0 261 };
michael@0 262
michael@0 263 inline FieldPosition&
michael@0 264 FieldPosition::operator=(const FieldPosition& copy)
michael@0 265 {
michael@0 266 fField = copy.fField;
michael@0 267 fEndIndex = copy.fEndIndex;
michael@0 268 fBeginIndex = copy.fBeginIndex;
michael@0 269 return *this;
michael@0 270 }
michael@0 271
michael@0 272 inline UBool
michael@0 273 FieldPosition::operator==(const FieldPosition& copy) const
michael@0 274 {
michael@0 275 return (fField == copy.fField &&
michael@0 276 fEndIndex == copy.fEndIndex &&
michael@0 277 fBeginIndex == copy.fBeginIndex);
michael@0 278 }
michael@0 279
michael@0 280 inline UBool
michael@0 281 FieldPosition::operator!=(const FieldPosition& copy) const
michael@0 282 {
michael@0 283 return !operator==(copy);
michael@0 284 }
michael@0 285
michael@0 286 U_NAMESPACE_END
michael@0 287
michael@0 288 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 289
michael@0 290 #endif // _FIELDPOS
michael@0 291 //eof

mercurial