Class: TRationalNumberFormatter

Declaration: NumberFormat.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

TNumberFormatter

Inherited By:

None.

Purpose:

This class, derived from TNumberFormatter, handles rational numbers, formatting them as either proper or improper fractions. Note: The Scan function currently does not handle the sign correctly for rational numbers. Negative numbers might be scanned as positive numbers. This will be fixed in the next release.

Instantiation:

Always allocate on the heap.

Deriving Classes:

Derived classes must override the TextToCanonicalNumber and CanonicalNumberToText functions.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Member Function: TRationalNumberFormatter::TRationalNumberFormatter

  1. TRationalNumberFormatter ()
  2. TRationalNumberFormatter (EFractionPropriety thePropriety, bool useSuperScript, EFractionDirection theFractionDirection =kNumeratorFirst)
  3. TRationalNumberFormatter (const TRationalNumberFormatter &)

Interface Category:

API.

Purpose:

  1. Default constructor. Creates a formatter with these characteristics: formats proper fractions, puts the numerator first, superscripts the numerator, subscripts the denominator, uses a space between the integer and the fraction, uses a slash between the numerator and the denominator, does not style the numerator or denominator text, and uses a TUnicodeDecimalNumerals object to map characters to values.
  2. Creates a formatter with the specified propriety, superscripting, and direction. This formatter will have the other characteristics of the default formatter.
  3. Copy constructor.

Calling Context:

  1. Called by the stream-in operators and and directly to instantiate this class.
  2. Call this function directly.
  3. Called to copy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::~TRationalNumberFormatter

virtual ~ TRationalNumberFormatter ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetUpCanonicalNumberConverter

virtual void SetUpCanonicalNumberConverter ()

Interface Category:

API.

Purpose:

Sets up the canonical number converter for use in converting between binary numbers and text.

Calling Context:

Called by the Format and Scan functions.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::TextToCanonicalNumber

virtual void TextToCanonicalNumber (const TText &, TCanonicalNumber &, TNumberScanResult &, const TTextRange &)

Interface Category:

API.

Purpose:

During a scanning operation, converts a text string into a TCanonicalNumber object. The scanning function then uses a TCanonicalNumberConverter to convert the canonical number to a binary number.

Calling Context:

Called by the Scan member function when converting a text string into a numeral.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::CanonicalNumberToText

virtual void CanonicalNumberToText (const TCanonicalNumber &, TText &, TNumberFormatResult &)

Interface Category:

API.

Purpose:

During a formatting operation, converts a TCanonicalNumber object into a text string. The formatting function first uses a TCanonicalNumberConverter to convert the binary number into the canonical number.

Calling Context:

Called by the Format function when converting a numeral into a text string.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetVariance

virtual double GetVariance () const

Interface Category:

API.

Purpose:

Gets the precision requirement for how close the fraction value must be to the decimal value. The default value is 0.0000005.

Calling Context:

Called during conversion operations.

Parameters:

Return Value:

The precision requirement.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetVariance

virtual void SetVariance (double)

Interface Category:

API.

Purpose:

Sets the precision requirement for how close the fraction value must be to the decimal value.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetFractionSpace

virtual void GetFractionSpace (TText &) const

Interface Category:

API.

Purpose:

Gets the text used to separate the integer part of the value from the fractional part of the value.

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetFractionSpace

virtual void SetFractionSpace (const TText &)

Interface Category:

API.

Purpose:

Sets the text used to separate the integer part of the value from the fractional part of the value.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetFractionSign

virtual void GetFractionSign (TText &) const

Interface Category:

API.

Purpose:

Gets the text used to separate the numerator from the denominator.

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetFractionSign

virtual void SetFractionSign (const TText &)

Interface Category:

API.

Purpose:

Sets the text used to separate the numerator from the denominator.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetFractionPropriety

virtual EFractionPropriety GetFractionPropriety () const

Interface Category:

API.

Purpose:

