MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
Writer

Writers for outputing data. More...

Classes

struct  mtcore::io::Writer< Impl >
 A writer that writes data to some sort of stream or buffer Note: the data elements written should be trivially constructible, trivially destructible, and trivially copyable. More...
 

Functions

template<typename T, WriterImpl WI, typename Err = typename io::Writer<WI>::ErrType, typename FuncType = std::function<Result<size_t, Err>(io::Writer<WI> &, Slice<std::add_const_t<T>>)>>
io::Writer< impl::WriteTransformer< T, WI, Err, FuncType > > mtcore::io::write_transformer (io::Writer< WI > &writer, FuncType mapper)
 A specialized writer that will transform input data before passing it through to another writer Useful for things like adding an extra encoding step or for transforming between endianness.
 
template<typename T>
io::Writer< impl::SliceWriterImpl< T > > mtcore::io::slice_writer (Slice< T > out)
 Creates a writer to write to a Slice.
 
template<typename T>
io::Writer< impl::VoidWriterImpl< T > > mtcore::io::void_writer ()
 Creates a writer which discards what's written (think of it as writer to /dev/null) Useful for doing a dry-run of a complicated write pass to get the size of the final content.
 
template<Formattable T>
auto mtcore::io::ostream_writer (std::ostream &os)
 Creates a writer which passes its output to an ostream Useful for compatibility with the C++ standard library.
 
template<WriterImpl WI, typename Arg>
Result< size_t, typename Writer< WI >::ErrType > mtcore::io::format (Writer< WI > &writer, const FormatOptions &opts, Arg arg)
 Generic format function which takes a bunch of arguments (of the same type) and formatting options and then outputs the formatted version of those arguments into the writer.
 

Detailed Description

Writers for outputing data.

Function Documentation

◆ format()

template<WriterImpl WI, typename Arg>
Result< size_t, typename Writer< WI >::ErrType > mtcore::io::format ( Writer< WI > & writer,
const FormatOptions & opts,
Arg arg )

Generic format function which takes a bunch of arguments (of the same type) and formatting options and then outputs the formatted version of those arguments into the writer.

Usually you will call this through print()

See also
mtcore::print
Template Parameters
WIWriter implementation
ArgArgument to format
Parameters
writerwriter to output to
optsFormatting options
argArgumentsto format
Returns
The number of elements written, or an error

Definition at line 444 of file io/writer.hpp.

444 {
445 return Formatter<Arg>::fmt(writer, opts, arg);
446 }
Struct to override to specify how a type should be formatted.
Definition format.hpp:45
Here is the caller graph for this function:

◆ ostream_writer()

template<Formattable T>
auto mtcore::io::ostream_writer ( std::ostream & os)

Creates a writer which passes its output to an ostream Useful for compatibility with the C++ standard library.

Template Parameters
TData type to write
Parameters
osostream to write to

Definition at line 420 of file io/writer.hpp.

420 {
421 return io::Writer<impl::OstreamWriterImpl<T>>{.underlying = impl::OstreamWriterImpl<T>{os}};
422 }
A writer that writes data to some sort of stream or buffer Note: the data elements written should be ...
Definition io/writer.hpp:51
Here is the caller graph for this function:

◆ slice_writer()

template<typename T>
io::Writer< impl::SliceWriterImpl< T > > mtcore::io::slice_writer ( Slice< T > out)

Creates a writer to write to a Slice.

Template Parameters
TData type to write (should be trivially copyable, constructible, and destructible)
Parameters
outSlice to write to
Returns
A writer that writes to the Slice

Definition at line 396 of file io/writer.hpp.

396 {
397 return io::Writer<impl::SliceWriterImpl<T>>{.underlying = impl::SliceWriterImpl<T>{.out = out}};
398 }
Here is the caller graph for this function:

◆ void_writer()

template<typename T>
io::Writer< impl::VoidWriterImpl< T > > mtcore::io::void_writer ( )

Creates a writer which discards what's written (think of it as writer to /dev/null) Useful for doing a dry-run of a complicated write pass to get the size of the final content.

Template Parameters
TData type to write
Returns
A writer that discards input

Definition at line 408 of file io/writer.hpp.

408 {
410 }
Here is the caller graph for this function:

◆ write_transformer()

template<typename T, WriterImpl WI, typename Err = typename io::Writer<WI>::ErrType, typename FuncType = std::function<Result<size_t, Err>(io::Writer<WI> &, Slice<std::add_const_t<T>>)>>
io::Writer< impl::WriteTransformer< T, WI, Err, FuncType > > mtcore::io::write_transformer ( io::Writer< WI > & writer,
FuncType mapper )

A specialized writer that will transform input data before passing it through to another writer Useful for things like adding an extra encoding step or for transforming between endianness.

Template Parameters
TElement type to write into the outermost writer
WIWriter implementation type
ErrError type to be returned from FuncType (defaults to Writer<WI>::ErrType)
FuncTypeFunction type to transform incoming input before passing through to the underlying writer
Parameters
writerUnderlying writer where data will ultimately go
mapperMapper to transform the data and pass it to the underlying writer (or filter it out, or whatever)
Returns
A writer

Definition at line 384 of file io/writer.hpp.

384 {
386 }