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

Implementation class for a single-instance callable buffer with explicit allocator. More...

#include <callable_buffer.hpp>

Public Types

using allocator_type = Allocator
using byte_allocator_type
using size_type = size_t

Public Member Functions

 CallableBufferImpl ()=default
 Default constructor. Creates an empty buffer with no callable.
 CallableBufferImpl (const allocator_type &alloc)
 Constructs with a custom allocator.
 CallableBufferImpl (std::pmr::memory_resource *resource)
 Constructs with a PMR memory resource.
 CallableBufferImpl (std::nullptr_t)=delete
 CallableBufferImpl (const CallableBufferImpl &)=delete
 CallableBufferImpl (CallableBufferImpl &&other) noexcept
 ~CallableBufferImpl () noexcept
CallableBufferImploperator= (const CallableBufferImpl &)=delete
CallableBufferImploperator= (CallableBufferImpl &&other) noexcept
void Clear () noexcept
 Destroys the stored callable (if any) and resets the buffer.
template<CallableBufferStorable T>
requires details::DefaultOpCallable<std::remove_cvref_t<T>, Signatures...>
void Set (T &&callable)
 Stores a callable using its default operator() for invocation.
template<auto... Methods, CallableBufferStorable T>
requires details::AllMethodsValid<T, SignaturePack, Methods...> && (sizeof...(Methods) == kNumOperations)
void Set (T &&callable)
 Stores 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 the stored callable.
void Swap (CallableBufferImpl &other) noexcept(std::is_nothrow_swappable_v< BufferType >)
 Swaps contents with another buffer.
bool Empty () const noexcept
 Checks if a callable is currently stored.
size_type CapacityBytes () const noexcept
 Gets the current capacity in bytes of the internal buffer.
allocator_type GetAllocator () const noexcept
 Gets the allocator used by the buffer.

Static Public Attributes

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

Friends

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

Detailed Description

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

Implementation class for a single-instance callable buffer with explicit allocator.

Stores exactly one callable of any CallableBufferStorable type in a contiguous byte buffer, with embedded function pointers for type-erased invocation. Unlike CallableBufferArray, this container holds at most one callable at a time. Designed for command/handler patterns where you want value semantics with type-erased dispatch.

Use the CallableBuffer 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 38 of file callable_buffer.hpp.

Member Typedef Documentation

◆ allocator_type

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

Definition at line 42 of file callable_buffer.hpp.

◆ byte_allocator_type

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

Definition at line 43 of file callable_buffer.hpp.

◆ size_type

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

Definition at line 45 of file callable_buffer.hpp.

Constructor & Destructor Documentation

◆ CallableBufferImpl() [1/6]

template<typename Allocator, typename... Signatures>
helios::container::CallableBufferImpl< Allocator, Signatures >::CallableBufferImpl ( )
default

Default constructor. Creates an empty buffer with no callable.

◆ CallableBufferImpl() [2/6]

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

Constructs with a custom allocator.

Parameters
allocAllocator instance to use

Definition at line 76 of file callable_buffer.hpp.

◆ CallableBufferImpl() [3/6]

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

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 85 of file callable_buffer.hpp.

◆ CallableBufferImpl() [4/6]

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

◆ CallableBufferImpl() [5/6]

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

◆ CallableBufferImpl() [6/6]

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

Definition at line 237 of file callable_buffer.hpp.

◆ ~CallableBufferImpl()

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

Definition at line 93 of file callable_buffer.hpp.

Member Function Documentation

◆ CapacityBytes()

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

Gets the current capacity in bytes of the internal buffer.

Returns
Capacity in bytes

Definition at line 179 of file callable_buffer.hpp.

◆ Clear()

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

Destroys the stored callable (if any) and resets the buffer.

Definition at line 262 of file callable_buffer.hpp.

◆ Empty()

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

Checks if a callable is currently stored.

Returns
true if empty, false otherwise

Definition at line 173 of file callable_buffer.hpp.

◆ GetAllocator()

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

Gets the allocator used by the buffer.

Returns
Allocator instance

Definition at line 187 of file callable_buffer.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::CallableBufferImpl< Allocator, Signatures >::Invoke ( UArgs &&... args)
inlinenoexcept

Invokes operation N on the stored callable.

Supports polymorphic argument conversion for flexible invocation.

Warning
Triggers assertion if the buffer is empty.
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 289 of file callable_buffer.hpp.

◆ operator=() [1/2]

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

Definition at line 246 of file callable_buffer.hpp.

◆ operator=() [2/2]

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

◆ Set() [1/2]

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

Stores a callable with custom member function pointers.

Allows specifying custom function names for each operation. Number of Methods must match kNumOperations. Any previously stored callable is destroyed first.

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

Definition at line 136 of file callable_buffer.hpp.

◆ Set() [2/2]

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

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

For single-signature buffers, uses operator()(Args...). For multi-signature buffers, uses operator()(std::integral_constant<size_t, N>, Args...). Any previously stored callable is destroyed first.

Template Parameters
TCallable type
Parameters
callableCallable object to store

Definition at line 112 of file callable_buffer.hpp.

◆ Swap()

template<typename Allocator, typename... Signatures>
void helios::container::CallableBufferImpl< Allocator, Signatures >::Swap ( CallableBufferImpl< Allocator, Signatures > & other)
inlinenoexcept

Swaps contents with another buffer.

Parameters
otherBuffer to swap with

Definition at line 158 of file callable_buffer.hpp.

◆ swap

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

Definition at line 164 of file callable_buffer.hpp.

Member Data Documentation

◆ kNumOperations

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

Definition at line 40 of file callable_buffer.hpp.