Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::container::CallableBufferArrayImpl< Allocator, Signatures > Class Template Reference

Implementation class for an inline callable array buffer with explicit allocator. More...

#include <callable_buffer_array.hpp>

Public Types

using allocator_type = Allocator
using byte_allocator_type
using offset_allocator_type
using size_type = size_t

Public Member Functions

constexpr CallableBufferArrayImpl ()=default
constexpr CallableBufferArrayImpl (const allocator_type &alloc)
 Constructs with a custom allocator.
constexpr CallableBufferArrayImpl (std::pmr::memory_resource *resource)
 Constructs with a PMR memory resource.
 CallableBufferArrayImpl (std::nullptr_t)=delete
constexpr CallableBufferArrayImpl (const CallableBufferArrayImpl &)=delete
constexpr CallableBufferArrayImpl (CallableBufferArrayImpl &&other) noexcept
 ~CallableBufferArrayImpl () noexcept
CallableBufferArrayImploperator= (const CallableBufferArrayImpl &)=delete
CallableBufferArrayImploperator= (CallableBufferArrayImpl &&other) noexcept
void Clear () noexcept
 Clears all stored callables, calling destructors as needed.
template<CallableBufferStorable T>
requires details::DefaultOpCallable<std::remove_cvref_t<T>, Signatures...>
void Push (T &&callable)
 Pushes a callable using its default operator() for invocation.
template<auto... Methods, CallableBufferStorable T>
requires details::AllMethodsValid<T, SignaturePack, Methods...> && (sizeof...(Methods) == kNumOperations)
void Push (T &&callable)
 Pushes a callable with custom member function pointers.
template<size_t N = 0, typename... UArgs>
requires details::ArgsConvertibleTo< details::NthSignatureArgsT<N, Signatures...>, UArgs...> && (N < sizeof...(Signatures))
void Invoke (UArgs &&... args) noexcept
 Invokes operation N on all stored callables in insertion order.
constexpr void ReserveBytes (size_type bytes)
 Reserves bytes in the internal buffer.
constexpr void Reserve (size_type count)
 Reserves space for approximately count callables.
constexpr void Swap (CallableBufferArrayImpl &other) noexcept(std::is_nothrow_swappable_v< BufferType > &&std::is_nothrow_swappable_v< OffsetsType >)
 Swaps contents with another array.
constexpr void Merge (CallableBufferArrayImpl &&other)
 Merges another array into this one by moving its callables.
constexpr bool Empty () const noexcept
 Checks if the array is empty.
constexpr size_type Size () const noexcept
 Gets the number of stored callables.
constexpr size_type CapacityBytes () const noexcept
 Gets the current capacity in bytes of the internal buffer.
constexpr allocator_type GetAllocator () const noexcept
 Gets the allocator used by the array.

Static Public Attributes

static constexpr size_t kNumOperations = sizeof...(Signatures)

Friends

void swap (CallableBufferArrayImpl &lhs, CallableBufferArrayImpl &rhs) noexcept(std::is_nothrow_swappable_v< BufferType > &&std::is_nothrow_swappable_v< OffsetsType >)

Detailed Description

template<typename Allocator, typename... Signatures>
requires ((sizeof...(Signatures) > 0) && (details::VoidSignature<Signatures> && ...))
class helios::container::CallableBufferArrayImpl< Allocator, Signatures >

Implementation class for an inline callable array buffer with explicit allocator.

Stores multiple callable instances of heterogeneous types in a single contiguous byte buffer, with embedded function pointers for type-erased invocation. Optimized for fast sequential iteration without virtual dispatch or per-callable heap allocations. Preserves insertion order.

Use the CallableBufferArray alias for ergonomic usage.

Template Parameters
AllocatorAllocator type for the internal byte buffer (default: std::allocator<std::byte>).
SignaturesFunction signatures in the form void(Args...).

Definition at line 36 of file callable_buffer_array.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Allocator, typename... Signatures>
using helios::container::CallableBufferArrayImpl< Allocator, Signatures >::allocator_type = Allocator

Definition at line 40 of file callable_buffer_array.hpp.

◆ byte_allocator_type

template<typename Allocator, typename... Signatures>
using helios::container::CallableBufferArrayImpl< Allocator, Signatures >::byte_allocator_type
Initial value:
std::allocator_traits<allocator_type>::template rebind_alloc<std::byte>

Definition at line 41 of file callable_buffer_array.hpp.

◆ offset_allocator_type

