FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
streams::ios_base Class Reference

Base class for formatted streams. More...

#include <fastarduino/ios.h>

Inheritance diagram for streams::ios_base:

Public Types

using iostate = uint8_t
 Bitmask type to represent stream state flags. More...
 
using fmtflags = uint16_t
 Bitmask type to represent stream format flags. More...
 

Public Member Functions

iostate rdstate () const
 Return the current stream error state. More...
 
void setstate (iostate state)
 Set the stream error flags state in addition to currently set flags. More...
 
void clear (iostate state=goodbit)
 Set the stream error state flags by assigning them the value of state. More...
 
bool good () const
 
bool eof () const
 Return true if the associated stream has reached end-of-file. More...
 
bool fail () const
 Return true if an error has occurred on the associated stream, since last time state was reset (clear() was called). More...
 
bool bad () const
 Return true if a non-recoverable error has occurred on the associated stream. More...
 
bool operator! () const
 Return true if an error has occurred on the associated stream, since last time state was reset (clear() was called). More...
 
 operator bool () const
 Check that the current stream has no errors. More...
 
void flags (fmtflags flags)
 Set new format flags for this stream. More...
 
fmtflags flags () const
 Return the format flags currently selected in this stream. More...
 
void setf (fmtflags flags)
 Set this stream's format flags whose bits are set in flags, leaving unchanged the rest. More...
 
void setf (fmtflags flags, fmtflags mask)
 Set this stream's format flags whose bits are set in both flags and mask, and clears the format flags whose bits are set in mask but not in flags. More...
 
void unsetf (fmtflags flags)
 Clear this stream's format flags whose bits are set in flags. More...
 
char fill () const
 Return the fill character. More...
 
void fill (char fill)
 Set fill as new fill character for this stream. More...
 
void width (uint8_t width)
 Set minimum width used for displaying values. More...
 
uint8_t width () const
 Get the current minimum width value (default = 0) used for formatted output. More...
 
void precision (uint8_t precision)
 Set precision (number of digits after decimal point) used for displaying floating values. More...
 
uint8_t precision () const
 Get the current precision (default = 6) used for formatted floating values output. More...
 
ios_basecopyfmt (const ios_base &rhs)
 Copy formatting information from rhs to this stream. More...
 

Static Public Attributes

static constexpr iostate eofbit = 0x01
 This bit is set if the stream has unexpectedly reached its end during an extraction. More...
 
static constexpr iostate failbit = 0x02
 This bit is set when an input or operation failed due to a formatting error during extraction. More...
 
static constexpr iostate badbit = 0x04
 This bit is set when an irrecoverable stream error has occurred, e.g. More...
 
static constexpr iostate goodbit = 0
 No error; always 0. More...
 
static constexpr fmtflags dec = 0x0001
 Read or write integral values using decimal (0..9) base format. More...
 
static constexpr fmtflags bin = 0x0002
 Read or write integral values using binary (0,1) base format. More...
 
static constexpr fmtflags oct = 0x0004
 Read or write integral values using octal (0..7) base format. More...
 
static constexpr fmtflags hex = 0x0008
 Read or write integral values using hexadecimal (0..9,A..F) base format. More...
 
static constexpr fmtflags basefield = dec | bin | oct | hex
 Bitmask constant used with setf(fmtflags, fmtflags) when changing the output base format. More...
 
static constexpr fmtflags left = 0x0010
 Pad all output to width() characters, with fill() character appended at the end so that the output appears left-adjusted. More...
 
static constexpr fmtflags right = 0x0020
 Pad all output to width() characters, with fill() character added at the beginning so that the output appears right-adjusted. More...
 
static constexpr fmtflags adjustfield = left | right
 Bitmask constant used with setf(fmtflags, fmtflags) when changing the output adjustment. More...
 
static constexpr fmtflags scientific = 0x0040
 Write floating point values in fixed-point notation. More...
 
static constexpr fmtflags fixed = 0x0080
 Write floating point values in scientific notation. More...
 
static constexpr fmtflags floatfield = scientific | fixed
 Bitmask constant used with setf(fmtflags, fmtflags) when changing the floating point output representation. More...
 
static constexpr fmtflags boolalpha = 0x0200
 Read or write bool values as alphabetic string (true or false). More...
 
