StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::Callback Class Referencefinal

Callback with explicitly cloned context and creator-module release. More...

#include <StormByte/safe/callback.hxx>

Public Types

using Invoke = Status (*)(void*, const String&) noexcept
 Invoke with owned context and borrowed text.
using Clone = void* (*)(const void*) noexcept
 Clone the callback context in its creator module; null reports failure.
using Release = void (*)(void*) noexcept
 Release the context in its creator module exactly once.

Public Member Functions

 Callback (void *context, Invoke invoke, Clone clone, Release release)
 Adopt a non-null context with non-null callbacks.
 Callback (const Callback &other)=default
 Deep-copy the context through its creator-module callback.
Callback & operator= (const Callback &other)=default
 Deep-copy the context with the strong guarantee.
 Callback (Callback &&other) noexcept
 Transfer context; source becomes empty.
Callback & operator= (Callback &&other) noexcept
 Release old context and transfer.
 ~Callback () noexcept
 Invoke the creator-module release callback.
bool HasValue () const noexcept
 Test whether a context is held.
Status Call (const String &value) const noexcept
 Invoke with borrowed UTF-8 text.

Detailed Description

Callback with explicitly cloned context and creator-module release.

Invoke borrows UTF-8 text for the duration of the call. Retained text must be copied into a Safe owner. Function pointers use the project's default C++ calling convention; all participants must agree. No exceptions may escape Invoke or Release. Keep the callback's module and Base loaded until release. Thread safety and reentrancy are the provider's responsibility. A callback must not destroy itself during invocation. This is not std::function.

Member Typedef Documentation

◆ Clone

using StormByte::Safe::Callback::Clone = void* (*)(const void*) noexcept

Clone the callback context in its creator module; null reports failure.

◆ Invoke

using StormByte::Safe::Callback::Invoke = Status (*)(void*, const String&) noexcept

Invoke with owned context and borrowed text.

◆ Release

using StormByte::Safe::Callback::Release = void (*)(void*) noexcept

Release the context in its creator module exactly once.

Constructor & Destructor Documentation

◆ Callback() [1/3]

StormByte::Safe::Callback::Callback ( void * context,
Invoke invoke,
Clone clone,
Release release )

Adopt a non-null context with non-null callbacks.

Parameters
contextOwned context.
invokeInvocation callback.
cloneContext clone callback.
releaseDestruction callback.
Exceptions
StormByte::ExceptionInvalid arguments; ownership is not transferred.

◆ Callback() [2/3]

StormByte::Safe::Callback::Callback ( const Callback & other)
default

Deep-copy the context through its creator-module callback.

Parameters
otherSource callback.
Exceptions
StormByte::ExceptionContext cloning failed.

◆ Callback() [3/3]

StormByte::Safe::Callback::Callback ( Callback && other)
noexcept

Transfer context; source becomes empty.

Parameters
otherSource.

◆ ~Callback()

StormByte::Safe::Callback::~Callback ( )
noexcept

Invoke the creator-module release callback.

Member Function Documentation

◆ Call()

Status StormByte::Safe::Callback::Call ( const String & value) const
noexcept

Invoke with borrowed UTF-8 text.

Parameters
valueText valid for this call.
Returns
Provider status, or Missing after move.

◆ HasValue()

bool StormByte::Safe::Callback::HasValue ( ) const
noexcept

Test whether a context is held.

Returns
False after move.

◆ operator=() [1/2]

Callback & StormByte::Safe::Callback::operator= ( Callback && other)
noexcept

Release old context and transfer.

Parameters
otherSource.
Returns
This callback.

◆ operator=() [2/2]

Callback & StormByte::Safe::Callback::operator= ( const Callback & other)
default

Deep-copy the context with the strong guarantee.

Parameters
otherSource callback.
Returns
This callback.
Exceptions
StormByte::ExceptionContext cloning failed.

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