template<typename Allocator, typename... Signatures>
using helios::container::CallableBufferArrayImpl< Allocator, Signatures >::offset_allocator_type
Initial value:
std::allocator_traits<allocator_type>::template rebind_alloc<size_t>

Definition at line 43 of file callable_buffer_array.hpp.

◆ size_type

template<typename Allocator, typename... Signatures>
using helios::container::CallableBufferArrayImpl< Allocator, Signatures >::size_type = size_t

Definition at line 46 of file callable_buffer_array.hpp.

Constructor & Destructor Documentation

◆ CallableBufferArrayImpl() [1/6]

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferArrayImpl< Allocator, Signatures >::CallableBufferArrayImpl ( )
constexprdefault

◆ CallableBufferArrayImpl() [2/6]

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferArrayImpl< Allocator, Signatures >::CallableBufferArrayImpl ( const allocator_type & alloc)
inlineexplicitconstexpr

Constructs with a custom allocator.

Parameters
allocAllocator instance to use

Definition at line 77 of file callable_buffer_array.hpp.

◆ CallableBufferArrayImpl() [3/6]

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferArrayImpl< Allocator, Signatures >::CallableBufferArrayImpl ( std::pmr::memory_resource * resource)
inlineexplicitconstexpr

Constructs with a PMR memory resource.

Enabled only when allocator_type is constructible from std::pmr::memory_resource*.

Parameters
resourceMemory resource used to construct allocator

Definition at line 87 of file callable_buffer_array.hpp.

◆ CallableBufferArrayImpl() [4/6]

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferArrayImpl< Allocator, Signatures >::CallableBufferArrayImpl ( std::nullptr_t )
delete

◆ CallableBufferArrayImpl() [5/6]

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferArrayImpl< Allocator, Signatures >::CallableBufferArrayImpl ( const CallableBufferArrayImpl< Allocator, Signatures > & )
constexprdelete

◆ CallableBufferArrayImpl() [6/6]

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferArrayImpl< Allocator, Signatures >::CallableBufferArrayImpl ( CallableBufferArrayImpl< Allocator, Signatures > && other)
inlineconstexprnoexcept

Definition at line 95 of file callable_buffer_array.hpp.

◆ ~CallableBufferArrayImpl()

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferArrayImpl< Allocator, Signatures >::~CallableBufferArrayImpl ( )
inlinenoexcept

Definition at line 99 of file callable_buffer_array.hpp.

Member Function Documentation

◆ CapacityBytes()

template<typename Allocator, typename... Signatures>
size_type helios::container::CallableBufferArrayImpl< Allocator, Signatures >::CapacityBytes ( ) const
inlinenodiscardconstexprnoexcept

Gets the current capacity in bytes of the internal buffer.

Returns
Capacity in bytes

Definition at line 218 of file callable_buffer_array.hpp.

◆ Clear()

template<typename Allocator, typename... Signatures>
requires ((sizeof...(Signatures) > 0) && (details::VoidSignature<Signatures> && ...))
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Clear ( )
inlinenoexcept

Clears all stored callables, calling destructors as needed.

Destroys in reverse insertion order.

Definition at line 305 of file callable_buffer_array.hpp.

◆ Empty()

template<typename Allocator, typename... Signatures>
bool helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Empty ( ) const
inlinenodiscardconstexprnoexcept

Checks if the array is empty.

Returns
true if empty, false otherwise

Definition at line 202 of file callable_buffer_array.hpp.

◆ GetAllocator()

template<typename Allocator, typename... Signatures>
allocator_type helios::container::CallableBufferArrayImpl< Allocator, Signatures >::GetAllocator ( ) const
inlinenodiscardconstexprnoexcept

Gets the allocator used by the array.

Returns
Allocator instance

Definition at line 226 of file callable_buffer_array.hpp.

◆ Invoke()

template<typename Allocator, typename... Signatures>
requires details::ArgsConvertibleTo< details::NthSignatureArgsT<N, Signatures...>, UArgs...> && (N < sizeof...(Signatures))
template<size_t N, typename... UArgs>
requires details::ArgsConvertibleTo< details::NthSignatureArgsT<N, Signatures...>, UArgs...> && (N < sizeof...(Signatures))
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Invoke ( UArgs &&... args)
inlinenoexcept

Invokes operation N on all stored callables in insertion order.

Supports polymorphic argument conversion for flexible invocation.

Template Parameters
NOperation index (0 to kNumOperations-1)
UArgsActual argument types (must be convertible to signature args)
Parameters
argsArguments for operation N

Definition at line 330 of file callable_buffer_array.hpp.

◆ Merge()

