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

Defines C++-like streams API, based on circular buffers for input or output. More...

Classes

class  ios_base
 Base class for formatted streams. More...
 
class  istream
 Input stream wrapper to provide formatted input API, a la C++. More...
 
class  istreambuf
 Input API based on a ring buffer. More...
 
class  null_ostream
 Implements an empty formatted output that does nothing. More...
 
class  ostream
 Output stream wrapper to provide formatted output API, a la C++. More...
 
class  ostreambuf
 Output API based on a ring buffer. More...
 

Typedefs

using ios = ios_base
 Alias for ios_base, allowing to write shorter code, eg ios::eofbit. More...
 

Functions

constexpr const setw_ setw (uint8_t width)
 Set the field width to be used on output (and some input) operations. More...
 
constexpr const setprecision_ setprecision (uint8_t precision)
 Set the decimal precision to be used to format floating-point values on output operations. More...
 
constexpr const setbase_ setbase (int base)
 Set the ios::basefield to one of its possible values (ios::dec, ios::bin, ios::oct or ios::hex) according to base, which must be one of 10, 2, 8 or 16. More...
 
constexpr const setfill_ setfill (char fill)
 Set a new fill character. More...
 
constexpr const setiosflags_ setiosflags (ios::fmtflags mask)
 Set the format flags specified by mask. More...
 
constexpr const resetiosflags_ resetiosflags (ios::fmtflags mask)
 Unset the format flags specified by mask. More...
 
template<typename FSTREAM >
void skipws (FSTREAM &stream)
 Manipulator for an input stream, which will activate whitespace discarding before formatted input operations on that stream. More...
 
template<typename FSTREAM >
void noskipws (FSTREAM &stream)
 Manipulator for an input stream, which will deactivate whitespace discarding before formatted input operations on that stream. More...
 
template<typename FSTREAM >
void bin (FSTREAM &stream)
 Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to binary. More...
 
template<typename FSTREAM >
void oct (FSTREAM &stream)
 Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to octal. More...
 
template<typename FSTREAM >
void dec (FSTREAM &stream)
 Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to decimal. More...
 
template<typename FSTREAM >
void hex (FSTREAM &stream)
 Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to hexadecimal. More...
 
template<typename FSTREAM >
void boolalpha (FSTREAM &stream)
 Set the ios::boolalpha format flag for stream. More...
 
template<typename FSTREAM >
void noboolalpha (FSTREAM &stream)
 Clear the ios::boolalpha format flag for stream. More...
 
template<typename FSTREAM >
void showbase (FSTREAM &stream)
 Set the ios::showbase format flag for stream. More...
 
template<typename FSTREAM >
void noshowbase (FSTREAM &stream)
 Clear the ios::showbase format flag for stream. More...
 
template<typename FSTREAM >
void showpos (FSTREAM &stream)
 Set the ios::showpos format flag for stream. More...
 
template<typename FSTREAM >
void noshowpos (FSTREAM &stream)
 Clear the ios::showpos format flag for stream. More...
 
template<typename FSTREAM >
void uppercase (FSTREAM &stream)
 Set the ios::uppercase format flag for stream. More...
 
template<typename FSTREAM >
void nouppercase (FSTREAM &stream)
 Clear the ios::uppercase format flag for stream. More...
 
template<typename FSTREAM >
void unitbuf (FSTREAM &stream)
 Set the ios::unitbuf format flag for stream. More...
 
template<typename FSTREAM >
void nounitbuf (FSTREAM &stream)
 Clear the ios::unitbuf format flag for stream. More...
 
template<typename FSTREAM >
void left (FSTREAM &stream)
 Set the ios::adjustfield format flag for stream to ios::left, thus adjusting next output to the left. More...
 
template<typename FSTREAM >
void right (FSTREAM &stream)
 Set the ios::adjustfield format flag for stream to ios::right, thus adjusting next output to the right. More...
 
template<typename FSTREAM >
void defaultfloat (FSTREAM &stream)
 Set the ios::floatfield format flag for stream to ios::defaultfloat. More...
 
template<typename FSTREAM >
void fixed (FSTREAM &stream)
 Set the ios::floatfield format flag for stream to ios::fixed. More...
 
template<typename FSTREAM >
void scientific (FSTREAM &stream)
 Set the ios::floatfield format flag for stream to ios::scientific. More...
 
template<typename FSTREAM >
void ws (FSTREAM &stream)
 Manipulator for an input stream, which will swallow all white spaces from that stream. More...
 
template<typename FSTREAM >
void flush (FSTREAM &stream)
 Manipulator for an output stream, which will flush the stream buffer. More...
 
template<typename FSTREAM >
void endl (FSTREAM &stream)
 Manipulator for an output stream, which will insert a new-line character and flush the stream buffer. More...
 

