MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::io::Writer< Impl > Struct Template Reference

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...

#include <writer.hpp>

Collaboration diagram for mtcore::io::Writer< Impl >:

Public Types

using WriteElem = typename Impl::WriteElem
 
using ErrType = typename Impl::ErrType
 

Public Member Functions

Result< size_t, ErrTypewrite (const Slice< std::remove_const_t< WriteElem > > &s)
 Will write as much of a Slice as possible.
 
Result< size_t, ErrTypewrite (const Slice< std::add_const_t< WriteElem > > &s)
 Will write as much of a Slice as possible.
 
Result< size_t, ErrTypewrite (const std::remove_const_t< WriteElem > &one)
 Will write a single element If there is no room, will return the error OUT_OF_ROOM.
 
Result< void, ErrTypeflush ()
 Flushes a writer (i.e.
 
void deinit (Allocator &allocator)
 Cleans up any memory stuff Only usable if the underlying writer has a deinit that takes an allocator.
 
void deinit ()
 Cleans up writer Only usable if the underlying writer has a deinit that takes an allocator.
 
size_t bytes_written () const
 Gets the number of bytes written.
 
Result< size_t, ErrTypewrite_all (const Slice< std::remove_const_t< WriteElem > > &s)
 Will write all the elements in a Slice If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.
 
size_t bytes_written () const
 
auto written () const
 
void reset ()
 
Result< size_t, ErrTypewrite_all (const Slice< std::add_const_t< WriteElem > > &s)
 Will write all the elements in a Slice If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.
 
Result< void, ErrTypewrite_n_times (const Slice< std::remove_const_t< WriteElem > > &s, size_t n)
 Will write all the elements in a Slice N times If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.
 
Result< size_t, ErrTypewrite_n_times (const Slice< std::add_const_t< WriteElem > > &s, size_t n)
 Will write all the elements in a Slice N times If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.
 
Result< size_t, ErrTypewrite_n_times (const std::remove_const_t< WriteElem > &one, size_t n)
 Will write a single element N times If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.
 

Public Attributes

Impl underlying
 

Detailed Description

template<WriterImpl Impl>
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.

Template Parameters
ImplWriter Implementation (
See also
WriterImpl concept)

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

Member Typedef Documentation

◆ ErrType

template<WriterImpl Impl>
using mtcore::io::Writer< Impl >::ErrType = typename Impl::ErrType

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

◆ WriteElem

template<WriterImpl Impl>
using mtcore::io::Writer< Impl >::WriteElem = typename Impl::WriteElem

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

Member Function Documentation

◆ bytes_written() [1/2]

template<WriterImpl Impl>
size_t mtcore::io::Writer< Impl >::bytes_written ( ) const
inlinenodiscard

Gets the number of bytes written.

Returns
The amount of bytes written

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

118{ return underlying.bytes_written(); }

◆ bytes_written() [2/2]

template<WriterImpl Impl>
size_t mtcore::io::Writer< Impl >::bytes_written ( ) const
inlinenodiscard
Returns
Number of bytes written if able to

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

136 {
137 return underlying.bytes_written();
138 }

◆ deinit() [1/2]

template<WriterImpl Impl>
void mtcore::io::Writer< Impl >::deinit ( )
inline

Cleans up writer Only usable if the underlying writer has a deinit that takes an allocator.

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

110 {
111 underlying.deinit();
112 }

◆ deinit() [2/2]

template<WriterImpl Impl>
void mtcore::io::Writer< Impl >::deinit ( Allocator & allocator)
inline

Cleans up any memory stuff Only usable if the underlying writer has a deinit that takes an allocator.

Parameters
allocatorAllocator for any possible memory-related cleanup

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

100 {
101 underlying.deinit(allocator);
102 }
A writer that writes data to some sort of stream or buffer Note: the data elements written should be ...
Definition io/writer.hpp:51

◆ flush()

template<WriterImpl Impl>
Result< void, ErrType > mtcore::io::Writer< Impl >::flush ( )
inline

Flushes a writer (i.e.

send any buffered output if possible)

Returns
success or error

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

86 {
87 if constexpr (is_flushable<Impl>) {
88 return underlying.flush();
89 }
90 return success();
91 }
Success< void > success()
Creates a successful void Result object.
Definition result.hpp:398
Here is the call graph for this function:

◆ reset()

template<WriterImpl Impl>
void mtcore::io::Writer< Impl >::reset ( )
inline

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

148 {
149 underlying.reset();
150 }

◆ write() [1/3]

template<WriterImpl Impl>
Result< size_t, ErrType > mtcore::io::Writer< Impl >::write ( const Slice< std::add_const_t< WriteElem > > & s)
inline

Will write as much of a Slice as possible.

Parameters
sSlice to write
Returns
Number of elements written, or an error

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

69{ return underlying.write(s); }

◆ write() [2/3]

template<WriterImpl Impl>
Result< size_t, ErrType > mtcore::io::Writer< Impl >::write ( const Slice< std::remove_const_t< WriteElem > > & s)
inline

Will write as much of a Slice as possible.

Parameters
sSlice to write
Returns
Number of elements written, or an error

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

62{ return write(s.to_const()); }
Result< size_t, ErrType > write(const Slice< std::remove_const_t< WriteElem > > &s)
Will write as much of a Slice as possible.
Definition io/writer.hpp:62
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [3/3]

template<WriterImpl Impl>
Result< size_t, ErrType > mtcore::io::Writer< Impl >::write ( const std::remove_const_t< WriteElem > & one)
inline

Will write a single element If there is no room, will return the error OUT_OF_ROOM.

Parameters
oneElement to write
Returns
success or error

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

77 {
79 return write_all(s);
80 }
Result< size_t, ErrType > write_all(const Slice< std::remove_const_t< WriteElem > > &s)
Will write all the elements in a Slice If there is no room, will return the error OUT_OF_ROOM Note: M...
Here is the call graph for this function:

◆ write_all() [1/2]

template<WriterImpl Impl>
Result< size_t, ErrType > mtcore::io::Writer< Impl >::write_all ( const Slice< std::add_const_t< WriteElem > > & s)
inline

Will write all the elements in a Slice If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.

Parameters
sElement to write
Returns
success or error

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

159 {
160 auto r = underlying.write(s);
161 if (r.is_error()) {
162 return r.error();
163 }
164 // if we're dealing with a write-through writer, we have to rely on the final check in the stack
165 // as there will be transformations, so we can't check for out of room here
166 if constexpr (!is_write_through<Impl>) {
167 if (r.value() != s.size()) {
169 }
170 }
171 return success(r.value());
172 }
Error< Underlying > error(Underlying err)
Creates an error.
Definition result.hpp:425
Here is the call graph for this function:

◆ write_all() [2/2]

template<WriterImpl Impl>
Result< size_t, ErrType > mtcore::io::Writer< Impl >::write_all ( const Slice< std::remove_const_t< WriteElem > > & s)
inline

Will write all the elements in a Slice If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.

Parameters
sElement to write
Returns
success or error

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

127 {
128 return write_all(s.to_const());
129 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_n_times() [1/3]

template<WriterImpl Impl>
Result< size_t, ErrType > mtcore::io::Writer< Impl >::write_n_times ( const Slice< std::add_const_t< WriteElem > > & s,
size_t n )
inline

Will write all the elements in a Slice N times If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.

Parameters
sElement to write
nNumber of times to write the Slice
Returns
success or error

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

194 {
195 for (size_t i = 0; i < n; ++i) {
196 auto r = write_all(s);
197 if (r.is_error()) {
198 return r.error();
199 }
200 }
201 return success(n);
202 }
Here is the call graph for this function:

◆ write_n_times() [2/3]

template<WriterImpl Impl>
Result< void, ErrType > mtcore::io::Writer< Impl >::write_n_times ( const Slice< std::remove_const_t< WriteElem > > & s,
size_t n )
inline

Will write all the elements in a Slice N times If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.

Parameters
sElement to write
nNumber of times to write the Slice
Returns
success or error

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

182 {
183 return write_n_times(s.to_const(), n);
184 }
Result< void, ErrType > write_n_times(const Slice< std::remove_const_t< WriteElem > > &s, size_t n)
Will write all the elements in a Slice N times If there is no room, will return the error OUT_OF_ROOM...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_n_times() [3/3]

template<WriterImpl Impl>
Result< size_t, ErrType > mtcore::io::Writer< Impl >::write_n_times ( const std::remove_const_t< WriteElem > & one,
size_t n )
inline

Will write a single element N times If there is no room, will return the error OUT_OF_ROOM Note: May Result in a partial write to the output stream.

Parameters
oneElement to write
nNumber of times to write the Slice
Returns
success or error

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

212 {
214 for (size_t i = 0; i < n; ++i) {
215 auto r = write_all(s);
216 if (r.is_error()) {
217 return r.error();
218 }
219 }
220 return success(n);
221 }
Here is the call graph for this function:

◆ written()

template<WriterImpl Impl>
auto mtcore::io::Writer< Impl >::written ( ) const
inlinenodiscard

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

142 {
143 return underlying.written();
144 }

Member Data Documentation

◆ underlying

template<WriterImpl Impl>
Impl mtcore::io::Writer< Impl >::underlying

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


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