Gets the EFractionPropriety value specifying whether formatted fractions should be proper or improper.

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

Returns the EFractionPropriety value, either kProperFraction or kImproperFraction.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetFractionPropriety

virtual void SetFractionPropriety (EFractionPropriety)

Interface Category:

API.

Purpose:

Specifies whether formatted fractions should be proper or improper.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetSuperscriptUse

virtual bool GetSuperscriptUse () const

Interface Category:

API.

Purpose:

Queries whether the formatter is set to superscript the first element of the fraction and subscript the second element of the fraction.

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

Returns true if the formatter is set to superscript the first element of the fraction and subscript the second element of the fraction.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetSuperscriptUse

virtual void SetSuperscriptUse (const bool)

Interface Category:

API.

Purpose:

Specifies whether the formatter should superscript the first element of the fraction and subscript the second element of the fraction.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetNumeratorStyle

virtual void GetNumeratorStyle (TStyleSet &) const

Interface Category:

API.

Purpose:

Gets the style set used when formatting the numerator into a text string.

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetNumeratorStyle

virtual void SetNumeratorStyle (const TStyleSet &)

Interface Category:

API.

Purpose:

Sets the style set used when formatting the numerator into a text string.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetDenominatorStyle

virtual void GetDenominatorStyle (TStyleSet &) const

Interface Category:

API.

Purpose:

Gets the style set used when formatting the denominator into a text string.

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetDenominatorStyle

virtual void SetDenominatorStyle (const TStyleSet &)

Interface Category:

API.

Purpose:

Sets the style set used when formatting the denominator into a text string.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetFractionDirection

virtual EFractionDirection GetFractionDirection () const

Interface Category:

API.

Purpose:

Queries whether the formatter is set to display the numerator or the denominator first. By default, the numerator appears first.

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

Returns the EFractionDirection value, either kNumeratorFirst or kDenominatorFirst.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::SetFractionDirection

virtual void SetFractionDirection (EFractionDirection)

Interface Category:

API.

Purpose:

Specifies whether the numerator or the denominator should appear first.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::GetIntegerFormatter

virtual TNumberFormatter * GetIntegerFormatter () const

Interface Category:

API.

Purpose:

Gets a pointer to the number formatter used to format each integral portion of the number (the integer, the numerator, and the denominator).

Calling Context:

Calling during the formatting operation.

Parameters:

Return Value:

A pointer to the integer formatter.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::AdoptIntegerFormatter

virtual void AdoptIntegerFormatter (TNumberFormatter *)

Interface Category:

API.

Purpose:

Specifies a pointer to the number formatter to use to format each integral portion of the number (the integer, the numerator, and the denominator).

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::operator=

TRationalNumberFormatter & operator =(const TRationalNumberFormatter &)

Interface Category:

API.

Purpose:

Assignment operator.

Calling Context:

Called when an object is assigned to another compatible object.

Parameters:

Return Value:

A non-const reference to the left-hand side object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::operator>>=

virtual TStream & operator >>=(TStream & toWhere) const

Interface Category:

API.

Purpose:

Stream-out operator.

Calling Context:

Called to stream out data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself out to.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::operator<<=

virtual TStream & operator <<= (TStream & fromWhere)

Interface Category:

API.

Purpose:

Stream-in operator.

Calling Context:

Called to stream in data.

Parameters:

Return Value:

Returns a reference to the stream the object streams itself in from.

Exceptions:

Throws a TStandardException if the version of the formatter cannot be used on the current system.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::IsEqual

virtual bool IsEqual (const MCollectible * obj) const

Interface Category:

API.

Purpose:

Compares two objects for equality.

Calling Context:

Called to compare compatible objects.

Parameters:

Return Value:

Returns true if the objects match.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TRationalNumberFormatter::Hash

virtual long Hash () const

Interface Category:

API.

Purpose:

Generates a hash value.

Calling Context:

Called to generate a hash value.

Parameters:

Return Value:

The numeric value of the hash.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.