Detailed Description

Defines C++-like streams API, based on circular buffers for input or output.

Typical usage of an output "stream":

const uint8_t BUFFER_SIZE;
char buffer[BUFFER_SIZE];
ostreambuf raw_out{buffer};
ostream out{raw_out};
out << "Hello, World!\n" << flush;
out << hex << 123 << dec << 123 << endl;
Output stream wrapper to provide formatted output API, a la C++.
Definition: streams.h:61
Output API based on a ring buffer.
Definition: streambuf.h:96
void flush(FSTREAM &stream)
Manipulator for an output stream, which will flush the stream buffer.
Definition: streams.h:716
void endl(FSTREAM &stream)
Manipulator for an output stream, which will insert a new-line character and flush the stream buffer.
Definition: streams.h:725
void hex(FSTREAM &stream)
Manipulator for an output or input stream, which will set the base, used to represent (output) or int...
Definition: ios.h:774
void dec(FSTREAM &stream)
Manipulator for an output or input stream, which will set the base, used to represent (output) or int...
Definition: ios.h:765

Note that these streams are generally created for you by higher level API, such as serial::hard::UART and similar classes.

See also
serial::hard
serial::soft

Typedef Documentation

◆ ios

using streams::ios = typedef ios_base

Alias for ios_base, allowing to write shorter code, eg ios::eofbit.

Definition at line 723 of file ios.h.

Function Documentation

◆ setw()

constexpr const setw_ streams::setw ( uint8_t  width)
constexpr

Set the field width to be used on output (and some input) operations.

This method should only be used as a stream manipulator.

The folowing example displays 123 right-aligned on 10 positions, i.e. with 7 fill characters prepended:

out << setw(10) << dec << right << 123 << endl;
void right(FSTREAM &stream)
Set the ios::adjustfield format flag for stream to ios::right, thus adjusting next output to the righ...
Definition: ios.h:948
constexpr const setw_ setw(uint8_t width)
Set the field width to be used on output (and some input) operations.
Definition: iomanip.h:195

Note that setw() is effective only for one input or output operation, and thus must be called before each operation.

Definition at line 195 of file iomanip.h.

◆ setprecision()

constexpr const setprecision_ streams::setprecision ( uint8_t  precision)
constexpr

Set the decimal precision to be used to format floating-point values on output operations.

This method should only be used as a stream manipulator.

The folowing example displays 123.456789 with various precision, i.e. various number of decimals afeter the decimal point:

out << setprecision(2) << 123.456789 << endl;
out << setprecision(4) << 123.456789 << endl;
out << setprecision(6) << 123.456789 << endl;
out << setprecision(8) << 123.456789 << endl;
constexpr const setprecision_ setprecision(uint8_t precision)
Set the decimal precision to be used to format floating-point values on output operations.
Definition: iomanip.h:214

Definition at line 214 of file iomanip.h.

◆ setbase()

constexpr const setbase_ streams::setbase ( int  base)
constexpr

Set the ios::basefield to one of its possible values (ios::dec, ios::bin, ios::oct or ios::hex) according to base, which must be one of 10, 2, 8 or 16.

This method should only be used as a stream manipulator.

The folowing example displays 123 under all available bases:

out << setbase(10) << 123 << endl;
out << setbase(2) << 123 << endl;
out << setbase(8) << 123 << endl;
out << setbase(16) << 123 << endl;
constexpr const setbase_ setbase(int base)
Set the ios::basefield to one of its possible values (ios::dec, ios::bin, ios::oct or ios::hex) accor...
Definition: iomanip.h:238

Note that it is generally preferrable to use the other manipulators.

See also
dec()
bin()
oct()
hex()

Definition at line 238 of file iomanip.h.

◆ setfill()

constexpr const setfill_ streams::setfill ( char  fill)
constexpr

Set a new fill character.

This method should only be used as a stream manipulator.

The following example displays 123 in hexadecimal form on 4 positions, padded with 0 if necessary:

out << setfill(`0`) << setw(4) << hex << right << 123 << endl;
constexpr const setfill_ setfill(char fill)
Set a new fill character.
Definition: iomanip.h:253

Definition at line 253 of file iomanip.h.

◆ setiosflags()

constexpr const setiosflags_ streams::setiosflags ( ios::fmtflags  mask)
constexpr

Set the format flags specified by mask.

This method should only be used as a stream manipulator.

Behaves as if ios::setf was called with mask as argument, on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams). See ios::fmtflags for more information on the particular flags that can be modified with this manipulator function.

See also
ios::fmtflags
ios::setf()

Definition at line 270 of file iomanip.h.