static constexpr fmtflags showbase = 0x0400
 Write integral values prefixed by their base: More...
 
static constexpr fmtflags showpos = 0x1000
 Write non-negative numerical values preceded by +. More...
 
static constexpr fmtflags skipws = 0x2000
 Skip leading spaces on certain extraction (read) operations. More...
 
static constexpr fmtflags unitbuf = 0x4000
 Flush output after each insertion operation. More...
 
static constexpr fmtflags uppercase = 0x8000U
 Write uppercase letters instead of lowercase in certain insertion operations. More...
 
static constexpr uint8_t MAX_PRECISION = 16
 The maximum allowed precision. More...
 

Detailed Description

Base class for formatted streams.

Allows defining base, width and precision for numbers display.

Definition at line 37 of file ios.h.

Member Typedef Documentation

◆ iostate

using streams::ios_base::iostate = uint8_t

Bitmask type to represent stream state flags.

This type is used as parameter or return value by methods setstate, rdstate and clear.

The values passed and retrieved by these methods can be any valid combination of the predefined constants:

  • goodbit (no error)
  • badbit
  • failbit
  • eofbit
See also
setstate(iostate)
rdstate()
clear(iostate)

Definition at line 56 of file ios.h.

◆ fmtflags

using streams::ios_base::fmtflags = uint16_t

Bitmask type to represent stream format flags.

This type is used as parameter or return value by methods flags, setf and unsetf. The values passed and retrieved by these methods can be any valid combination of the predefined constants:

  • basefield flags
    • dec (default)
    • bin
    • oct
    • hex
  • floatfield flags
    • fixed (default)
    • scientific
  • adjustfield flags
    • left
    • right (default)
  • independent flags
    • boolalpha
    • showbase
    • showpos
    • skipws (default)
    • unitbuf
    • uppercase
See also
flags()
flags(fmtflags)
setf(fmtflags)
setf(fmtflags, fmtflags)
unsetf(fmtflags)

Definition at line 209 of file ios.h.

Member Function Documentation

◆ rdstate()

iostate streams::ios_base::rdstate ( ) const
inline

Return the current stream error state.

Definition at line 81 of file ios.h.

◆ setstate()

void streams::ios_base::setstate ( iostate  state)
inline

Set the stream error flags state in addition to currently set flags.

Essentially calls clear(rdstate() | state).

Definition at line 90 of file ios.h.

◆ clear()

void streams::ios_base::clear ( iostate  state = goodbit)
inline

Set the stream error state flags by assigning them the value of state.

By default, assigns ios::goodbit which has the effect of clearing all error state flags.

Definition at line 100 of file ios.h.

◆ good()

bool streams::ios_base::good ( ) const
inline
Return values
`true`if the most recent I/O operation on the stream completed successfully.
`false`if any I/O operation has failed since last call to ios::clear().
See also
rdstate()
goodbit
clear()

Definition at line 114 of file ios.h.

◆ eof()

bool streams::ios_base::eof ( ) const
inline

Return true if the associated stream has reached end-of-file.

Specifically, returns true if ios::eofbit is set in rdstate().

See also
rdstate()
eofbit

Definition at line 125 of file ios.h.

◆ fail()

bool streams::ios_base::fail ( ) const
inline

Return true if an error has occurred on the associated stream, since last time state was reset (clear() was called).

Specifically, returns true if ios::badbit or ios::failbit is set in rdstate().

See also
rdstate()
failbit
badbit
clear()

Definition at line 140 of file ios.h.

◆ bad()

bool streams::ios_base::bad ( ) const
inline

Return true if a non-recoverable error has occurred on the associated stream.

Specifically, returns true if ios::badbit is set in rdstate().

See also
rdstate()
badbit

Definition at line 152 of file ios.h.

◆ operator!()

bool streams::ios_base::operator! ( ) const
inline

Return true if an error has occurred on the associated stream, since last time state was reset (clear() was called).

Actually, this is equivalent to calling fail().

See also
fail()

Definition at line 163 of file ios.h.

◆ operator bool()

streams::ios_base::operator bool ( ) const
inlineexplicit

Check that the current stream has no errors.

Returns true if the stream has no errors and is ready for I/O operations.

See also
fail()

Definition at line 173 of file ios.h.

◆ flags() [1/2]

