microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Public Member Functions | List of all members
microfmt::buffer_sink< N > Class Template Reference

Output sink that stores formatted characters in an internal fixed-size stack/inline buffer. More...

#include <microfmt.hpp>

Inheritance diagram for microfmt::buffer_sink< N >:
Inheritance graph
[legend]
Collaboration diagram for microfmt::buffer_sink< N >:
Collaboration graph
[legend]

Public Member Functions

constexpr buffer_sink () noexcept
 Constructs an empty buffer sink.
 
 ~buffer_sink ()=default
 
RELOCO_BEGIN_UNSAFE_BUFFER_USAGE constexpr buffer_sink (const buffer_sink &other) noexcept
 
constexpr buffer_sink (buffer_sink &&other) noexcept
 
constexpr buffer_sink & operator= (const buffer_sink &other) noexcept
 
constexpr buffer_sink & operator= (buffer_sink &&other) noexcept
 
RELOCO_END_UNSAFE_BUFFER_USAGE RELOCO_CONSTEXPR20 sink as_sink () &noexcept RELOCO_LIFETIMEBOUND
 Creates a type-erased sink adapter pointing to this instance.
 
constexpr microfmt::string_view view () const &noexcept RELOCO_LIFETIMEBOUND
 Returns a string view over the characters written so far.
 
constexpr microfmt::string_view view () const &&=delete
 
constexpr std::size_t size () const noexcept
 Returns the total number of characters written so far.
 
constexpr std::size_t capacity () const noexcept
 Returns the maximum capacity of the buffer.
 
constexpr std::size_t available () const noexcept
 Returns the remaining unwritten capacity in the buffer.
 
constexpr span< const char > as_span () const &noexcept RELOCO_LIFETIMEBOUND
 Returns a microfmt::span view over the written portion of the buffer.
 
constexpr span< const char > as_span () const &&=delete
 
RELOCO_REINITIALIZES constexpr void reset () noexcept
 Resets the write offset back to the beginning of the buffer.
 

Detailed Description

template<std::size_t N>
class microfmt::buffer_sink< N >

Output sink that stores formatted characters in an internal fixed-size stack/inline buffer.

Provides a self-contained, zero-allocation storage buffer of N bytes and exposes a type-erased sink interface. Writes exceeding the buffer capacity are safely truncated.

Template Parameters
NThe capacity of the internal storage buffer in bytes.

Constructor & Destructor Documentation

◆ buffer_sink() [1/3]

template<std::size_t N>
constexpr microfmt::buffer_sink< N >::buffer_sink ( )
inlineconstexprnoexcept

Constructs an empty buffer sink.

◆ ~buffer_sink()

template<std::size_t N>
microfmt::buffer_sink< N >::~buffer_sink ( )
default

◆ buffer_sink() [2/3]

template<std::size_t N>
RELOCO_BEGIN_UNSAFE_BUFFER_USAGE constexpr microfmt::buffer_sink< N >::buffer_sink ( const buffer_sink< N > &  other)
inlineconstexprnoexcept

◆ buffer_sink() [3/3]

template<std::size_t N>
constexpr microfmt::buffer_sink< N >::buffer_sink ( buffer_sink< N > &&  other)
inlineconstexprnoexcept

Member Function Documentation

◆ as_sink()

template<std::size_t N>
RELOCO_END_UNSAFE_BUFFER_USAGE RELOCO_CONSTEXPR20 sink microfmt::buffer_sink< N >::as_sink ( ) &
inlinenoexcept

Creates a type-erased sink adapter pointing to this instance.

Returns
A lightweight sink struct configured with a callback to append to this buffer.

◆ as_span() [1/2]

template<std::size_t N>
constexpr span< const char > microfmt::buffer_sink< N >::as_span ( ) const &&
constexprdelete

◆ as_span() [2/2]

template<std::size_t N>
constexpr span< const char > microfmt::buffer_sink< N >::as_span ( ) const &
inlineconstexprnoexcept

Returns a microfmt::span view over the written portion of the buffer.

Returns
Span containing the written characters.

◆ available()

template<std::size_t N>
constexpr std::size_t microfmt::buffer_sink< N >::available ( ) const
inlineconstexprnoexcept

Returns the remaining unwritten capacity in the buffer.

Returns
Available space in bytes.

◆ capacity()

template<std::size_t N>
constexpr std::size_t microfmt::buffer_sink< N >::capacity ( ) const
inlineconstexprnoexcept

Returns the maximum capacity of the buffer.

Returns
Total capacity in bytes (N).

◆ operator=() [1/2]

template<std::size_t N>
constexpr buffer_sink & microfmt::buffer_sink< N >::operator= ( buffer_sink< N > &&  other)
inlineconstexprnoexcept

◆ operator=() [2/2]

template<std::size_t N>
constexpr buffer_sink & microfmt::buffer_sink< N >::operator= ( const buffer_sink< N > &  other)
inlineconstexprnoexcept

◆ reset()

template<std::size_t N>
RELOCO_REINITIALIZES constexpr void microfmt::buffer_sink< N >::reset ( )
inlineconstexprnoexcept

Resets the write offset back to the beginning of the buffer.

◆ size()

template<std::size_t N>
constexpr std::size_t microfmt::buffer_sink< N >::size ( ) const
inlineconstexprnoexcept

Returns the total number of characters written so far.

Returns
Current write offset in bytes.

◆ view() [1/2]

template<std::size_t N>
constexpr microfmt::string_view microfmt::buffer_sink< N >::view ( ) const &&
constexprdelete

◆ view() [2/2]

template<std::size_t N>
constexpr microfmt::string_view microfmt::buffer_sink< N >::view ( ) const &
inlineconstexprnoexcept

Returns a string view over the characters written so far.

Returns
Non-owning view of the formatted output.

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