Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

FieldPosition Class Reference

FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted output. More...

#include <fieldpos.h>

Inheritance diagram for FieldPosition::

UObject List of all members.

Public Types

enum  { DONT_CARE = -1 }
 DONT_CARE may be specified as the field to indicate that the caller doesn't need to specify a field. More...


Public Methods

 FieldPosition ()
 Creates a FieldPosition object with a non-specified field. More...

 FieldPosition (int32_t field)
 Creates a FieldPosition object for the given field. More...

 FieldPosition (const FieldPosition &copy)
 Copy constructor. More...

 ~FieldPosition ()
 Destructor. More...

FieldPosition & operator= (const FieldPosition &copy)
 Assignment operator. More...

UBool operator== (const FieldPosition &that) const
 Equality operator. More...

UBool operator!= (const FieldPosition &that) const
 Equality operator. More...

int32_t getField (void) const
 Retrieve the field identifier. More...

int32_t getBeginIndex (void) const
 Retrieve the index of the first character in the requested field. More...

int32_t getEndIndex (void) const
 Retrieve the index of the character following the last character in the requested field. More...

void setField (int32_t f)
 Set the field. More...

void setBeginIndex (int32_t bi)
 Set the begin index. More...

void setEndIndex (int32_t ei)
 Set the end index. More...

virtual UClassID getDynamicClassID () const
 ICU "poor man's RTTI", returns a UClassID for the actual class. More...


Static Public Methods

UClassID getStaticClassID ()
 ICU "poor man's RTTI", returns a UClassID for this class. More...


Private Attributes

int32_t fField
 Input: Desired field to determine start and end offsets for. More...

int32_t fBeginIndex
 Output: Start offset of field in text. More...

int32_t fEndIndex
 Output: End offset of field in text. More...


Static Private Attributes

const char fgClassID
 The address of this static class variable serves as this class's ID for ICU "poor man's RTTI". More...


Detailed Description

FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted output.

Fields are identified by constants, whose names typically end with _FIELD, defined in the various subclasses of Format. See ERA_FIELD and its friends in DateFormat for an example.

FieldPosition keeps track of the position of the field within the formatted output with two indices: the index of the first character of the field and the index of the last character of the field.

One version of the format method in the various Format classes requires a FieldPosition object as an argument. You use this format method to perform partial formatting or to get information about the formatted output (such as the position of a field).

Below is an example of using FieldPosition to aid alignment of an array of formatted floating-point numbers on their decimal points:

 
       double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789,
                  12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
       int dNumSize = (int)(sizeof(doubleNum)/sizeof(double));
       
       UErrorCode status = U_ZERO_ERROR;
       DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
       fmt->setDecimalSeparatorAlwaysShown(true);
       
       const int tempLen = 20;
       char temp[tempLen];
       
       for (int i=0; i<dNumSize; i++) {
           FieldPosition pos(NumberFormat::INTEGER_FIELD);
           UnicodeString buf;
           char fmtText[tempLen];
           ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);
           for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces
           temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0';
           cout << temp << fmtText   << endl;
       }
       delete fmt;

The code will generate the following output:

 
           123,456,789.000
           -12,345,678.900
             1,234,567.880
              -123,456.789
                12,345.678
                -1,234.567
                   123.456
                   -12.345
                     1.234

Definition at line 95 of file fieldpos.h.


Member Enumeration Documentation

anonymous enum
 

DONT_CARE may be specified as the field to indicate that the caller doesn't need to specify a field.

Do not subclass.

Enumeration values:
DONT_CARE 

Definition at line 101 of file fieldpos.h.


Constructor & Destructor Documentation

FieldPosition::FieldPosition   [inline]
 

Creates a FieldPosition object with a non-specified field.

Stable:

Definition at line 107 of file fieldpos.h.

FieldPosition::FieldPosition int32_t    field [inline]
 

Creates a FieldPosition object for the given field.

Fields are identified by constants, whose names typically end with _FIELD, in the various subclasses of Format.

See also:
NumberFormat::INTEGER_FIELD , NumberFormat::FRACTION_FIELD , DateFormat::YEAR_FIELD , DateFormat::MONTH_FIELD
Stable:

