header_utils
Loading...
Searching...
No Matches
Buffers

A buffer models a stream of byte-like elements that can be appended to. More...

Concepts

concept  ghassanpl::output_buffer
 Checks if an element value is appendable to a buffer.

Typedefs

template<typename BUFFER>
using ghassanpl::buffer_element_type
 Resolves to the destination element type of the buffer.

Functions

template<typename BUFFER, typename T>
bool ghassanpl::buffer_append (BUFFER &&buffer, T &&val)
 Primary function to append a value (preferably the buffer element type) to the buffer.
template<typename BUFFER>
bool ghassanpl::buffer_reserve (BUFFER &buffer, size_t additional)
 Reserves additional elements in the buffer, if possible.
template<typename BUFFER, typename RANGE>
size_t ghassanpl::buffer_append_range (BUFFER &buffer, RANGE &&range)
 Appends elements in the range to the buffer.
template<typename BUFFER, typename CHAR_TYPE>
size_t ghassanpl::buffer_append_cstring_ptr (BUFFER &buffer, const CHAR_TYPE *cstr)
 Appends characters in the cstr to the buffer.
template<typename BUFFER, typename CHAR_TYPE>
size_t ghassanpl::buffer_append_cstring_ptr (BUFFER &buffer, const CHAR_TYPE *cstr, size_t max_len)
 Appends at most max_len characters in the cstr to the buffer.
template<typename BUFFER, size_t N, typename CHAR_TYPE>
size_t ghassanpl::buffer_append_cstring (BUFFER &buffer, const CHAR_TYPE(&cstr)[N])
 Appends characters in the cstr literal array to the buffer.
template<typename BUFFER, typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
size_t ghassanpl::buffer_append_varint (BUFFER &buffer, std::integral auto oval)
 Appends a variable number of uint8_ts to the buffer that encode the value oval in a minimal amount of space.
template<typename BUFFER, typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
size_t ghassanpl::buffer_append_utf8 (BUFFER &buffer, char32_t cp)
 Appends UTF-8 codeunits that represent the Unicode code-point cp to the buffer. Assumes the codepoint is a valid Unicode codepoint that represents a character.
template<typename BUFFER, typename STRING_TYPE, typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
size_t ghassanpl::buffer_append_utf8 (BUFFER &buffer, STRING_TYPE &&str)
 Appends UTF-8 codeunits that represent the char32_t-based range str to the buffer.
template<typename BUFFER, typename POD>
size_t ghassanpl::buffer_append_pod (BUFFER &buffer, POD const &pod)
 Appends a POD value's internal object representation to a buffer.

Detailed Description

A buffer models a stream of byte-like elements that can be appended to.

The default, primary behavior is to append a single byte-like element to the buffer. Most other behaviors can be 'emulated' by repeatedly appending elements, but you are always free to provide your own overloads of the buffer_* functions. The default implementations will try to use methods/functions available in the standard library and its containers. Most functions return either the success boolean, or the number of elements successfully appended (in case of appending ranges).

Typedef Documentation

◆ buffer_element_type

template<typename BUFFER>
using ghassanpl::buffer_element_type

Resolves to the destination element type of the buffer.

Definition at line 36 of file buffers.h.

Function Documentation

◆ buffer_append()

template<typename BUFFER, typename T>
bool ghassanpl::buffer_append ( BUFFER && buffer,
T && val )

Primary function to append a value (preferably the buffer element type) to the buffer.

Definition at line 40 of file buffers.h.

◆ buffer_append_cstring()

template<typename BUFFER, size_t N, typename CHAR_TYPE>
size_t ghassanpl::buffer_append_cstring ( BUFFER & buffer,
const CHAR_TYPE(&) cstr[N] )

Appends characters in the cstr literal array to the buffer.

Definition at line 143 of file buffers.h.

◆ buffer_append_cstring_ptr() [1/2]

template<typename BUFFER, typename CHAR_TYPE>
size_t ghassanpl::buffer_append_cstring_ptr ( BUFFER & buffer,
const CHAR_TYPE * cstr )

Appends characters in the cstr to the buffer.

Definition at line 127 of file buffers.h.

◆ buffer_append_cstring_ptr() [2/2]

template<typename BUFFER, typename CHAR_TYPE>
size_t ghassanpl::buffer_append_cstring_ptr ( BUFFER & buffer,
const CHAR_TYPE * cstr,
size_t max_len )

Appends at most max_len characters in the cstr to the buffer.

Definition at line 135 of file buffers.h.

◆ buffer_append_pod()

template<typename BUFFER, typename POD>
size_t ghassanpl::buffer_append_pod ( BUFFER & buffer,
POD const & pod )

Appends a POD value's internal object representation to a buffer.

Note
If, for some reason, you want to append the pod as a certain type of bytelikes

Definition at line 212 of file buffers.h.

◆ buffer_append_range()

template<typename BUFFER, typename RANGE>
size_t ghassanpl::buffer_append_range ( BUFFER & buffer,
RANGE && range )

Appends elements in the range to the buffer.

Definition at line 91 of file buffers.h.

◆ buffer_append_utf8() [1/2]

template<typename BUFFER, typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
size_t ghassanpl::buffer_append_utf8 ( BUFFER & buffer,
char32_t cp )

Appends UTF-8 codeunits that represent the Unicode code-point cp to the buffer. Assumes the codepoint is a valid Unicode codepoint that represents a character.

Definition at line 169 of file buffers.h.

◆ buffer_append_utf8() [2/2]

template<typename BUFFER, typename STRING_TYPE, typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
size_t ghassanpl::buffer_append_utf8 ( BUFFER & buffer,
STRING_TYPE && str )

Appends UTF-8 codeunits that represent the char32_t-based range str to the buffer.

Assumes all codepoints in str are valid.

See also
buffer_append_utf8(BUFFER& buffer, char32_t cp)

Definition at line 199 of file buffers.h.

◆ buffer_append_varint()

template<typename BUFFER, typename ELEMENT_TYPE = buffer_element_type<BUFFER>>
size_t ghassanpl::buffer_append_varint ( BUFFER & buffer,
std::integral auto oval )

Appends a variable number of uint8_ts to the buffer that encode the value oval in a minimal amount of space.

Definition at line 151 of file buffers.h.

◆ buffer_reserve()

template<typename BUFFER>
bool ghassanpl::buffer_reserve ( BUFFER & buffer,
size_t additional )

Reserves additional elements in the buffer, if possible.

Definition at line 77 of file buffers.h.