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

Output sink that guarantees a null-terminated string within a fixed-size buffer. More...

#include <microfmt.hpp>

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

Public Member Functions

constexpr c_string_sink () noexcept
 Constructs an empty, null-terminated string sink.
 
 ~c_string_sink ()=default
 
RELOCO_BEGIN_UNSAFE_BUFFER_USAGE constexpr c_string_sink (const c_string_sink &other) noexcept
 
constexpr c_string_sink (c_string_sink &&other) noexcept
 
constexpr c_string_sink & operator= (const c_string_sink &other) noexcept
 
constexpr c_string_sink & operator= (c_string_sink &&other) noexcept
 
RELOCO_END_UNSAFE_BUFFER_USAGE sink as_sink () &noexcept RELOCO_LIFETIMEBOUND
 Creates a type-erased sink adapter pointing to this instance.
 
RELOCO_BEGIN_UNSAFE_CODE constexpr const char * c_str () const &noexcept RELOCO_LIFETIMEBOUND
 Returns a null-terminated C string pointer.
 
RELOCO_END_UNSAFE_CODE constexpr const char * c_str () const &&=delete
 
constexpr microfmt::string_view view () const &noexcept RELOCO_LIFETIMEBOUND
 Returns a string view over the characters written (excluding null terminator).
 
constexpr microfmt::string_view view () const &&=delete
 
constexpr std::size_t size () const noexcept
 Returns the length of the string in bytes (excluding null terminator).
 
RELOCO_REINITIALIZES constexpr void reset () noexcept
 Resets the sink to an empty, null-terminated state.
 

Static Public Member Functions

static constexpr std::size_t max_size () noexcept
 Returns the maximum characters the sink can store (excluding null terminator).
 

Detailed Description

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

Output sink that guarantees a null-terminated string within a fixed-size buffer.

Reserves 1 byte for the trailing \0. Output is clamped to N - 1 bytes and guaranteed to be null-terminated after every write.

Template Parameters
NTotal buffer size including the null terminator (must be >= 1).

Constructor & Destructor Documentation

◆ c_string_sink() [1/3]

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

Constructs an empty, null-terminated string sink.

◆ ~c_string_sink()

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

◆ c_string_sink() [2/3]

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

◆ c_string_sink() [3/3]

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

Member Function Documentation

◆ as_sink()

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

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

Returns
A lightweight sink struct configured to append and null-terminate.

◆ c_str() [1/2]

template<std::size_t N>
RELOCO_END_UNSAFE_CODE constexpr const char * microfmt::c_string_sink< N >::c_str ( ) const &&
constexprdelete

◆ c_str() [2/2]

template<std::size_t N>
RELOCO_BEGIN_UNSAFE_CODE constexpr const char * microfmt::c_string_sink< N >::c_str ( ) const &
inlineconstexprnoexcept

Returns a null-terminated C string pointer.

Returns
Pointer to the underlying null-terminated buffer.

◆ max_size()

template<std::size_t N>
static constexpr std::size_t microfmt::c_string_sink< N >::max_size ( )
inlinestaticconstexprnoexcept

Returns the maximum characters the sink can store (excluding null terminator).

Returns
Maximum payload capacity (N - 1).

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ reset()

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

Resets the sink to an empty, null-terminated state.

◆ size()

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

Returns the length of the string in bytes (excluding null terminator).

Returns
String length in bytes.

◆ view() [1/2]

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

◆ view() [2/2]

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

Returns a string view over the characters written (excluding null terminator).

Returns
Non-owning view of formatted text.

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