ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
AlignedCharArray< TChar, TLength > Struct Template Reference

Description:

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
struct alib::characters::AlignedCharArray< TChar, TLength >

Encapsulates a fixed-size character buffer. The character type and the buffer's length are templated. Furthermore the buffer, and with it this type, is aligned to 8 bytes on 64-bit machines and to 4 bytes on 32-bit hardware. This supports fast access and compile-time optimizations.

An overloaded constructor and method Fill allow filling the buffer with a distinct character. This is provided, as a frequent use-case for this struct is to provide String objects of variable length. For example, when generating indentation in text files, a std::basic_ostream might be faster filled with spaces using a local variable of this type than putting character by character to the stream in a loop.

The type's name uses the word "local" because usually it is used with local (stack allocated) variables.

Template Parameters
TCharThe character type. Alias names for C++ character types exist with

Defaults to character.

Template Parameters
TLengthThe length of the local buffer. Defaults to 128 bytes.

Definition at line 647 of file characters.hpp.

#include <characters.hpp>

Public Static Field Index:

static constexpr size_t Alignment
 

Public Field Index:

TChar buffer [TLength]
 The buffer.
 

Public Method Index:

constexpr AlignedCharArray () noexcept=default
 Default constructor. Leaves the characters uninitialized.
 
constexpr AlignedCharArray (TChar fillChar) noexcept
 
constexpr const TChar * Buffer () const noexcept
 
constexpr TChar * Buffer () noexcept
 
constexpr void Fill (TChar fillChar) noexcept
 
constexpr integer Length () const noexcept
 

Field Details:

◆ Alignment

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
size_t Alignment
staticconstexpr
Initial value:
=
std::conditional_t<sizeof(void*) == 8, std::integral_constant<size_t ALIB_COMMA 64>,
std::integral_constant<size_t ALIB_COMMA 64>>::value

The alignment of the field buffer. Because this is the first (and only) field, this struct itself shares this alignment.

Definition at line 650 of file characters.hpp.

◆ buffer

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
TChar buffer[TLength]

The buffer.

Definition at line 655 of file characters.hpp.

Constructor(s) / Destructor Details:

◆ AlignedCharArray()

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
AlignedCharArray ( TChar fillChar)
inlineconstexprnoexcept

Constructor taking a character to initialize the buffer with.

Parameters
fillCharThe character to fill this local buffer with.

Definition at line 662 of file characters.hpp.

Here is the call graph for this function:

Method Details:

◆ Buffer() [1/2]

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
const TChar * Buffer ( ) const
inlineconstexprnoexcept

Returns a pointer to the internal buffer.

Returns
A const pointer to the characters.

Definition at line 670 of file characters.hpp.

◆ Buffer() [2/2]

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
TChar * Buffer ( )
inlineconstexprnoexcept

Returns a pointer to the internal buffer.

Returns
A mutable pointer to the characters.

Definition at line 666 of file characters.hpp.

◆ Fill()

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
void Fill ( TChar fillChar)
inlineconstexprnoexcept

Fills the buffer with given fillChar.

Parameters
fillCharThe character to fill this local buffer with.

Definition at line 678 of file characters.hpp.

Here is the call graph for this function:

◆ Length()

template<typename TChar = character, size_t TLength = 128/sizeof(TChar)>
integer Length ( ) const
inlineconstexprnoexcept

Returns the number of characters in this buffer.

Returns
The value of template parameter TLength.

Definition at line 674 of file characters.hpp.


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