void streams::ios_base::flags ( fmtflags  flags)
inline

Set new format flags for this stream.

See also
fmtflags

Definition at line 287 of file ios.h.

◆ flags() [2/2]

fmtflags streams::ios_base::flags ( ) const
inline

Return the format flags currently selected in this stream.

See also
fmtflags

Definition at line 296 of file ios.h.

◆ setf() [1/2]

void streams::ios_base::setf ( fmtflags  flags)
inline

Set this stream's format flags whose bits are set in flags, leaving unchanged the rest.

This is equivalent to flags(flags | flags());.

This method is used to set independent flags.

See also
fmtflags
setf(fmtflags, fmtflags)
flags(fmtflags)

Definition at line 312 of file ios.h.

◆ setf() [2/2]

void streams::ios_base::setf ( fmtflags  flags,
fmtflags  mask 
)
inline

Set this stream's format flags whose bits are set in both flags and mask, and clears the format flags whose bits are set in mask but not in flags.

This is equivalent to flags((flags & mask) | (flags() & ~mask));.

This method is used to set a value for one of a group of related flags, using one of the field bitmasks as the mask argument:

flags mask
left, right adjustfield
dec, bin, oct, hex basefield
scientific, fixed floatfield
See also
fmtflags
setf(fmtflags)
flags(fmtflags)

Definition at line 335 of file ios.h.

◆ unsetf()

void streams::ios_base::unsetf ( fmtflags  flags)
inline

Clear this stream's format flags whose bits are set in flags.

See also
fmtflags
setf(fmtflags)
flags(fmtflags)

Definition at line 346 of file ios.h.

◆ fill() [1/2]

char streams::ios_base::fill ( ) const
inline

Return the fill character.

The fill character is the character used by output insertion functions to fill spaces when padding results to the field width. Default fill character is a space.

See also
width()

Definition at line 358 of file ios.h.

◆ fill() [2/2]

void streams::ios_base::fill ( char  fill)
inline

Set fill as new fill character for this stream.

The fill character is the character used by output insertion functions to fill spaces when padding results to the field width.

See also
width()

Definition at line 369 of file ios.h.

◆ width() [1/2]

void streams::ios_base::width ( uint8_t  width)
inline

Set minimum width used for displaying values.

If a value's representation needs less than width characters for display, then additional characters will be added before or after the value. The filler character is determined by fill(), a space by default. Padding side is determined by flags(): left or right. Note that if the value representation needs more than width characters, then width will have no effect on display.

Parameters
widththe new width to use for next formatted output
See also
fill(char)
flags(fmtflags)
left
right

Definition at line 390 of file ios.h.

◆ width() [2/2]

uint8_t streams::ios_base::width ( ) const
inline

Get the current minimum width value (default = 0) used for formatted output.

Returns
current minimum width

Definition at line 400 of file ios.h.

◆ precision() [1/2]

void streams::ios_base::precision ( uint8_t  precision)
inline

Set precision (number of digits after decimal point) used for displaying floating values.

Parameters
precisionthe new precision for next formatted output

Definition at line 411 of file ios.h.

◆ precision() [2/2]

uint8_t streams::ios_base::precision ( ) const
inline

Get the current precision (default = 6) used for formatted floating values output.

Returns
current precision

Definition at line 421 of file ios.h.

◆ copyfmt()

ios_base & streams::ios_base::copyfmt ( const ios_base rhs)
inline

Copy formatting information from rhs to this stream.

Formatting information is:

Definition at line 434 of file ios.h.

Member Data Documentation

◆ eofbit

constexpr iostate streams::ios_base::eofbit = 0x01
staticconstexpr

This bit is set if the stream has unexpectedly reached its end during an extraction.

Note that this bit is currently never set by istreambuf, as istreambuf is blocked until characters are input.

Definition at line 64 of file ios.h.

◆ failbit

constexpr iostate streams::ios_base::failbit = 0x02
staticconstexpr

This bit is set when an input or operation failed due to a formatting error during extraction.

Definition at line 69 of file ios.h.

◆ badbit

constexpr iostate streams::ios_base::badbit = 0x04
staticconstexpr

This bit is set when an irrecoverable stream error has occurred, e.g.

if an overflow occurs when writing to ostreambuf.

Definition at line 74 of file ios.h.

