libostd
|
A stream system to replace the C++ iostreams. More...
Files | |
file | io.hh |
File streams and standard output/input/error manipulation. | |
file | stream.hh |
A base class for streams plus stream utilities. | |
Classes | |
struct | ostd::file_stream |
A file stream. More... | |
struct | ostd::stream_range< T, bool > |
struct | ostd::stream_error |
Thrown on stream errors. More... | |
struct | ostd::stream_line_range< T, TC > |
A range type for streams to read by line. More... | |
struct | ostd::stream |
A base stream class. More... | |
struct | ostd::stream_range< T, true > |
A range type for streams. More... | |
Typedefs | |
using | ostd::stream_off_t = off_t |
The stream offset type. More... | |
Enumerations | |
enum | ostd::stream_mode { ostd::stream_mode::READ = 0, ostd::stream_mode::WRITE, ostd::stream_mode::APPEND, ostd::stream_mode::READ_U, ostd::stream_mode::WRITE_U, ostd::stream_mode::APPEND_U } |
The mode to open file streams with. More... | |
enum | ostd::stream_seek { ostd::stream_seek::CUR = SEEK_CUR, ostd::stream_seek::END = SEEK_END, ostd::stream_seek::SET = SEEK_SET } |
Reference position for seeking. More... | |
Functions | |
void | ostd::swap (file_stream &a, file_stream &b) |
Swaps two file streams including ownership. | |
template<typename ... A> | |
void | ostd::write (A const &...args) |
Writes all given values into standard output. More... | |
template<typename ... A> | |
void | ostd::writeln (A const &...args) |
Writes all given values into standard output followed by a newline. More... | |
template<typename ... A> | |
void | ostd::writef (string_range fmt, A const &...args) |
Writes a formatted string into standard output. More... | |
template<typename ... A> | |
void | ostd::writefln (string_range fmt, A const &...args) |
Writes a formatted string into standard output followed by a newline. More... | |
template<typename T = char> | |
stream_range< T > | ostd::stream::iter () |
Creates a range around the stream. More... | |
template<typename T = char, typename TC = std::basic_string<T>> | |
stream_line_range< T, TC > | ostd::stream::iter_lines (bool keep_nl=false) |
Creates a by-line range around the stream. More... | |
template<typename ... A> | |
void | ostd::stream::write (A const &...args) |
Writes all given values into the stream. More... | |
template<typename ... A> | |
void | ostd::stream::writef (string_range fmt, A const &...args) |
Writes a formatted string into the stream. More... | |
Variables | |
OSTD_EXPORT file_stream | ostd::cin |
Standard input file stream. | |
OSTD_EXPORT file_stream | ostd::cout |
Standard output file stream. | |
OSTD_EXPORT file_stream | ostd::cerr |
Standard error file stream. | |
A stream system to replace the C++ iostreams.
Libostd provides a custom stream system with considerably simpler API and integration with other libostd features (such as ranges).
Some string examples:
And binary examples:
See the examples provided with the library for further information.
using ostd::stream_off_t = typedef off_t |
The stream offset type.
This is a signed integer type that can represent file sizes and offsets. On POSIX systems, it defaults to the POSIX off_t
type. On Windows, it's a signed 64-bit integer. On other systems it's long
.
|
strong |
The mode to open file streams with.
Libostd file streams are always opened in binary mode. Text mode is not directly supported (the only way to get it is to encapsulate a C FILE *
that is already opened in text mode).
See the C fopen() function documentation for more info on modes.
|
strong |
|
inline |
Creates a range around the stream.
The range stays valid as long as the stream is valid. The range does not own the stream, so you have to track the lifetime correctly.
By default, it's a char
range that can be read from if the stream can be read from and written into if the stream can be written into. You can override the type by passing in the template parameter. The type must always be trivial.
T | The type to use for reading/writing (char by default). |
|
inline |
Creates a by-line range around the stream.
Same lifetime rules as with iter() apply. The range uses get_line() to read the lines.
TC | The string type to use for line storage in the range. |
|
inline |
Writes all given values into standard output.
Behaves the same as calling ostd::stream::write() on ostd::cout, but with more convenience.
|
inline |
Writes all given values into the stream.
There is no separator put between the values. It supports any type that can be formatted using ostd::format_spec with the default s
format specifier. The stream's locale is passed into the formatter.
ostd::stream_error | on write error. |
ostd::format_error | if a value cannot be formatted. |
|
inline |
Writes a formatted string into standard output.
Behaves the same as calling ostd::stream::writef() on ostd::cout, but with more convenience.
|
inline |
Writes a formatted string into the stream.
Given a format string and arguments, this is just like using ostd::format() with this stream as the sink. The stream's locale is passed into the formatter.
ostd::stream_error | on write error. |
ostd::format_error | if the formatting fails. |
|
inline |
Writes a formatted string into standard output followed by a newline.
Behaves the same as calling ostd::stream::writefln() on ostd::cout, but with more convenience.
|
inline |
Writes all given values into standard output followed by a newline.
Behaves the same as calling ostd::stream::writeln() on ostd::cout, but with more convenience.