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

Specialized owning text history with allocation-free publication. More...

#include <text_history.hpp>

Public Member Functions

std::uint64_t contentState () const noexcept
 TextHistory (TextHistoryOptions options={}, WidthPolicy policy={}, TextLimits limits={})
 Create an empty history under immutable text validation settings.
 ~TextHistory ()
 Release all owning history storage.
 TextHistory (const TextHistory &)=delete
TextHistory & operator= (const TextHistory &)=delete
std::expected< PreparedTextHistory, TextHistoryError > prepareEdit (const TextHistorySnapshot &before, const TextHistorySnapshot &after, TextHistoryKind kind) const
 Prepare a whole edit without changing this history.
std::expected< PreparedTextHistory, TextHistoryError > prepareUndo () const
 Stage one undo with restoration segmentation under captured settings.
std::expected< PreparedTextHistory, TextHistoryError > prepareRedo () const
 Stage one redo with restoration segmentation under captured settings.
std::expected< PreparedTextHistory, TextHistoryError > prepareResetBaseline (const TextHistorySnapshot &baseline) const
 Validate a new external baseline and stage clearing every group, even for equal bytes.
std::expected< void, TextHistoryError > checkPrepared (const PreparedTextHistory &prepared) const noexcept
 Check that a prepared value can be committed before publishing its text.
std::expected< void, TextHistoryError > commit (PreparedTextHistory &&prepared) noexcept
 Publish prepared history without allocation or callbacks.
void stopGrouping () noexcept
 End the open editing group; invalidates outstanding staging without allocation.
bool canUndo () const noexcept
 Query local undo availability; editor eligibility belongs to the external owner.
bool canRedo () const noexcept
 Query local redo availability.
std::size_t operationCount () const noexcept
 Count all retained undo and redo groups.
std::size_t retainedBytes () const noexcept
 Query retained logical memory, excluding documented overhead.

Detailed Description

Specialized owning text history with allocation-free publication.

Values contain no editor, model, widget, callback or external buffer references. The caller synchronizes operations; editor owners normally use their UI thread. All retained undo and redo groups share one count and logical memory budget. Memory counts sizeof(entry), both string capacities, and an optional pair of content-state tokens per group when tracking is enabled. Container storage, shared ownership control blocks, allocator bookkeeping, the current editor text and temporary staging allocations are excluded; this is not an RSS cap. Staging copies only shared entry handles, never all retained strings. Constructor allocations may throw; prepare methods return NO_MEMORY instead.

Constructor & Destructor Documentation

◆ TextHistory()

portals::TextHistory::TextHistory ( TextHistoryOptions options = {},
WidthPolicy policy = {},
TextLimits limits = {} )
explicit

Create an empty history under immutable text validation settings.

Parameters
optionsRetention and grouping configuration, captured by value.
policyWidth policy applied to every prepared snapshot.
limitsText validation limits applied to every prepared snapshot.

Member Function Documentation

◆ canRedo()

bool portals::TextHistory::canRedo ( ) const
nodiscardnoexcept

Query local redo availability.

Returns
True when at least one recorded group follows the history cursor.

◆ canUndo()

bool portals::TextHistory::canUndo ( ) const
nodiscardnoexcept

Query local undo availability; editor eligibility belongs to the external owner.

Returns
True when at least one recorded group precedes the history cursor.

◆ checkPrepared()

std::expected< void, TextHistoryError > portals::TextHistory::checkPrepared ( const PreparedTextHistory & prepared) const
nodiscardnoexcept

Check that a prepared value can be committed before publishing its text.

Parameters
preparedOwning staged operation from this unchanged history.
Returns
Success or STALE; does not change either value or allocate.

◆ commit()

std::expected< void, TextHistoryError > portals::TextHistory::commit ( PreparedTextHistory && prepared)
nodiscardnoexcept

Publish prepared history without allocation or callbacks.

Parameters
preparedPreviously checked staging, consumed on success.
Returns
Success or STALE; failures preserve history and staging.

◆ contentState()

std::uint64_t portals::TextHistory::contentState ( ) const
nodiscardnoexcept
Returns
Current opaque owner-local content state; initially one when enabled, otherwise zero. Tokens remain distinct after branching and baseline reset. This is not a save authority.

◆ operationCount()

std::size_t portals::TextHistory::operationCount ( ) const
nodiscardnoexcept

Count all retained undo and redo groups.

Returns
Combined operation count, bounded by maxOperations.

◆ prepareEdit()

std::expected< PreparedTextHistory, TextHistoryError > portals::TextHistory::prepareEdit ( const TextHistorySnapshot & before,
const TextHistorySnapshot & after,
TextHistoryKind kind ) const
nodiscard

Prepare a whole edit without changing this history.

Parameters
beforeCurrent text and selection; selection changes prevent merging.
afterAccepted candidate text and selection.
kindEditing category; paste, cut, replacement and programmatic edits are separate.
Returns
Owning staging or a typed failure. Equal bytes preserve redo.

◆ prepareRedo()

std::expected< PreparedTextHistory, TextHistoryError > portals::TextHistory::prepareRedo ( ) const
nodiscard

Stage one redo with restoration segmentation under captured settings.

Returns
Owning target text and staged cursor, or EMPTY/technical failure.

◆ prepareResetBaseline()

std::expected< PreparedTextHistory, TextHistoryError > portals::TextHistory::prepareResetBaseline ( const TextHistorySnapshot & baseline) const
nodiscard

Validate a new external baseline and stage clearing every group, even for equal bytes.

Parameters
baselineNew current text and selection; retained editor storage remains external.
Returns
Owning target text and reset staging, or a typed failure.

◆ prepareUndo()

std::expected< PreparedTextHistory, TextHistoryError > portals::TextHistory::prepareUndo ( ) const
nodiscard

Stage one undo with restoration segmentation under captured settings.

Returns
Owning target text and staged cursor, or EMPTY/technical failure.

◆ retainedBytes()

std::size_t portals::TextHistory::retainedBytes ( ) const
nodiscardnoexcept

Query retained logical memory, excluding documented overhead.

Returns
Sum of entry objects and UTF-8 capacities, in bytes.

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