Definition at line 121 of file fieldpos.h.

FieldPosition::FieldPosition const FieldPosition &    copy [inline]
 

Copy constructor.

Parameters:
copy  the object to be copied from.
Stable:

Definition at line 129 of file fieldpos.h.

FieldPosition::~FieldPosition   [inline]
 

Destructor.

Stable:

Definition at line 136 of file fieldpos.h.


Member Function Documentation

int32_t FieldPosition::getBeginIndex void    const [inline]
 

Retrieve the index of the first character in the requested field.

Returns:
the index of the first character in the requested field.
Stable:

Definition at line 173 of file fieldpos.h.

virtual UClassID FieldPosition::getDynamicClassID void    const [inline, virtual]
 

ICU "poor man's RTTI", returns a UClassID for the actual class.

Draft:
This API has been introduced in ICU 2.2. It is still in draft state and may be modified in a future release.

Reimplemented from UObject.

Definition at line 210 of file fieldpos.h.

int32_t FieldPosition::getEndIndex void    const [inline]
 

Retrieve the index of the character following the last character in the requested field.

Returns:
the index of the character following the last character in the requested field.
Stable:

Definition at line 182 of file fieldpos.h.

int32_t FieldPosition::getField void    const [inline]
 

Retrieve the field identifier.

Returns:
the field identifier.
Stable:

Definition at line 166 of file fieldpos.h.

UClassID FieldPosition::getStaticClassID void    [inline, static]
 

ICU "poor man's RTTI", returns a UClassID for this class.

Draft:
This API has been introduced in ICU 2.2. It is still in draft state and may be modified in a future release.

Definition at line 217 of file fieldpos.h.

UBool FieldPosition::operator!= const FieldPosition &    copy const [inline]
 

Equality operator.

Parameters:
that  the object to be compared with.
Returns:
TRUE if the two field positions are not equal, FALSE otherwise.
Stable:

Definition at line 266 of file fieldpos.h.

FieldPosition & FieldPosition::operator= const FieldPosition &    copy [inline]
 

Assignment operator.

Parameters:
copy  the object to be copied from.
Stable:

Definition at line 246 of file fieldpos.h.

UBool FieldPosition::operator== const FieldPosition &    copy const [inline]
 

Equality operator.

Parameters:
that  the object to be compared with.
Returns:
TRUE if the two field positions are equal, FALSE otherwise.
Stable:

Definition at line 255 of file fieldpos.h.

Referenced by operator!=().

void FieldPosition::setBeginIndex int32_t    bi [inline]
 

Set the begin index.

For use by subclasses of Format.

Parameters:
bi  the new value of the begin index
Stable:

Definition at line 196 of file fieldpos.h.

void FieldPosition::setEndIndex int32_t    ei [inline]
 

Set the end index.

For use by subclasses of Format.

Parameters:
ei  the new value of the end index
Stable:

Definition at line 203 of file fieldpos.h.

void FieldPosition::setField int32_t    f [inline]
 

Set the field.

Parameters:
f  the new value of the field.
Stable:

Definition at line 189 of file fieldpos.h.


Member Data Documentation

int32_t FieldPosition::fBeginIndex [private]
 

Output: Start offset of field in text.

If the field does not occur in the text, 0 is returned.

Definition at line 230 of file fieldpos.h.

Referenced by operator=(), and operator==().

int32_t FieldPosition::fEndIndex [private]
 

Output: End offset of field in text.

If the field does not occur in the text, 0 is returned.

Definition at line 236 of file fieldpos.h.

Referenced by operator=(), and operator==().

int32_t FieldPosition::fField [private]
 

Input: Desired field to determine start and end offsets for.

The meaning depends on the subclass of Format.

Definition at line 224 of file fieldpos.h.

Referenced by operator=(), and operator==().

const char FieldPosition::fgClassID [static, private]
 

The address of this static class variable serves as this class's ID for ICU "poor man's RTTI".

Definition at line 242 of file fieldpos.h.


The documentation for this class was generated from the following file:
Generated on Thu Aug 15 14:13:58 2002 for ICU 2.2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001