Template Class FormatNumber
Defined in File number.hpp
Class Documentation
-
template<typename Number>
class FormatNumber Formatter for integral types.
Default formatter for integral types. For convenience, use the individual Format classes that inherit this one instead.
Public Functions
-
inline FormatNumber(int w = -1, ecl::Alignment a = NoAlign, ecl::IntegralBase b = Dec)
Default constructor. Initialises the format tags for width, alignment and base.
- Parameters:
w – : width (default - no width constraints)
a – : the textual alignment (default - no alignment constraints)
b – : the base format for the integral representation (default - decimal)
-
inline virtual ~FormatNumber()
-
FormatNumber<Number> &base(ecl::IntegralBase b)
Sets the base format. For integral types, this can be binary, hexadecimal or decimal.
See also
- Parameters:
b – : the base representation used for the output.
-
FormatNumber<Number> &width(int w)
Sets the width format parameter. Setting this to -1 will turn off width formatting constraints.
- Parameters:
w – : the total width of the text output.
-
FormatNumber<Number> &align(ecl::Alignment a)
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
ecl::formatters::Alignment
- Parameters:
a – : the aligning property for the output text.
-
FormatNumber<Number> &operator()(int w, ecl::Alignment a, ecl::IntegralBase b)
Convenient stream format parameter setter. This one permanently configures the width alignment and base as specified.
- Parameters:
w – : the total width of the text output.
a – : the aligning property for the output text.
b – : the base representation used for the output.
- Returns:
FormatNumber& : this formatter readied for use by a stream.
-
FormatNumber<Number> &operator()(Number n)
Convenient stream formatter. This function directly formats the specified input value with the stored settings.
Insert an input value to be formatted when passed to a stream.
- Parameters:
n – : the input value to be formatted.
- Returns:
FormatNumber& : this formatter readied for use by a stream.
-
FormatNumber<Number> &operator()(Number n, int w, ecl::IntegralBase b)
Convenient stream formatter. This member directly formats the specified input value with the supplied/temporary parameters.
Temporarily configure the formatter with a width, base combination along with a value to be formatted.
- Parameters:
n – : the input value to be formatted.
w – : the total width of the text output.
b – : the base representation used for the output.
- Returns:
FormatNumber& : this formatter readied for use by a stream.
-
FormatNumber<Number> &operator()(Number n, int w, ecl::Alignment a, ecl::IntegralBase b)
Convenient stream formatter. This member directly formats the specified input value with the supplied/temporary parameters.
Temporarily configure the formatter with a complete parameter set along with a value to be formatted.
- Parameters:
n – : the input value to be formatted.
w – : the total width of the text output.
a – : the aligning property for the output text.
b – : the base representation used for the output.
- Returns:
FormatNumber& : this formatter readied for use by a stream.
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 formatBin(OutputStream &ostream) const
-
template<typename OutputStream>
void formatHex(OutputStream &ostream) const
-
template<typename OutputStream>
void formatDec(OutputStream &ostream) const
Protected Attributes
-
int prm_width
-
int tmp_width
-
ecl::IntegralBase prm_base
-
ecl::IntegralBase tmp_base
-
int *width_
-
IntegralBase *base_
-
bool ready_to_format
Friends
-
template<typename OutputStream, typename N>
friend OutputStream &operator<<(OutputStream &ostream, FormatNumber<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.
- Throws:
StandardException – : throws if the formatter is used multiply in one stream operation [debug mode only].
- Returns:
OutputStream& : return the stream that was utilised.
-
inline FormatNumber(int w = -1, ecl::Alignment a = NoAlign, ecl::IntegralBase b = Dec)