Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::CellBuffer Class Reference

Owning bounded cell framebuffer and immutable-width-policy intern pools. More...

#include <cell_buffer.hpp>

Public Member Functions

 CellBuffer (CellBuffer &&other) noexcept
 Transfer storage and leave a distinct source empty; no allocation or errors.
CellBuffer & operator= (CellBuffer &&other) noexcept
 Transfer storage, invalidate both objects' views and empty a distinct source.
 CellBuffer (const CellBuffer &)=delete
 Buffers have one owner; copying is disabled.
CellBuffer & operator= (const CellBuffer &)=delete
 Buffers have one owner; copy assignment is disabled.
CellSize size () const noexcept
 Return owning normalized extents; no errors or allocation.
WidthPolicy policy () const noexcept
 Return the owning captured width policy; no errors or allocation.
CellBufferLimits limits () const noexcept
 Return the owning resource caps; no errors or allocation.
std::span< const Cell > cells () const noexcept
 Borrow row-major metadata until successful mutation/move/destruction; no errors.
std::expected< CellView, CellBufferError > at (CellPoint position) const noexcept
 Resolve by coordinate; no API accepts arbitrary glyph/style IDs.
std::expected< void, CellBufferError > put (CellPoint position, const GraphemeText &text, std::size_t grapheme_index, CellStyle style={}) noexcept
 Atomically write one complete grapheme, clearing every intersected old glyph.
void clear () noexcept
 Reset to default blanks and reset intern counts; retain capacity, no errors/allocation.
std::expected< void, CellBufferError > resize (CellSize size)
 Allocate a new blank extent with the same policy/caps; discard old contents on success.
CellBufferMemory memory () const noexcept
 Return measured owned storage/counts, excluding allocator overhead; no errors/allocation.

Static Public Member Functions

static std::expected< CellBuffer, CellBufferError > from (CellSize size, WidthPolicy policy={}, CellBufferLimits limits={})
 Allocate a blank buffer and fixed-capacity glyph/byte/style pools.

Detailed Description

Owning bounded cell framebuffer and immutable-width-policy intern pools.

No I/O, callbacks, worker threads or global storage. Any thread may own a buffer; the UI owner mutates it with caller synchronization. Concurrent reads of an unchanged buffer are safe. IDs are local output metadata, never accepted as lookup/write authority. put copies complete display bytes and style. Successful put/clear/resize/assignment invalidates borrowed views logically; failures preserve views, cells, intern counts and accounting. Moving invalidates source views and leaves a distinct source empty, with zero allocated storage; it can be cleared, resized, assigned and queried. Self-move is a no-op. No table eviction occurs: even overwritten entries remain until clear/resize.

Constructor & Destructor Documentation

◆ CellBuffer()

portals::CellBuffer::CellBuffer ( CellBuffer && other)
noexcept

Transfer storage and leave a distinct source empty; no allocation or errors.

Parameters
otherSole storage owner to consume; it becomes empty with default policy and limits.

Member Function Documentation

◆ at()

std::expected< CellView, CellBufferError > portals::CellBuffer::at ( CellPoint position) const
nodiscardnoexcept

Resolve by coordinate; no API accepts arbitrary glyph/style IDs.

Parameters
positionOwning coordinate, borrowed storage is never retained.
Returns
Borrowed display bytes and copied metadata/style, or OUT_OF_BOUNDS.
Note
No allocation; view expires on successful mutation/move/destruction.

◆ cells()

std::span< const Cell > portals::CellBuffer::cells ( ) const
nodiscardnoexcept

Borrow row-major metadata until successful mutation/move/destruction; no errors.

Returns
Borrowed row-major cell records; interpret IDs only through this buffer.

◆ from()

std::expected< CellBuffer, CellBufferError > portals::CellBuffer::from ( CellSize size,
WidthPolicy policy = {},
CellBufferLimits limits = {} )
staticnodiscard

Allocate a blank buffer and fixed-capacity glyph/byte/style pools.

Parameters
sizeOwning cell extents; negative components normalize to zero.
policyOwning complete width policy, captured for all future writes.
limitsOwning caps, validated before allocation and multiplication.
Returns
Independent buffer or explicit limit/policy/allocation error.
Note
Any thread; allocation failures are returned, never partial results.

◆ limits()

CellBufferLimits portals::CellBuffer::limits ( ) const
nodiscardnoexcept

Return the owning resource caps; no errors or allocation.

Returns
An independent copy of the caps used by creation and resize.

◆ memory()

CellBufferMemory portals::CellBuffer::memory ( ) const
nodiscardnoexcept

Return measured owned storage/counts, excluding allocator overhead; no errors/allocation.

Returns
Current owned capacities and used counts; neither peak allocation nor process memory.

◆ operator=()

CellBuffer & portals::CellBuffer::operator= ( CellBuffer && other)
noexcept

Transfer storage, invalidate both objects' views and empty a distinct source.

Parameters
otherStorage owner to consume; self-move preserves the buffer.
Returns
This buffer after replacement; a distinct source has empty storage.

◆ policy()

WidthPolicy portals::CellBuffer::policy ( ) const
nodiscardnoexcept

Return the owning captured width policy; no errors or allocation.

Returns
An independent copy of the policy accepted by put().

◆ put()

std::expected< void, CellBufferError > portals::CellBuffer::put ( CellPoint position,
const GraphemeText & text,
std::size_t grapheme_index,
CellStyle style = {} )
nodiscardnoexcept

Atomically write one complete grapheme, clearing every intersected old glyph.

Parameters
positionOwning first-cell coordinate.
textValidated text, borrowed synchronously; display bytes are copied.
grapheme_indexIndex in text.graphemes(), not a byte offset.
styleOwning paint value, interned by equality.
Returns
Success or coordinate/index/policy/edge/pool error; failure changes nothing.
Note
No allocation. Unsupported text displays ASCII '?'. Touching an old continuation clears its lead too, even outside the new glyph's footprint. Cleared cells outside that footprint retain their old style as ASCII spaces; styled spaces are narrow leads, while default-style spaces are blanks.

◆ resize()

std::expected< void, CellBufferError > portals::CellBuffer::resize ( CellSize size)
nodiscard

Allocate a new blank extent with the same policy/caps; discard old contents on success.

Parameters
sizeOwning extents; negative components normalize to zero.
Returns
Success or extent/allocation error; failure preserves all old storage.
Note
New and old storage coexist during allocation; transient peak can exceed memory().

◆ size()

CellSize portals::CellBuffer::size ( ) const
nodiscardnoexcept

Return owning normalized extents; no errors or allocation.

Returns
The current nonnegative width and height in terminal cells.

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