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

#include <ArenaWriter.h>

Inheritance diagram for swoc::ArenaWriter:
Inheritance graph
Collaboration diagram for swoc::ArenaWriter:
Collaboration graph

Public Member Functions

 ArenaWriter (MemArena &arena)
 
ArenaWriterwrite (void const *data, size_t n) override
 
ArenaWriterwrite (char c) override
 Write a single character c to the buffer.
 
bool commit (size_t n) override
 
- Public Member Functions inherited from swoc::FixedBufferWriter
 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

void realloc (size_t n)
 
- Protected Member Functions inherited from swoc::FixedBufferWriter
 FixedBufferWriter (char *buffer, size_t capacity, bool noexcept_flag) noexcept
 

Protected Attributes

MemArena_arena
 Arena for the buffer.
 
- Protected Attributes inherited from swoc::FixedBufferWriter
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

Buffer writer for a MemArena.

This provides formatted output to the remnant of a MemArena. The output resides in uncommitted arena memory and must be committed externally. This will resize the remnant as needed to contain the output without overflow. Because it uses the remnant, if there is an error or resizing, no arena memory will be lost.

Definition at line 21 of file ArenaWriter.h.

Constructor & Destructor Documentation

◆ ArenaWriter()

swoc::ArenaWriter::ArenaWriter ( swoc::MemArena & arena)
inline

Constructor.

Parameters
arenaArena to use for storage.

Definition at line 61 of file ArenaWriter.h.

Member Function Documentation

◆ commit()

bool swoc::ArenaWriter::commit ( size_t n)
overridevirtual

Mark bytes as in use.

Parameters
nNumber of bytes to include in the used buffer.
Returns
true if successful, false if additional buffer space was required.

Implements swoc::BufferWriter.

Definition at line 30 of file ArenaWriter.cc.

◆ realloc()

void swoc::ArenaWriter::realloc ( size_t n)
protected

Reallocate the buffer to increase the capacity.

Parameters
nTotal size required.

Definition at line 39 of file ArenaWriter.cc.

◆ write() [1/2]

ArenaWriter & swoc::ArenaWriter::write ( char c)
overridevirtual

Write a single character c to the buffer.

Implements swoc::BufferWriter.

Definition at line 12 of file ArenaWriter.cc.

◆ write() [2/2]

ArenaWriter & swoc::ArenaWriter::write ( void const * data,
size_t n )
overridevirtual

Write data to the buffer.

Parameters
dataData to write.
nAmount of data in bytes.
Returns
this

Reimplemented from swoc::BufferWriter.

Definition at line 21 of file ArenaWriter.cc.

Member Data Documentation

◆ _arena

MemArena& swoc::ArenaWriter::_arena
protected

Arena for the buffer.

Definition at line 52 of file ArenaWriter.h.


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