1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/fieldpos.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,291 @@ 1.4 +/* 1.5 + ******************************************************************************** 1.6 + * Copyright (C) 1997-2006, International Business Machines 1.7 + * Corporation and others. All Rights Reserved. 1.8 + ******************************************************************************** 1.9 + * 1.10 + * File FIELDPOS.H 1.11 + * 1.12 + * Modification History: 1.13 + * 1.14 + * Date Name Description 1.15 + * 02/25/97 aliu Converted from java. 1.16 + * 03/17/97 clhuang Updated per Format implementation. 1.17 + * 07/17/98 stephen Added default/copy ctors, and operators =, ==, != 1.18 + ******************************************************************************** 1.19 + */ 1.20 + 1.21 +// ***************************************************************************** 1.22 +// This file was generated from the java source file FieldPosition.java 1.23 +// ***************************************************************************** 1.24 + 1.25 +#ifndef FIELDPOS_H 1.26 +#define FIELDPOS_H 1.27 + 1.28 +#include "unicode/utypes.h" 1.29 + 1.30 +/** 1.31 + * \file 1.32 + * \brief C++ API: FieldPosition identifies the fields in a formatted output. 1.33 + */ 1.34 + 1.35 +#if !UCONFIG_NO_FORMATTING 1.36 + 1.37 +#include "unicode/uobject.h" 1.38 + 1.39 +U_NAMESPACE_BEGIN 1.40 + 1.41 +/** 1.42 + * <code>FieldPosition</code> is a simple class used by <code>Format</code> 1.43 + * and its subclasses to identify fields in formatted output. Fields are 1.44 + * identified by constants, whose names typically end with <code>_FIELD</code>, 1.45 + * defined in the various subclasses of <code>Format</code>. See 1.46 + * <code>ERA_FIELD</code> and its friends in <code>DateFormat</code> for 1.47 + * an example. 1.48 + * 1.49 + * <p> 1.50 + * <code>FieldPosition</code> keeps track of the position of the 1.51 + * field within the formatted output with two indices: the index 1.52 + * of the first character of the field and the index of the last 1.53 + * character of the field. 1.54 + * 1.55 + * <p> 1.56 + * One version of the <code>format</code> method in the various 1.57 + * <code>Format</code> classes requires a <code>FieldPosition</code> 1.58 + * object as an argument. You use this <code>format</code> method 1.59 + * to perform partial formatting or to get information about the 1.60 + * formatted output (such as the position of a field). 1.61 + * 1.62 + * The FieldPosition class is not suitable for subclassing. 1.63 + * 1.64 + * <p> 1.65 + * Below is an example of using <code>FieldPosition</code> to aid 1.66 + * alignment of an array of formatted floating-point numbers on 1.67 + * their decimal points: 1.68 + * <pre> 1.69 + * \code 1.70 + * double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789, 1.71 + * 12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789}; 1.72 + * int dNumSize = (int)(sizeof(doubleNum)/sizeof(double)); 1.73 + * 1.74 + * UErrorCode status = U_ZERO_ERROR; 1.75 + * DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status); 1.76 + * fmt->setDecimalSeparatorAlwaysShown(true); 1.77 + * 1.78 + * const int tempLen = 20; 1.79 + * char temp[tempLen]; 1.80 + * 1.81 + * for (int i=0; i<dNumSize; i++) { 1.82 + * FieldPosition pos(NumberFormat::INTEGER_FIELD); 1.83 + * UnicodeString buf; 1.84 + * char fmtText[tempLen]; 1.85 + * ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText); 1.86 + * for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces 1.87 + * temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0'; 1.88 + * cout << temp << fmtText << endl; 1.89 + * } 1.90 + * delete fmt; 1.91 + * \endcode 1.92 + * </pre> 1.93 + * <p> 1.94 + * The code will generate the following output: 1.95 + * <pre> 1.96 + * \code 1.97 + * 123,456,789.000 1.98 + * -12,345,678.900 1.99 + * 1,234,567.880 1.100 + * -123,456.789 1.101 + * 12,345.678 1.102 + * -1,234.567 1.103 + * 123.456 1.104 + * -12.345 1.105 + * 1.234 1.106 + * \endcode 1.107 + * </pre> 1.108 + */ 1.109 +class U_I18N_API FieldPosition : public UObject { 1.110 +public: 1.111 + /** 1.112 + * DONT_CARE may be specified as the field to indicate that the 1.113 + * caller doesn't need to specify a field. Do not subclass. 1.114 + */ 1.115 + enum { DONT_CARE = -1 }; 1.116 + 1.117 + /** 1.118 + * Creates a FieldPosition object with a non-specified field. 1.119 + * @stable ICU 2.0 1.120 + */ 1.121 + FieldPosition() 1.122 + : UObject(), fField(DONT_CARE), fBeginIndex(0), fEndIndex(0) {} 1.123 + 1.124 + /** 1.125 + * Creates a FieldPosition object for the given field. Fields are 1.126 + * identified by constants, whose names typically end with _FIELD, 1.127 + * in the various subclasses of Format. 1.128 + * 1.129 + * @see NumberFormat#INTEGER_FIELD 1.130 + * @see NumberFormat#FRACTION_FIELD 1.131 + * @see DateFormat#YEAR_FIELD 1.132 + * @see DateFormat#MONTH_FIELD 1.133 + * @stable ICU 2.0 1.134 + */ 1.135 + FieldPosition(int32_t field) 1.136 + : UObject(), fField(field), fBeginIndex(0), fEndIndex(0) {} 1.137 + 1.138 + /** 1.139 + * Copy constructor 1.140 + * @param copy the object to be copied from. 1.141 + * @stable ICU 2.0 1.142 + */ 1.143 + FieldPosition(const FieldPosition& copy) 1.144 + : UObject(copy), fField(copy.fField), fBeginIndex(copy.fBeginIndex), fEndIndex(copy.fEndIndex) {} 1.145 + 1.146 + /** 1.147 + * Destructor 1.148 + * @stable ICU 2.0 1.149 + */ 1.150 + virtual ~FieldPosition(); 1.151 + 1.152 + /** 1.153 + * Assignment operator 1.154 + * @param copy the object to be copied from. 1.155 + * @stable ICU 2.0 1.156 + */ 1.157 + FieldPosition& operator=(const FieldPosition& copy); 1.158 + 1.159 + /** 1.160 + * Equality operator. 1.161 + * @param that the object to be compared with. 1.162 + * @return TRUE if the two field positions are equal, FALSE otherwise. 1.163 + * @stable ICU 2.0 1.164 + */ 1.165 + UBool operator==(const FieldPosition& that) const; 1.166 + 1.167 + /** 1.168 + * Equality operator. 1.169 + * @param that the object to be compared with. 1.170 + * @return TRUE if the two field positions are not equal, FALSE otherwise. 1.171 + * @stable ICU 2.0 1.172 + */ 1.173 + UBool operator!=(const FieldPosition& that) const; 1.174 + 1.175 + /** 1.176 + * Clone this object. 1.177 + * Clones can be used concurrently in multiple threads. 1.178 + * If an error occurs, then NULL is returned. 1.179 + * The caller must delete the clone. 1.180 + * 1.181 + * @return a clone of this object 1.182 + * 1.183 + * @see getDynamicClassID 1.184 + * @stable ICU 2.8 1.185 + */ 1.186 + FieldPosition *clone() const; 1.187 + 1.188 + /** 1.189 + * Retrieve the field identifier. 1.190 + * @return the field identifier. 1.191 + * @stable ICU 2.0 1.192 + */ 1.193 + int32_t getField(void) const { return fField; } 1.194 + 1.195 + /** 1.196 + * Retrieve the index of the first character in the requested field. 1.197 + * @return the index of the first character in the requested field. 1.198 + * @stable ICU 2.0 1.199 + */ 1.200 + int32_t getBeginIndex(void) const { return fBeginIndex; } 1.201 + 1.202 + /** 1.203 + * Retrieve the index of the character following the last character in the 1.204 + * requested field. 1.205 + * @return the index of the character following the last character in the 1.206 + * requested field. 1.207 + * @stable ICU 2.0 1.208 + */ 1.209 + int32_t getEndIndex(void) const { return fEndIndex; } 1.210 + 1.211 + /** 1.212 + * Set the field. 1.213 + * @param f the new value of the field. 1.214 + * @stable ICU 2.0 1.215 + */ 1.216 + void setField(int32_t f) { fField = f; } 1.217 + 1.218 + /** 1.219 + * Set the begin index. For use by subclasses of Format. 1.220 + * @param bi the new value of the begin index 1.221 + * @stable ICU 2.0 1.222 + */ 1.223 + void setBeginIndex(int32_t bi) { fBeginIndex = bi; } 1.224 + 1.225 + /** 1.226 + * Set the end index. For use by subclasses of Format. 1.227 + * @param ei the new value of the end index 1.228 + * @stable ICU 2.0 1.229 + */ 1.230 + void setEndIndex(int32_t ei) { fEndIndex = ei; } 1.231 + 1.232 + /** 1.233 + * ICU "poor man's RTTI", returns a UClassID for the actual class. 1.234 + * 1.235 + * @stable ICU 2.2 1.236 + */ 1.237 + virtual UClassID getDynamicClassID() const; 1.238 + 1.239 + /** 1.240 + * ICU "poor man's RTTI", returns a UClassID for this class. 1.241 + * 1.242 + * @stable ICU 2.2 1.243 + */ 1.244 + static UClassID U_EXPORT2 getStaticClassID(); 1.245 + 1.246 +private: 1.247 + /** 1.248 + * Input: Desired field to determine start and end offsets for. 1.249 + * The meaning depends on the subclass of Format. 1.250 + */ 1.251 + int32_t fField; 1.252 + 1.253 + /** 1.254 + * Output: Start offset of field in text. 1.255 + * If the field does not occur in the text, 0 is returned. 1.256 + */ 1.257 + int32_t fBeginIndex; 1.258 + 1.259 + /** 1.260 + * Output: End offset of field in text. 1.261 + * If the field does not occur in the text, 0 is returned. 1.262 + */ 1.263 + int32_t fEndIndex; 1.264 +}; 1.265 + 1.266 +inline FieldPosition& 1.267 +FieldPosition::operator=(const FieldPosition& copy) 1.268 +{ 1.269 + fField = copy.fField; 1.270 + fEndIndex = copy.fEndIndex; 1.271 + fBeginIndex = copy.fBeginIndex; 1.272 + return *this; 1.273 +} 1.274 + 1.275 +inline UBool 1.276 +FieldPosition::operator==(const FieldPosition& copy) const 1.277 +{ 1.278 + return (fField == copy.fField && 1.279 + fEndIndex == copy.fEndIndex && 1.280 + fBeginIndex == copy.fBeginIndex); 1.281 +} 1.282 + 1.283 +inline UBool 1.284 +FieldPosition::operator!=(const FieldPosition& copy) const 1.285 +{ 1.286 + return !operator==(copy); 1.287 +} 1.288 + 1.289 +U_NAMESPACE_END 1.290 + 1.291 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.292 + 1.293 +#endif // _FIELDPOS 1.294 +//eof