◆ resetiosflags()

constexpr const resetiosflags_ streams::resetiosflags ( ios::fmtflags  mask)
constexpr

Unset the format flags specified by mask.

This method should only be used as a stream manipulator.

Behaves as if ios::unsetf was called with mask as argument, on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams). See ios::fmtflags for more information on the particular flags that can be modified with this manipulator function.

See also
ios::fmtflags
ios::unsetf()

Definition at line 287 of file iomanip.h.

◆ skipws()

template<typename FSTREAM >
void streams::skipws ( FSTREAM &  stream)
inline

Manipulator for an input stream, which will activate whitespace discarding before formatted input operations on that stream.

Definition at line 729 of file ios.h.

◆ noskipws()

template<typename FSTREAM >
void streams::noskipws ( FSTREAM &  stream)
inline

Manipulator for an input stream, which will deactivate whitespace discarding before formatted input operations on that stream.

Definition at line 738 of file ios.h.

◆ bin()

template<typename FSTREAM >
void streams::bin ( FSTREAM &  stream)
inline

Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to binary.

Definition at line 747 of file ios.h.

◆ oct()

template<typename FSTREAM >
void streams::oct ( FSTREAM &  stream)
inline

Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to octal.

Definition at line 756 of file ios.h.

◆ dec()

template<typename FSTREAM >
void streams::dec ( FSTREAM &  stream)
inline

Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to decimal.

Definition at line 765 of file ios.h.

◆ hex()

template<typename FSTREAM >
void streams::hex ( FSTREAM &  stream)
inline

Manipulator for an output or input stream, which will set the base, used to represent (output) or interpret (input) integral numerical values, to hexadecimal.

Definition at line 774 of file ios.h.

◆ boolalpha()

template<typename FSTREAM >
void streams::boolalpha ( FSTREAM &  stream)
inline

Set the ios::boolalpha format flag for stream.

When the boolalpha format flag is set, bool values are inserted/extracted by their textual representation: either true or false, instead of integral values.

This flag can be unset with the noboolalpha manipulator.

See also
noboolalpha

Definition at line 788 of file ios.h.

◆ noboolalpha()

template<typename FSTREAM >
void streams::noboolalpha ( FSTREAM &  stream)
inline

Clear the ios::boolalpha format flag for stream.

When the boolalpha format flag is not set, bool values are inserted/extracted as integral values (0 and 1) instead of their textual representations: true or false. This flag can be set with the boolalpha manipulator.

See also
boolalpha

Definition at line 801 of file ios.h.

◆ showbase()

template<typename FSTREAM >
void streams::showbase ( FSTREAM &  stream)
inline

Set the ios::showbase format flag for stream.

When the showbase format flag is set, numerical integer values inserted into output streams are prefixed with the same prefixes used by C++ literal constants: 0x for hexadecimal values (see hex), 0 for octal values (see oct), 0b for binary values (see bin) and no prefix for decimal-base values (see dec).

This option can be unset with the noshowbase manipulator.

See also
noshowbase
dec
hex
oct
bin

Definition at line 821 of file ios.h.

◆ noshowbase()

template<typename FSTREAM >
void streams::noshowbase ( FSTREAM &  stream)
inline

Clear the ios::showbase format flag for stream.

When the showbase format flag is not set, numerical integer values are inserted into stream without prefixing them with any numerical base prefix (i.e. 0x for hexadecimal values, 0 for octal values, 0b for binary values and no prefix for decimal-base values).

This option can be set with the showbase manipulator.

See also
showbase

Definition at line 836 of file ios.h.

◆ showpos()

template<typename FSTREAM >
void streams::showpos ( FSTREAM &  stream)
inline

Set the ios::showpos format flag for stream.

When the showpos format flag is set, a plus sign (+) precedes every non-negative numerical value inserted into stream (including zeros).

This flag can be unset with the noshowpos manipulator.

See also
noshowpos

Definition at line 849 of file ios.h.

◆ noshowpos()

template<typename FSTREAM >
void streams::noshowpos ( FSTREAM &  stream)
inline

Clear the ios::showpos format flag for stream.

When the showpos format flag is not set, no plus signs precede positive values inserted into stream.

This flag can be set with the noshowpos manipulator.

See also
showpos

Definition at line 862 of file ios.h.

◆ uppercase()

template<typename FSTREAM >
void streams::uppercase ( FSTREAM &  stream)
inline

Set the ios::uppercase format flag for stream.

When the uppercase format flag is set, uppercase (capital) letters are used instead of lowercase for representations on output operations involving stream-generated letters, like hexadecimal representations.

This flag can be unset with the nouppercase manipulator, not forcing the use of uppercase for generated letters.

See also
nouppercase