◆ goodbit

constexpr iostate streams::ios_base::goodbit = 0
staticconstexpr

No error; always 0.

Definition at line 76 of file ios.h.

◆ dec

constexpr fmtflags streams::ios_base::dec = 0x0001
staticconstexpr

Read or write integral values using decimal (0..9) base format.

Definition at line 212 of file ios.h.

◆ bin

constexpr fmtflags streams::ios_base::bin = 0x0002
staticconstexpr

Read or write integral values using binary (0,1) base format.

Definition at line 214 of file ios.h.

◆ oct

constexpr fmtflags streams::ios_base::oct = 0x0004
staticconstexpr

Read or write integral values using octal (0..7) base format.

Definition at line 216 of file ios.h.

◆ hex

constexpr fmtflags streams::ios_base::hex = 0x0008
staticconstexpr

Read or write integral values using hexadecimal (0..9,A..F) base format.

Definition at line 218 of file ios.h.

◆ basefield

constexpr fmtflags streams::ios_base::basefield = dec | bin | oct | hex
staticconstexpr

Bitmask constant used with setf(fmtflags, fmtflags) when changing the output base format.

See also
dec
bin
oct
hex

Definition at line 227 of file ios.h.

◆ left

constexpr fmtflags streams::ios_base::left = 0x0010
staticconstexpr

Pad all output to width() characters, with fill() character appended at the end so that the output appears left-adjusted.

Definition at line 233 of file ios.h.

◆ right

constexpr fmtflags streams::ios_base::right = 0x0020
staticconstexpr

Pad all output to width() characters, with fill() character added at the beginning so that the output appears right-adjusted.

Definition at line 238 of file ios.h.

◆ adjustfield

constexpr fmtflags streams::ios_base::adjustfield = left | right
staticconstexpr

Bitmask constant used with setf(fmtflags, fmtflags) when changing the output adjustment.

See also
left
right

Definition at line 245 of file ios.h.

◆ scientific

constexpr fmtflags streams::ios_base::scientific = 0x0040
staticconstexpr

Write floating point values in fixed-point notation.

Definition at line 248 of file ios.h.

◆ fixed

constexpr fmtflags streams::ios_base::fixed = 0x0080
staticconstexpr

Write floating point values in scientific notation.

Definition at line 250 of file ios.h.

◆ floatfield

constexpr fmtflags streams::ios_base::floatfield = scientific | fixed
staticconstexpr

Bitmask constant used with setf(fmtflags, fmtflags) when changing the floating point output representation.

See also
fixed
scientific

Definition at line 257 of file ios.h.

◆ boolalpha

constexpr fmtflags streams::ios_base::boolalpha = 0x0200
staticconstexpr

Read or write bool values as alphabetic string (true or false).

Definition at line 260 of file ios.h.

◆ showbase

constexpr fmtflags streams::ios_base::showbase = 0x0400
staticconstexpr

Write integral values prefixed by their base:

  • decimal: no prefix
  • binary: 0b prefix
  • octal: 0 prefix
  • hexadecimal: 0x prefix

Definition at line 268 of file ios.h.

◆ showpos

constexpr fmtflags streams::ios_base::showpos = 0x1000
staticconstexpr

Write non-negative numerical values preceded by +.

Definition at line 270 of file ios.h.

◆ skipws

constexpr fmtflags streams::ios_base::skipws = 0x2000
staticconstexpr

Skip leading spaces on certain extraction (read) operations.

Definition at line 272 of file ios.h.

◆ unitbuf

constexpr fmtflags streams::ios_base::unitbuf = 0x4000
staticconstexpr

Flush output after each insertion operation.

Definition at line 274 of file ios.h.

◆ uppercase

constexpr fmtflags streams::ios_base::uppercase = 0x8000U
staticconstexpr

Write uppercase letters instead of lowercase in certain insertion operations.

This applies to hexadecimal letters when writing integral numbers and exponent letter when writing floating point numbers. Base prefixes (0x or 0b) are not affected.

Definition at line 281 of file ios.h.

◆ MAX_PRECISION

constexpr uint8_t streams::ios_base::MAX_PRECISION = 16
staticconstexpr

The maximum allowed precision.

See also
precision()

Definition at line 447 of file ios.h.


The documentation for this class was generated from the following file: