LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc::FixedBufferWriter Class Reference

#include <BufferWriter.h>

Inheritance diagram for swoc::FixedBufferWriter:
Inheritance graph
Collaboration diagram for swoc::FixedBufferWriter:
Collaboration graph

Public Member Functions

 FixedBufferWriter (char *buffer, size_t capacity)
 
 FixedBufferWriter (MemSpan< void > const &span)
 Construct using the memory span as the buffer.
 
 FixedBufferWriter (MemSpan< char > const &span)
 Construct using the memory span as the buffer.
 
 FixedBufferWriter (std::nullptr_t)
 
 FixedBufferWriter (const FixedBufferWriter &)=delete
 
FixedBufferWriteroperator= (const FixedBufferWriter &)=delete
 
 FixedBufferWriter (FixedBufferWriter &&that)
 Move constructor.
 
FixedBufferWriteroperator= (FixedBufferWriter &&that)
 Move assignment.
 
self_typeassign (MemSpan< char > const &span)
 Reset buffer.
 
FixedBufferWriterwrite (char c) override
 Write a single character c to the buffer.
 
FixedBufferWriterwrite (const void *data, size_t length) override
 Write length bytes, starting at data, to the buffer.
 
const char * data () const override
 Return the output buffer.
 
bool error () const override
 
char * aux_data () override
 
size_t capacity () const override
 Get the total capacity of the output buffer.
 
size_t extent () const override
 Get the total output sent to the writer.
 
bool commit (size_t n) override
 Advance the used part of the output buffer.
 
self_typediscard (size_t n) override
 Drop n characters from the end of the buffer.
 
self_typerestrict (size_t n) override
 Reduce the capacity by n.
 
self_typerestore (size_t n) override
 Restore n bytes of the capacity.
 
FixedBufferWritercopy (size_t dst, size_t src, size_t n) override
 Copy data in the buffer.
 
self_typeclear ()
 
self_typedetach ()
 
swoc::TextView view () const
 
 operator std::string_view () const
 Provide a string_view of all successfully written characters as a user conversion.
 
 operator swoc::TextView () const
 Provide a string_view of all successfully written characters as a user conversion.
 
std::ostream & operator>> (std::ostream &stream) const override
 Output the buffer contents to the stream.
 
BufferWriterwrite (MemSpan< void const > span)
 
- Public Member Functions inherited from swoc::BufferWriter
BufferWriterwrite (MemSpan< void const > span)
 
size_t size () const
 
size_t remaining () const
 
MemSpan< char > aux_span ()
 
template<typename... Args>
BufferWriterprint (const TextView &fmt, Args &&...args)
 
template<typename... Args>
BufferWriterprint_v (const TextView &fmt, const std::tuple< Args... > &args)
 
template<typename... Args>
BufferWriterprint (const bwf::Format &fmt, Args &&...args)
 
template<typename... Args>
BufferWriterprint_v (const bwf::Format &fmt, const std::tuple< Args... > &args)
 
template<typename Binding, typename Extractor>
BufferWriterprint_nfv (Binding &&names, Extractor &&ex, bwf::ArgPack const &args)
 
template<typename Binding, typename Extractor>
BufferWriterprint_nfv (Binding const &names, Extractor &&ex)
 
template<typename Binding>
BufferWriterprint_n (Binding const &names, TextView const &fmt)
 
template<typename T>
BufferWriterformat (bwf::Spec const &spec, T &&t)
 
template<typename T>
BufferWriterformat (bwf::Spec const &spec, T const &t)
 

Protected Member Functions

 FixedBufferWriter (char *buffer, size_t capacity, bool noexcept_flag) noexcept
 

Protected Attributes

char *const _buffer
 Output buffer.
 
size_t _capacity
 Size of output buffer.
 
size_t _attempted = 0
 Number of characters written, including those discarded due error condition.
 

Detailed Description

A concrete BufferWriter class for a fixed buffer.

Definition at line 302 of file BufferWriter.h.

Constructor & Destructor Documentation

◆ FixedBufferWriter() [1/6]

swoc::FixedBufferWriter::FixedBufferWriter ( char * buffer,
size_t capacity )
inline

Construct a buffer writer on a fixed buffer of size capacity.

If writing goes past the end of the buffer, the excess is dropped.

Definition at line 498 of file BufferWriter.h.

◆ FixedBufferWriter() [2/6]

swoc::FixedBufferWriter::FixedBufferWriter ( MemSpan< void > const & span)
inline

Construct using the memory span as the buffer.

Definition at line 507 of file BufferWriter.h.

◆ FixedBufferWriter() [3/6]

swoc::FixedBufferWriter::FixedBufferWriter ( MemSpan< char > const & span)
inline

Construct using the memory span as the buffer.

Definition at line 510 of file BufferWriter.h.

◆ FixedBufferWriter() [4/6]

swoc::FixedBufferWriter::FixedBufferWriter ( std::nullptr_t )
inline

Constructor an empty buffer with no capacity. This can be useful to measure the extent of the output before allocating memory.

Definition at line 512 of file BufferWriter.h.

◆ FixedBufferWriter() [5/6]

swoc::FixedBufferWriter::FixedBufferWriter ( FixedBufferWriter && that)
inline

Move constructor.

Definition at line 522 of file BufferWriter.h.

◆ FixedBufferWriter() [6/6]

swoc::FixedBufferWriter::FixedBufferWriter ( char * buffer,
size_t capacity,
bool noexcept_flag )
inlineprotectednoexcept

Definition at line 504 of file BufferWriter.h.

Member Function Documentation

◆ assign()

