48 [[nodiscard]]
explicit operator bool()
const noexcept
50 return (data !=
nullptr) && (size > 0U);
60template <
typename T,
size_t Capacity>
class WorkArray final
65 static constexpr size_t get_capacity()
noexcept
70 [[nodiscard]]
size_t get_used()
const noexcept
75 [[nodiscard]]
size_t get_remaining()
const noexcept
77 return Capacity - get_used();
80 [[nodiscard]] T* data()
noexcept
85 [[nodiscard]]
const T* data()
const noexcept
129 if ((len == 0U) || (len > Capacity))
133 if ((m_top + len) > Capacity)
139 out.data = &m_data[m_top];
154 if ((ptr ==
nullptr) || (len == 0U) || (len > Capacity))
159 T*
const begin = m_data.data();
160 T*
const end = m_data.data() + Capacity;
161 if ((ptr < begin) || (ptr >= end))
166 const size_t start =
static_cast<size_t>(ptr - begin);
167 if ((start + len) > Capacity)
173 if ((start + len) != m_top)
191 std::array<T, Capacity> m_data = {};
201template <
typename T,
size_t Capacity>
class WorkFrame final
217 (void)m_work.restore(m_marker);
220 [[nodiscard]]
size_t get_marker()
const noexcept
227 return m_work.allocate(len, out);
Fixed-capacity allocator for temporary work buffers.
Definition fsb_work.h:61
WorkArrayStatus deallocate(T *ptr, size_t len) noexcept
Deallocate a work block previously returned by allocate().
Definition fsb_work.h:152
size_t get_marker() const noexcept
Get a marker representing the current top of stack.
Definition fsb_work.h:101
void reset() noexcept
Reset allocator state (frees all allocations).
Definition fsb_work.h:93
WorkArrayStatus restore(size_t marker) noexcept
Restore the allocator to a previous marker (LIFO bulk free).
Definition fsb_work.h:109
WorkArrayStatus allocate(size_t len, WorkBlock< T > &out) noexcept
Allocate a contiguous work block of len elements.
Definition fsb_work.h:126
WorkArrayStatus deallocate(const WorkBlock< T > &block) noexcept
Deallocate a work block.
Definition fsb_work.h:185
RAII helper that restores a WorkArray to its entry marker.
Definition fsb_work.h:202
@ FULL
Operation failed, buffer is full.
@ SUCCESS
Successful operation.
WorkArrayStatus
Definition fsb_work.h:28
@ OUT_OF_ORDER
Attempted to free memory out of LIFO order.
@ FULL
Not enough space available.
@ SUCCESS
Successful operation.
@ INVALID_ARGUMENT
Invalid argument (null pointer, out of range, size==0, etc.)
A view describing an allocated work block.
Definition fsb_work.h:43