Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:04

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004  ********************************************************************************
0005  *   Copyright (C) 1997-2006, International Business Machines
0006  *   Corporation and others.  All Rights Reserved.
0007  ********************************************************************************
0008  *
0009  * File FIELDPOS.H
0010  *
0011  * Modification History:
0012  *
0013  *   Date        Name        Description
0014  *   02/25/97    aliu        Converted from java.
0015  *   03/17/97    clhuang     Updated per Format implementation.
0016  *    07/17/98    stephen        Added default/copy ctors, and operators =, ==, !=
0017  ********************************************************************************
0018  */
0019 
0020 // *****************************************************************************
0021 // This file was generated from the java source file FieldPosition.java
0022 // *****************************************************************************
0023  
0024 #ifndef FIELDPOS_H
0025 #define FIELDPOS_H
0026 
0027 #include "unicode/utypes.h"
0028 
0029 #if U_SHOW_CPLUSPLUS_API
0030 
0031 /**
0032  * \file 
0033  * \brief C++ API: FieldPosition identifies the fields in a formatted output.
0034  */
0035 
0036 #if !UCONFIG_NO_FORMATTING
0037 
0038 #include "unicode/uobject.h"
0039 
0040 U_NAMESPACE_BEGIN
0041 
0042 /**
0043  * <code>FieldPosition</code> is a simple class used by <code>Format</code>
0044  * and its subclasses to identify fields in formatted output. Fields are
0045  * identified by constants, whose names typically end with <code>_FIELD</code>,
0046  * defined in the various subclasses of <code>Format</code>. See
0047  * <code>ERA_FIELD</code> and its friends in <code>DateFormat</code> for
0048  * an example.
0049  *
0050  * <p>
0051  * <code>FieldPosition</code> keeps track of the position of the
0052  * field within the formatted output with two indices: the index
0053  * of the first character of the field and the index of the last
0054  * character of the field.
0055  *
0056  * <p>
0057  * One version of the <code>format</code> method in the various
0058  * <code>Format</code> classes requires a <code>FieldPosition</code>
0059  * object as an argument. You use this <code>format</code> method
0060  * to perform partial formatting or to get information about the
0061  * formatted output (such as the position of a field).
0062  *
0063  * The FieldPosition class is not intended for public subclassing.
0064  *
0065  * <p>
0066  * Below is an example of using <code>FieldPosition</code> to aid
0067  * alignment of an array of formatted floating-point numbers on
0068  * their decimal points:
0069  * <pre>
0070  * \code
0071  *       double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789,
0072  *                  12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
0073  *       int dNumSize = (int)(sizeof(doubleNum)/sizeof(double));
0074  *       
0075  *       UErrorCode status = U_ZERO_ERROR;
0076  *       DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
0077  *       fmt->setDecimalSeparatorAlwaysShown(true);
0078  *       
0079  *       const int tempLen = 20;
0080  *       char temp[tempLen];
0081  *       
0082  *       for (int i=0; i<dNumSize; i++) {
0083  *           FieldPosition pos(NumberFormat::INTEGER_FIELD);
0084  *           UnicodeString buf;
0085  *           char fmtText[tempLen];
0086  *           ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);
0087  *           for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces
0088  *           temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0';
0089  *           cout << temp << fmtText   << endl;
0090  *       }
0091  *       delete fmt;
0092  * \endcode
0093  * </pre>
0094  * <p>
0095  * The code will generate the following output:
0096  * <pre>
0097  * \code
0098  *           123,456,789.000
0099  *           -12,345,678.900
0100  *             1,234,567.880
0101  *              -123,456.789
0102  *                12,345.678
0103  *                -1,234.567
0104  *                   123.456
0105  *                   -12.345
0106  *                     1.234
0107  *  \endcode
0108  * </pre>
0109  */
0110 class U_I18N_API FieldPosition : public UObject {
0111 public:
0112     /**
0113      * DONT_CARE may be specified as the field to indicate that the
0114      * caller doesn't need to specify a field.
0115      * @stable ICU 2.0
0116      */
0117     enum { DONT_CARE = -1 };
0118 
0119     /**
0120      * Creates a FieldPosition object with a non-specified field.
0121      * @stable ICU 2.0
0122      */
0123     FieldPosition() 
0124         : UObject(), fField(DONT_CARE), fBeginIndex(0), fEndIndex(0) {}
0125 
0126     /**
0127      * Creates a FieldPosition object for the given field.  Fields are
0128      * identified by constants, whose names typically end with _FIELD,
0129      * in the various subclasses of Format.
0130      *
0131      * @see NumberFormat#INTEGER_FIELD
0132      * @see NumberFormat#FRACTION_FIELD
0133      * @see DateFormat#YEAR_FIELD
0134      * @see DateFormat#MONTH_FIELD
0135      * @stable ICU 2.0
0136      */
0137     FieldPosition(int32_t field) 
0138         : UObject(), fField(field), fBeginIndex(0), fEndIndex(0) {}
0139 
0140     /**
0141      * Copy constructor
0142      * @param copy the object to be copied from.
0143      * @stable ICU 2.0
0144      */
0145     FieldPosition(const FieldPosition& copy) 
0146         : UObject(copy), fField(copy.fField), fBeginIndex(copy.fBeginIndex), fEndIndex(copy.fEndIndex) {}
0147 
0148     /**
0149      * Destructor
0150      * @stable ICU 2.0
0151      */
0152     virtual ~FieldPosition();
0153 
0154     /**
0155      * Assignment operator
0156      * @param copy the object to be copied from.
0157      * @stable ICU 2.0
0158      */
0159     FieldPosition&      operator=(const FieldPosition& copy);
0160 
0161     /** 
0162      * Equality operator.
0163      * @param that    the object to be compared with.
0164      * @return        true if the two field positions are equal, false otherwise.
0165      * @stable ICU 2.0
0166      */
0167     bool               operator==(const FieldPosition& that) const;
0168 
0169     /** 
0170      * Equality operator.
0171      * @param that    the object to be compared with.
0172      * @return        true if the two field positions are not equal, false otherwise.
0173      * @stable ICU 2.0
0174      */
0175     bool               operator!=(const FieldPosition& that) const;
0176 
0177     /**
0178      * Clone this object.
0179      * Clones can be used concurrently in multiple threads.
0180      * If an error occurs, then nullptr is returned.
0181      * The caller must delete the clone.
0182      *
0183      * @return a clone of this object
0184      *
0185      * @see getDynamicClassID
0186      * @stable ICU 2.8
0187      */
0188     FieldPosition *clone() const;
0189 
0190     /**
0191      * Retrieve the field identifier.
0192      * @return    the field identifier.
0193      * @stable ICU 2.0
0194      */
0195     int32_t getField(void) const { return fField; }
0196 
0197     /**
0198      * Retrieve the index of the first character in the requested field.
0199      * @return    the index of the first character in the requested field.
0200      * @stable ICU 2.0
0201      */
0202     int32_t getBeginIndex(void) const { return fBeginIndex; }
0203 
0204     /**
0205      * Retrieve the index of the character following the last character in the
0206      * requested field.
0207      * @return    the index of the character following the last character in the
0208      *            requested field.
0209      * @stable ICU 2.0
0210      */
0211     int32_t getEndIndex(void) const { return fEndIndex; }
0212  
0213     /**
0214      * Set the field.
0215      * @param f    the new value of the field.
0216      * @stable ICU 2.0
0217      */
0218     void setField(int32_t f) { fField = f; }
0219 
0220     /**
0221      * Set the begin index.  For use by subclasses of Format.
0222      * @param bi    the new value of the begin index
0223      * @stable ICU 2.0
0224      */
0225     void setBeginIndex(int32_t bi) { fBeginIndex = bi; }
0226 
0227     /**
0228      * Set the end index.  For use by subclasses of Format.
0229      * @param ei    the new value of the end index
0230      * @stable ICU 2.0
0231      */
0232     void setEndIndex(int32_t ei) { fEndIndex = ei; }
0233     
0234     /**
0235      * ICU "poor man's RTTI", returns a UClassID for the actual class.
0236      *
0237      * @stable ICU 2.2
0238      */
0239     virtual UClassID getDynamicClassID() const override;
0240 
0241     /**
0242      * ICU "poor man's RTTI", returns a UClassID for this class.
0243      *
0244      * @stable ICU 2.2
0245      */
0246     static UClassID U_EXPORT2 getStaticClassID();
0247 
0248 private:
0249     /**
0250      * Input: Desired field to determine start and end offsets for.
0251      * The meaning depends on the subclass of Format.
0252      */
0253     int32_t fField;
0254 
0255     /**
0256      * Output: Start offset of field in text.
0257      * If the field does not occur in the text, 0 is returned.
0258      */
0259     int32_t fBeginIndex;
0260 
0261     /**
0262      * Output: End offset of field in text.
0263      * If the field does not occur in the text, 0 is returned.
0264      */
0265     int32_t fEndIndex;
0266 };
0267 
0268 inline FieldPosition&
0269 FieldPosition::operator=(const FieldPosition& copy)
0270 {
0271     fField         = copy.fField;
0272     fEndIndex     = copy.fEndIndex;
0273     fBeginIndex = copy.fBeginIndex;
0274     return *this;
0275 }
0276 
0277 inline bool
0278 FieldPosition::operator==(const FieldPosition& copy) const
0279 {
0280     return (fField == copy.fField &&
0281         fEndIndex == copy.fEndIndex &&
0282         fBeginIndex == copy.fBeginIndex);
0283 }
0284 
0285 inline bool
0286 FieldPosition::operator!=(const FieldPosition& copy) const
0287 {
0288     return !operator==(copy);
0289 }
0290 
0291 U_NAMESPACE_END
0292 
0293 #endif /* #if !UCONFIG_NO_FORMATTING */
0294 
0295 #endif /* U_SHOW_CPLUSPLUS_API */
0296 
0297 #endif // _FIELDPOS
0298 //eof