template<typename Allocator, typename... Signatures>
requires ((sizeof...(Signatures) > 0) && (details::VoidSignature<Signatures> && ...))
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Merge ( CallableBufferArrayImpl< Allocator, Signatures > && other)
constexpr

Merges another array into this one by moving its callables.

Moves all callables from the other array into this one. The other array is cleared after the operation.

Parameters
otherArray to merge from

Definition at line 367 of file callable_buffer_array.hpp.

◆ operator=() [1/2]

template<typename Allocator, typename... Signatures>
requires ((sizeof...(Signatures) > 0) && (details::VoidSignature<Signatures> && ...))
auto helios::container::CallableBufferArrayImpl< Allocator, Signatures >::operator= ( CallableBufferArrayImpl< Allocator, Signatures > && other)
inlinenoexcept

Definition at line 289 of file callable_buffer_array.hpp.

◆ operator=() [2/2]

template<typename Allocator, typename... Signatures>
CallableBufferArrayImpl & helios::container::CallableBufferArrayImpl< Allocator, Signatures >::operator= ( const CallableBufferArrayImpl< Allocator, Signatures > & )
delete

◆ Push() [1/2]

template<typename Allocator, typename... Signatures>
template<auto... Methods, CallableBufferStorable T>
requires details::AllMethodsValid<T, SignaturePack, Methods...> && (sizeof...(Methods) == kNumOperations)
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Push ( T && callable)
inline

Pushes a callable with custom member function pointers.

Allows specifying custom function names for each operation. Number of Methods must match kNumOperations. Each method must be invocable on T with the corresponding signature's arguments.

Template Parameters
MethodsMember function pointers for each operation
TCallable type (deduced)
Parameters
callableCallable object to store
// Single operation
array.Push<&MyCmd::Run>(MyCmd{});
// Multiple operations
array.Push<&MyCmd::Execute, &MyCmd::Log>(MyCmd{});

Definition at line 145 of file callable_buffer_array.hpp.

◆ Push() [2/2]

template<typename Allocator, typename... Signatures>
template<CallableBufferStorable T>
requires details::DefaultOpCallable<std::remove_cvref_t<T>, Signatures...>
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Push ( T && callable)
inline

Pushes a callable using its default operator() for invocation.

For single-signature arrays, uses operator()(Args...). For multi-signature arrays, uses operator()(std::integral_constant<size_t, N>, Args...).

Template Parameters
TCallable type that must be invocable with the appropriate signature(s) and return void.
Parameters
callableCallable object to store

Definition at line 121 of file callable_buffer_array.hpp.

◆ Reserve()

template<typename Allocator, typename... Signatures>
requires ((sizeof...(Signatures) > 0) && (details::VoidSignature<Signatures> && ...))
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Reserve ( size_type count)
constexpr

Reserves space for approximately count callables.

Estimates average callable size for reservation.

Parameters
countApproximate number of callables

Definition at line 347 of file callable_buffer_array.hpp.

◆ ReserveBytes()

template<typename Allocator, typename... Signatures>
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::ReserveBytes ( size_type bytes)
inlineconstexpr

Reserves bytes in the internal buffer.

Parameters
bytesNumber of bytes to reserve

Definition at line 166 of file callable_buffer_array.hpp.

◆ Size()

template<typename Allocator, typename... Signatures>
size_type helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Size ( ) const
inlinenodiscardconstexprnoexcept

Gets the number of stored callables.

Returns
Number of callables

Definition at line 210 of file callable_buffer_array.hpp.

◆ Swap()

template<typename Allocator, typename... Signatures>
requires ((sizeof...(Signatures) > 0) && (details::VoidSignature<Signatures> && ...))
void helios::container::CallableBufferArrayImpl< Allocator, Signatures >::Swap ( CallableBufferArrayImpl< Allocator, Signatures > & other)
constexprnoexcept

Swaps contents with another array.

Parameters
otherArray to swap with

Definition at line 356 of file callable_buffer_array.hpp.

◆ swap

template<typename Allocator, typename... Signatures>
void swap ( CallableBufferArrayImpl< Allocator, Signatures > & lhs,
CallableBufferArrayImpl< Allocator, Signatures > & rhs )
friend

Definition at line 183 of file callable_buffer_array.hpp.

Member Data Documentation

◆ kNumOperations

template<typename Allocator, typename... Signatures>
size_t helios::container::CallableBufferArrayImpl< Allocator, Signatures >::kNumOperations = sizeof...(Signatures)
staticconstexpr

Definition at line 38 of file callable_buffer_array.hpp.