LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc::LocalBufferWriter< N > Class Template Reference

#include <BufferWriter.h>

Inheritance diagram for swoc::LocalBufferWriter< N >:
Inheritance graph
Collaboration diagram for swoc::LocalBufferWriter< N >:
Collaboration graph

Public Member Functions

 LocalBufferWriter () noexcept
 Construct an empty writer.
 
 LocalBufferWriter (const LocalBufferWriter &that)=delete
 
LocalBufferWriteroperator= (const LocalBufferWriter &that)=delete
 
- 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 Attributes

char _arr [N]
 output 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.
 

Additional Inherited Members

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

Detailed Description

template<size_t N>
class swoc::LocalBufferWriter< N >

A BufferWriter that has an internal buffer.

Template Parameters
NNumber of bytes in internal buffer.

The buffer is part of the class instance and is therefore allocated from the same memory pool as the object. E.g, if this is declared as a local variable the buffer is on the stack.

This was written to make code such as

char buff[1024];
FixedBufferWriter w(buff, sizeof(buff));
FixedBufferWriter(char *buffer, size_t capacity)

simpler as

LocalBufferWriter() noexcept
Construct an empty writer.

This also makes it possible to use inside expressions and other stream operations without concern about having to previously declare the storage. E.g.

create_note(LocalBufferWriter<256>().print("Note {}", idx).view());
BufferWriter & print(const TextView &fmt, Args &&...args)
Definition bwf_base.h:927
swoc::TextView view() const

Definition at line 440 of file BufferWriter.h.

Constructor & Destructor Documentation

◆ LocalBufferWriter()

template<size_t N>
swoc::LocalBufferWriter< N >::LocalBufferWriter ( )
noexcept

Construct an empty writer.

Definition at line 655 of file BufferWriter.h.

Member Data Documentation

◆ _arr

template<size_t N>
char swoc::LocalBufferWriter< N >::_arr[N]
protected

output buffer.

Definition at line 453 of file BufferWriter.h.


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