jpayne@69: // © 2016 and later: Unicode, Inc. and others.
jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69: /*
jpayne@69: ********************************************************************************
jpayne@69: * Copyright (C) 1997-2006, International Business Machines
jpayne@69: * Corporation and others. All Rights Reserved.
jpayne@69: ********************************************************************************
jpayne@69: *
jpayne@69: * File FIELDPOS.H
jpayne@69: *
jpayne@69: * Modification History:
jpayne@69: *
jpayne@69: * Date Name Description
jpayne@69: * 02/25/97 aliu Converted from java.
jpayne@69: * 03/17/97 clhuang Updated per Format implementation.
jpayne@69: * 07/17/98 stephen Added default/copy ctors, and operators =, ==, !=
jpayne@69: ********************************************************************************
jpayne@69: */
jpayne@69:
jpayne@69: // *****************************************************************************
jpayne@69: // This file was generated from the java source file FieldPosition.java
jpayne@69: // *****************************************************************************
jpayne@69:
jpayne@69: #ifndef FIELDPOS_H
jpayne@69: #define FIELDPOS_H
jpayne@69:
jpayne@69: #include "unicode/utypes.h"
jpayne@69:
jpayne@69: #if U_SHOW_CPLUSPLUS_API
jpayne@69:
jpayne@69: /**
jpayne@69: * \file
jpayne@69: * \brief C++ API: FieldPosition identifies the fields in a formatted output.
jpayne@69: */
jpayne@69:
jpayne@69: #if !UCONFIG_NO_FORMATTING
jpayne@69:
jpayne@69: #include "unicode/uobject.h"
jpayne@69:
jpayne@69: U_NAMESPACE_BEGIN
jpayne@69:
jpayne@69: /**
jpayne@69: * FieldPosition
is a simple class used by Format
jpayne@69: * and its subclasses to identify fields in formatted output. Fields are
jpayne@69: * identified by constants, whose names typically end with _FIELD
,
jpayne@69: * defined in the various subclasses of Format
. See
jpayne@69: * ERA_FIELD
and its friends in DateFormat
for
jpayne@69: * an example.
jpayne@69: *
jpayne@69: *
jpayne@69: * FieldPosition
keeps track of the position of the
jpayne@69: * field within the formatted output with two indices: the index
jpayne@69: * of the first character of the field and the index of the last
jpayne@69: * character of the field.
jpayne@69: *
jpayne@69: *
jpayne@69: * One version of the format
method in the various
jpayne@69: * Format
classes requires a FieldPosition
jpayne@69: * object as an argument. You use this format
method
jpayne@69: * to perform partial formatting or to get information about the
jpayne@69: * formatted output (such as the position of a field).
jpayne@69: *
jpayne@69: * The FieldPosition class is not intended for public subclassing.
jpayne@69: *
jpayne@69: *
jpayne@69: * Below is an example of using FieldPosition
to aid
jpayne@69: * alignment of an array of formatted floating-point numbers on
jpayne@69: * their decimal points:
jpayne@69: *
jpayne@69: * \code jpayne@69: * double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789, jpayne@69: * 12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789}; jpayne@69: * int dNumSize = (int)(sizeof(doubleNum)/sizeof(double)); jpayne@69: * jpayne@69: * UErrorCode status = U_ZERO_ERROR; jpayne@69: * DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status); jpayne@69: * fmt->setDecimalSeparatorAlwaysShown(true); jpayne@69: * jpayne@69: * const int tempLen = 20; jpayne@69: * char temp[tempLen]; jpayne@69: * jpayne@69: * for (int i=0; iformat(doubleNum[i], buf, pos), fmtText); jpayne@69: * for (int j=0; j jpayne@69: * jpayne@69: * The code will generate the following output: jpayne@69: *
jpayne@69: * \code jpayne@69: * 123,456,789.000 jpayne@69: * -12,345,678.900 jpayne@69: * 1,234,567.880 jpayne@69: * -123,456.789 jpayne@69: * 12,345.678 jpayne@69: * -1,234.567 jpayne@69: * 123.456 jpayne@69: * -12.345 jpayne@69: * 1.234 jpayne@69: * \endcode jpayne@69: *jpayne@69: */ jpayne@69: class U_I18N_API FieldPosition : public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * DONT_CARE may be specified as the field to indicate that the jpayne@69: * caller doesn't need to specify a field. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: enum { DONT_CARE = -1 }; jpayne@69: jpayne@69: /** jpayne@69: * Creates a FieldPosition object with a non-specified field. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: FieldPosition() jpayne@69: : UObject(), fField(DONT_CARE), fBeginIndex(0), fEndIndex(0) {} jpayne@69: jpayne@69: /** jpayne@69: * Creates a FieldPosition object for the given field. Fields are jpayne@69: * identified by constants, whose names typically end with _FIELD, jpayne@69: * in the various subclasses of Format. jpayne@69: * jpayne@69: * @see NumberFormat#INTEGER_FIELD jpayne@69: * @see NumberFormat#FRACTION_FIELD jpayne@69: * @see DateFormat#YEAR_FIELD jpayne@69: * @see DateFormat#MONTH_FIELD jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: FieldPosition(int32_t field) jpayne@69: : UObject(), fField(field), fBeginIndex(0), fEndIndex(0) {} jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor jpayne@69: * @param copy the object to be copied from. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: FieldPosition(const FieldPosition& copy) jpayne@69: : UObject(copy), fField(copy.fField), fBeginIndex(copy.fBeginIndex), fEndIndex(copy.fEndIndex) {} jpayne@69: jpayne@69: /** jpayne@69: * Destructor jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual ~FieldPosition(); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator jpayne@69: * @param copy the object to be copied from. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: FieldPosition& operator=(const FieldPosition& copy); jpayne@69: jpayne@69: /** jpayne@69: * Equality operator. jpayne@69: * @param that the object to be compared with. jpayne@69: * @return TRUE if the two field positions are equal, FALSE otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool operator==(const FieldPosition& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Equality operator. jpayne@69: * @param that the object to be compared with. jpayne@69: * @return TRUE if the two field positions are not equal, FALSE otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool operator!=(const FieldPosition& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Clone this object. jpayne@69: * Clones can be used concurrently in multiple threads. jpayne@69: * If an error occurs, then NULL is returned. jpayne@69: * The caller must delete the clone. jpayne@69: * jpayne@69: * @return a clone of this object jpayne@69: * jpayne@69: * @see getDynamicClassID jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: FieldPosition *clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Retrieve the field identifier. jpayne@69: * @return the field identifier. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: int32_t getField(void) const { return fField; } jpayne@69: jpayne@69: /** jpayne@69: * Retrieve the index of the first character in the requested field. jpayne@69: * @return the index of the first character in the requested field. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: int32_t getBeginIndex(void) const { return fBeginIndex; } jpayne@69: jpayne@69: /** jpayne@69: * Retrieve the index of the character following the last character in the jpayne@69: * requested field. jpayne@69: * @return the index of the character following the last character in the jpayne@69: * requested field. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: int32_t getEndIndex(void) const { return fEndIndex; } jpayne@69: jpayne@69: /** jpayne@69: * Set the field. jpayne@69: * @param f the new value of the field. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setField(int32_t f) { fField = f; } jpayne@69: jpayne@69: /** jpayne@69: * Set the begin index. For use by subclasses of Format. jpayne@69: * @param bi the new value of the begin index jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setBeginIndex(int32_t bi) { fBeginIndex = bi; } jpayne@69: jpayne@69: /** jpayne@69: * Set the end index. For use by subclasses of Format. jpayne@69: * @param ei the new value of the end index jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEndIndex(int32_t ei) { fEndIndex = ei; } jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for the actual class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID() const; jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for this class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(); jpayne@69: jpayne@69: private: jpayne@69: /** jpayne@69: * Input: Desired field to determine start and end offsets for. jpayne@69: * The meaning depends on the subclass of Format. jpayne@69: */ jpayne@69: int32_t fField; jpayne@69: jpayne@69: /** jpayne@69: * Output: Start offset of field in text. jpayne@69: * If the field does not occur in the text, 0 is returned. jpayne@69: */ jpayne@69: int32_t fBeginIndex; jpayne@69: jpayne@69: /** jpayne@69: * Output: End offset of field in text. jpayne@69: * If the field does not occur in the text, 0 is returned. jpayne@69: */ jpayne@69: int32_t fEndIndex; jpayne@69: }; jpayne@69: jpayne@69: inline FieldPosition& jpayne@69: FieldPosition::operator=(const FieldPosition& copy) jpayne@69: { jpayne@69: fField = copy.fField; jpayne@69: fEndIndex = copy.fEndIndex; jpayne@69: fBeginIndex = copy.fBeginIndex; jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: inline UBool jpayne@69: FieldPosition::operator==(const FieldPosition& copy) const jpayne@69: { jpayne@69: return (fField == copy.fField && jpayne@69: fEndIndex == copy.fEndIndex && jpayne@69: fBeginIndex == copy.fBeginIndex); jpayne@69: } jpayne@69: jpayne@69: inline UBool jpayne@69: FieldPosition::operator!=(const FieldPosition& copy) const jpayne@69: { jpayne@69: return !operator==(copy); jpayne@69: } jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // _FIELDPOS jpayne@69: //eof