FixedBufferWriter::self_type & swoc::FixedBufferWriter::assign ( MemSpan< char > const & span)
inline

Reset buffer.

Definition at line 528 of file BufferWriter.h.

◆ aux_data()

char * swoc::FixedBufferWriter::aux_data ( )
inlineoverridevirtual
Returns
Start of the unused buffer, or nullptr is there is no remaining unwritten space.

Reimplemented from swoc::BufferWriter.

Definition at line 582 of file BufferWriter.h.

◆ capacity()

size_t swoc::FixedBufferWriter::capacity ( ) const
inlineoverridevirtual

Get the total capacity of the output buffer.

Implements swoc::BufferWriter.

Definition at line 594 of file BufferWriter.h.

◆ clear()

auto swoc::FixedBufferWriter::clear ( )
inline

Erase the buffer, reset to empty (no valid data). This is a convenience for reusing a buffer. For instance

bw.clear().print("....."); // clear old data and print new data.

This is equivalent to w.discard(w.size()) but clearer for that case.

Definition at line 627 of file BufferWriter.h.

◆ commit()

bool swoc::FixedBufferWriter::commit ( size_t n)
inlineoverridevirtual

Advance the used part of the output buffer.

Implements swoc::BufferWriter.

Definition at line 587 of file BufferWriter.h.

◆ copy()

auto swoc::FixedBufferWriter::copy ( size_t dst,
size_t src,
size_t n )
inlineoverridevirtual

Copy data in the buffer.

Implements swoc::BufferWriter.

Definition at line 633 of file BufferWriter.h.

◆ data()

const char * swoc::FixedBufferWriter::data ( ) const
inlineoverridevirtual

Return the output buffer.

Returns
The start of the buffer.

Implements swoc::BufferWriter.

Definition at line 572 of file BufferWriter.h.

◆ detach()

FixedBufferWriter::self_type & swoc::FixedBufferWriter::detach ( )
inline

Definition at line 515 of file BufferWriter.h.

◆ discard()

auto swoc::FixedBufferWriter::discard ( size_t n)
inlineoverridevirtual

Drop n characters from the end of the buffer.

Implements swoc::BufferWriter.

Definition at line 621 of file BufferWriter.h.

◆ error()

bool swoc::FixedBufferWriter::error ( ) const
inlineoverridevirtual
Returns
true if output has been discarded, false otherwise.

Implements swoc::BufferWriter.

Definition at line 577 of file BufferWriter.h.

◆ extent()

size_t swoc::FixedBufferWriter::extent ( ) const
inlineoverridevirtual

Get the total output sent to the writer.

Implements swoc::BufferWriter.

Definition at line 599 of file BufferWriter.h.

◆ operator std::string_view()

swoc::FixedBufferWriter::operator std::string_view ( ) const
inline

Provide a string_view of all successfully written characters as a user conversion.

Definition at line 646 of file BufferWriter.h.

◆ operator swoc::TextView()

swoc::FixedBufferWriter::operator swoc::TextView ( ) const
inline

Provide a string_view of all successfully written characters as a user conversion.

Definition at line 650 of file BufferWriter.h.

◆ operator=()

FixedBufferWriter & swoc::FixedBufferWriter::operator= ( FixedBufferWriter && that)
inline

Move assignment.

Definition at line 536 of file BufferWriter.h.

◆ operator>>()

std::ostream & swoc::FixedBufferWriter::operator>> ( std::ostream & stream) const
overridevirtual

Output the buffer contents to the stream.

Implements swoc::BufferWriter.

Definition at line 741 of file bw_format.cc.

◆ restore()

auto swoc::FixedBufferWriter::restore ( size_t n)
inlineoverridevirtual

Restore n bytes of the capacity.

Implements swoc::BufferWriter.

Definition at line 612 of file BufferWriter.h.

◆ restrict()

auto swoc::FixedBufferWriter::restrict ( size_t n)
inlineoverridevirtual

Reduce the capacity by n.

Implements swoc::BufferWriter.

Definition at line 603 of file BufferWriter.h.

◆ view()

swoc::TextView swoc::FixedBufferWriter::view ( ) const
inline
Returns
The used part of the buffer as a std::string_view.

Definition at line 642 of file BufferWriter.h.

◆ write() [1/3]

FixedBufferWriter & swoc::FixedBufferWriter::write ( char c)
inlineoverridevirtual

Write a single character c to the buffer.

Implements swoc::BufferWriter.

Definition at line 545 of file BufferWriter.h.

◆ write() [2/3]

FixedBufferWriter & swoc::FixedBufferWriter::write ( const void * data,
size_t length )
inlineoverridevirtual

Write length bytes, starting at data, to the buffer.

Reimplemented from swoc::BufferWriter.

Definition at line 555 of file BufferWriter.h.

◆ write() [3/3]

BufferWriter & swoc::BufferWriter::write ( MemSpan< void const > span)
inline

Write data to the buffer.

Parameters
spanData source.
Returns
this

Data from span is written directly to the buffer, and clipped to the size of the buffer.

Definition at line 66 of file BufferWriter.h.

Member Data Documentation

◆ _attempted

size_t swoc::FixedBufferWriter::_attempted = 0
protected

Number of characters written, including those discarded due error condition.

Definition at line 414 of file BufferWriter.h.

◆ _buffer

char* const swoc::FixedBufferWriter::_buffer
protected

Output buffer.

Definition at line 412 of file BufferWriter.h.

◆ _capacity

size_t swoc::FixedBufferWriter::_capacity
protected

Size of output buffer.

Definition at line 413 of file BufferWriter.h.


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