Definition at line 877 of file ios.h.

◆ nouppercase()

template<typename FSTREAM >
void streams::nouppercase ( FSTREAM &  stream)
inline

Clear the ios::uppercase format flag for stream.

When the uppercase format flag is notset, the letters automatically generated by stream for certain representations (like hexadecimal representations) are displayed as lwoercase.

This flag can be set with the uppercase manipulator, forcing the use of uppercase for generated letters.

See also
uppercase

Definition at line 892 of file ios.h.

◆ unitbuf()

template<typename FSTREAM >
void streams::unitbuf ( FSTREAM &  stream)
inline

Set the ios::unitbuf format flag for stream.

When the unitbuf flag is set, the associated buffer is flushed after each insertion operation.

This flag can be unset with the nounitbuf manipulator, not forcing flushes after every insertion.

See also
nounitbuf

Definition at line 906 of file ios.h.

◆ nounitbuf()

template<typename FSTREAM >
void streams::nounitbuf ( FSTREAM &  stream)
inline

Clear the ios::unitbuf format flag for stream.

When the unitbuf flag is not set, the associated buffer is not forced to be flushed after every insertion operation. With this mode, you can force buffer flush any time by using flush manipulator, or using endl which will output a new line follwoed by a buffer flush.

This flag can be set with the unitbuf manipulator, forcing flushes after every insertion.

See also
unitbuf

Definition at line 922 of file ios.h.

◆ left()

template<typename FSTREAM >
void streams::left ( FSTREAM &  stream)
inline

Set the ios::adjustfield format flag for stream to ios::left, thus adjusting next output to the left.

When adjustfield is set to left, the output is padded to the field width (ios::width()) by inserting fill characters (ios::fill()) at the end, effectively adjusting the field to the left.

See also
right

Definition at line 935 of file ios.h.

◆ right()

template<typename FSTREAM >
void streams::right ( FSTREAM &  stream)
inline

Set the ios::adjustfield format flag for stream to ios::right, thus adjusting next output to the right.

When adjustfield is set to right, the output is padded to the field width (ios::width()) by inserting fill characters (ios::fill()) at the beginning, effectively adjusting the field to the right.

See also
left

Definition at line 948 of file ios.h.

◆ defaultfloat()

template<typename FSTREAM >
void streams::defaultfloat ( FSTREAM &  stream)
inline

Set the ios::floatfield format flag for stream to ios::defaultfloat.

When floatfield is set to defaultfloat, floating-point values are written using the default notation: the representation uses as many meaningful digits as needed up to the stream's decimal precision (ios::precision()), counting both the digits before and after the decimal point (if any).

NOTE: current implementation behaves the same as fixed.

See also
fixed
scientific
ios::precision()
ios::precision(uint8_t)

Definition at line 966 of file ios.h.

◆ fixed()

template<typename FSTREAM >
void streams::fixed ( FSTREAM &  stream)
inline

Set the ios::floatfield format flag for stream to ios::fixed.

When floatfield is set to fixed, floating-point values are written using fixed-point notation: the value is represented with exactly as many digits in the decimal part as specified by the precision field (ios::precision()) and with no exponent part.

See also
defaultfloat
scientific
ios::precision()
ios::precision(uint8_t)

Definition at line 982 of file ios.h.

◆ scientific()

template<typename FSTREAM >
void streams::scientific ( FSTREAM &  stream)
inline

Set the ios::floatfield format flag for stream to ios::scientific.

When floatfield is set to scientific, floating-point values are written using scientific notation: the value is represented always with only one digit before the decimal point, followed by the decimal point and as many decimal digits as the precision field (ios::precision()). Finally, this notation always includes an exponential part consisting on the letter e followed by an optional sign and two exponential digits.

See also
defaultfloat
fixed
ios::precision()
ios::precision(uint8_t)

Definition at line 1000 of file ios.h.

◆ ws()

template<typename FSTREAM >
void streams::ws ( FSTREAM &  stream)
inline

Manipulator for an input stream, which will swallow all white spaces from that stream.

The following sample code puts the next non white space character of in into c:

char c;
in >> ws >> c;
void ws(FSTREAM &stream)
Manipulator for an input stream, which will swallow all white spaces from that stream.
Definition: streams.h:708

Definition at line 708 of file streams.h.

◆ flush()

template<typename FSTREAM >
void streams::flush ( FSTREAM &  stream)
inline

Manipulator for an output stream, which will flush the stream buffer.

Definition at line 716 of file streams.h.

◆ endl()

template<typename FSTREAM >
void streams::endl ( FSTREAM &  stream)
inline

Manipulator for an output stream, which will insert a new-line character and flush the stream buffer.

Definition at line 725 of file streams.h.