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

Owning literal bytes or a resource key, measured only at resolution. More...

#include <text_value.hpp>

Public Member Functions

constexpr ~TextValue ()=default
 Release the independently owned expression bytes.
constexpr TextValue (const TextValue &other)=default
 Copy expression bytes and kind into independent storage.
constexpr TextValue & operator= (const TextValue &other)=default
 Replace expression bytes and kind with an owning copy.
constexpr TextValue (TextValue &&other)=default
 Transfer expression storage using the standard library's default move.
constexpr TextValue & operator= (TextValue &&other)=default
 Transfer expression storage using the standard library's default move assignment.
constexpr TextValue (std::string_view bytes)
 Copy a literal buffer into independent expression storage.
constexpr std::string_view resourceKey () const noexcept
 Inspect the resource key without resolving or allocating.
constexpr bool isEmptyLiteral () const noexcept
std::expected< GraphemeText, TextValueError > resolve (WidthPolicy policy, TextLimits limits={}) const
 Resolve literal bytes without requiring a resource resolver.
template<class Resolver>
requires std::invocable<Resolver, std::string_view> && std::same_as<std::invoke_result_t<Resolver, std::string_view>,
std::expected<std::string, TextResourceError>>
std::expected< GraphemeText, TextValueError > resolve (WidthPolicy policy, Resolver &&resolver, TextLimits limits={}) const
 Resolve a key synchronously through the caller, or validate a literal directly.

Friends

class ManagedScene
constexpr TextValue i18n (std::string_view key)
 Copy a resource key for later resolution through an explicit caller.

Detailed Description

Owning literal bytes or a resource key, measured only at resolution.

No locale, resolver, display policy or mutable global state is retained. Construction copies bytes without validation, repair or normalization. Resolution validates under the receiving scene's explicit policy. Re-resolve after changing policy or resources; the caller owns layout/paint invalidation. Independent values have no thread affinity. Concurrent reads are safe when the caller's resolver is safe; mutation/destruction require synchronization. Construction and copy may throw std::bad_alloc or std::length_error. With the MSVC standard library and nonzero _ITERATOR_DEBUG_LEVEL, rvalue construction/assignment use fallible owning copies to avoid noexcept proxy allocation. Other library modes retain their default string moves.

Constructor & Destructor Documentation

◆ TextValue() [1/3]

portals::TextValue::TextValue ( const TextValue & other)
constexprdefault

Copy expression bytes and kind into independent storage.

Parameters
otherSource expression; copying may allocate and leaves it unchanged.

◆ TextValue() [2/3]

portals::TextValue::TextValue ( TextValue && other)
constexprdefault

Transfer expression storage using the standard library's default move.

Parameters
otherSource expression; its moved-from value remains valid but unspecified.

◆ TextValue() [3/3]

portals::TextValue::TextValue ( std::string_view bytes)
inlineexplicitconstexpr

Copy a literal buffer into independent expression storage.

Parameters
bytesLiteral bytes borrowed only during construction, including invalid UTF-8.
Exceptions
std::bad_allocIf expression storage cannot be allocated.
std::length_errorIf the buffer exceeds string storage limits.

Member Function Documentation

◆ isEmptyLiteral()

bool portals::TextValue::isEmptyLiteral ( ) const
inlinenodiscardconstexprnoexcept
Returns
Whether this expression is exactly an empty literal, without resolution or allocation.

◆ operator=() [1/2]

TextValue & portals::TextValue::operator= ( const TextValue & other)
constexprdefault

Replace expression bytes and kind with an owning copy.

Parameters
otherSource expression; self-assignment is supported.
Returns
This expression; copying may allocate.

◆ operator=() [2/2]

TextValue & portals::TextValue::operator= ( TextValue && other)
constexprdefault

Transfer expression storage using the standard library's default move assignment.

Parameters
otherSource expression; existing storage is released.
Returns
This expression; noexcept follows the underlying string move assignment.

◆ resolve() [1/2]

template<class Resolver>
requires std::invocable<Resolver, std::string_view> && std::same_as<std::invoke_result_t<Resolver, std::string_view>,
std::expected<std::string, TextResourceError>>
std::expected< GraphemeText, TextValueError > portals::TextValue::resolve ( WidthPolicy policy,
Resolver && resolver,
TextLimits limits = {} ) const
inlinenodiscard

Resolve a key synchronously through the caller, or validate a literal directly.

Template Parameters
ResolverCallable accepting std::string_view and returning exactly expected<string, TextResourceError>. Move-only callables are supported; the callable is not copied or retained.
Parameters
policyOwning display policy captured by the resulting text.
resolverBorrowed for this call; invoked once for a key and never for a literal. The key view is borrowed only for the callback. Resource acquisition must not block paint/measure.
limitsResource caps applied to the entire resolved buffer, including translated bytes.
Returns
Independent validated text, the original TextError or the resolver's resource error. Non-allocation callback exceptions become RESOLVER_FAILED without retaining exception details.
Exceptions
std::bad_allocIf the callback or text storage allocation fails.
std::length_errorIf the callback or text storage exceeds implementation limits.

◆ resolve() [2/2]

std::expected< GraphemeText, TextValueError > portals::TextValue::resolve ( WidthPolicy policy,
TextLimits limits = {} ) const
inlinenodiscard

Resolve literal bytes without requiring a resource resolver.

Parameters
policyOwning display policy captured by the resulting text.
limitsResource caps applied to the entire resolved literal buffer.
Returns
Independent validated text, the original TextError, or RESOLVER_REQUIRED for a key.
Exceptions
std::bad_allocIf validation storage cannot be allocated.
std::length_errorIf validation storage exceeds implementation limits.

◆ resourceKey()

std::string_view portals::TextValue::resourceKey ( ) const
inlinenodiscardconstexprnoexcept

Inspect the resource key without resolving or allocating.

Returns
Borrowed key bytes, or an empty view for a literal; an empty resource key is also permitted.
Note
The view is invalidated by this value's assignment, move or destruction.

◆ i18n

TextValue i18n ( std::string_view key)
friend

Copy a resource key for later resolution through an explicit caller.

Parameters
keyOpaque resource key borrowed only during this call; empty keys are permitted.
Returns
Owning expression that resolves the key anew on every resolve call.
Exceptions
std::bad_allocIf key storage cannot be allocated.
std::length_errorIf key storage exceeds implementation limits.

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