Template Class FormatFloat

Class Documentation

template<typename Number>
class FormatFloat

Formatter for float types.

Default formatter for float types. For convenience, use the individual Format<float|double> classes that inherit this one instead.

Public Functions

inline FormatFloat(const int w = -1, const unsigned int p = 4, const ecl::Alignment a = NoAlign, const ecl::FloatBase b = Fixed)

Default constructor. Initialises the format tags for width, precision, alignment and base.

Parameters:
  • w – : width (default - no width constraints)

  • p – : the number of decimal places of precision (default - 4)

  • a – : the textual alignment (default - no alignment constraints)

  • b – : the base format for the floating point representation (default - fixed)

inline virtual ~FormatFloat()
inline FormatFloat<Number> &precision(const unsigned int p)

Sets the precision format parameter.

Sets the precision format parameter.

Parameters:

p – : the number of decimal places of precision.

Returns:

FormatFloat& : this formatter readied for use with a stream.

FormatFloat<Number> &width(const int w)

Sets the width format parameter.

Sets the width format parameter.

Sets the width format parameter. Setting this to -1 will turn off width formatting constraints.

Parameters:
  • w – : the width to use for the inserted float (-1 is no width constraint).

  • w – : the total width of the text output.

Returns:

FormatFloat& : this formatter readied for use with a stream.

FormatFloat<Number> &align(const ecl::Alignment a)

Sets the alignment format parameter.

Sets the alignment format parameter.

Sets the alignment format parameter. This aligns the text output in the text window which has a width specified by the width parameter.

See also

Alignment

Parameters:
  • a – : the textual alignment.

  • a – : the aligning property for the output text.

Returns:

FormatFloat& : this formatter readied for use with a stream.

FormatFloat<Number> &base(const ecl::FloatBase b)

Sets the base notation to use.

Sets the base notation to use (fixed or scientific).

Sets the base format. For floating point values, this can be fixed, exponential or scientific.

See also

FloatBase

Parameters:
  • b – : the base format for the floating point representation.

  • b – : the base representation used for the output.

Returns:

FormatFloat& : this formatter readied for use with a stream.

inline int precision()

Returns the current precision setting.

Returns:

int : the precision value.

inline int width()

Returns the current precision setting.

Returns:

int : the width value (-1 for no constraint).

FormatFloat<Number> &operator()(unsigned int p, const int w)

Convenient stream format parameter setter. This one permanently configures the width and precision as specified.

Parameters:
  • p – : the number of decimal places of precision.

  • w – : the total width of the text output.

Returns:

FormatFloat& : this formatter readied for use with a stream.

FormatFloat<Number> &operator()(const unsigned int p, const int w, const ecl::Alignment align, const ecl::FloatBase b)

Convenient stream format parameter setter. This one permanently configures all parameters.

Parameters:
  • p – : the number of decimal places of precision.

  • w – : the total width of the text output.

  • align – : the aligning property for the output text.

  • b – : the base representation used for the output.

Returns:

FormatFloat& : this formatter readied for use with a stream.

FormatFloat<Number> &operator()(const Number n)

Convenient stream formatter. This function directly formats the specified input value with the stored settings.

Format<float> format;
cout << format(3,4)(3.5215233) << endl;

Parameters:

n – : the input value to be formatted.

Returns:

FormatFloat& : this formatter readied for use with a stream.

FormatFloat<Number> &operator()(const Number n, const unsigned int p, const int w)

Convenient stream formatter. This member directly formats the specified input value with the supplied/temporary parameters.

Parameters:
  • n – : the input value to be formatted.

  • p – : the number of decimal places of precision.

  • w – : the total width of the text output.

FormatFloat<Number> &operator()(const Number n, const unsigned int p, const int w, const ecl::Alignment align, const ecl::FloatBase b)

Convenient stream formatter. This member directly formats the specified input value with the supplied/temporary parameters.

Parameters:
  • n – : the input value to be formatted.

  • p – : the number of decimal places of precision.

  • w – : the total width of the text output.

  • align – : the aligning property for the output text.

  • b – : the base representation used for the output.

Protected Functions

template<typename OutputStream>
void pad(int n, OutputStream &ostream) const
template<typename OutputStream>
void prePad(int n, OutputStream &ostream) const
template<typename OutputStream>
void postPad(int n, OutputStream &ostream) const
template<typename OutputStream>
void formatFixed(OutputStream &ostream) const
template<typename OutputStream>
void formatSci(OutputStream &ostream) const

Protected Attributes

int prm_width
int tmp_width
int prm_precision
int tmp_precision
ecl::Alignment prm_alignment
ecl::Alignment tmp_alignment = {}
ecl::FloatBase prm_base
ecl::FloatBase tmp_base
int *width_
int *precision_
ecl::Alignment *alignment_
ecl::FloatBase *base_
bool ready_to_format
Number value_

Friends

template<typename OutputStream, typename N>
friend OutputStream &operator<<(OutputStream &ostream, FormatFloat<N> &formatter)

Friend function which allows a stream to act on the formatter to produce the formatted result. This works on normal c++ streams as well as TextStreams.

Parameters:
  • ostream – : the stream.

  • formatter – : the formatter with prespecified format parameters and input value.

Returns:

OutputStream& : return the stream that was utilised.