xentara-plugin v2.0.4
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::memory::WriteSentinel< Array > Class Referencefinal

A sentinel that protects write access to memory containing a heterogenious array. More...

#include <xentara/memory/WriteSentinel_Array.hpp>

+ Inheritance diagram for xentara::memory::WriteSentinel< Array >:

Public Member Functions

 WriteSentinel (const ArrayBlock &block)
 Constructor.
 
 WriteSentinel (const ArrayBlock &block, CopyOldValuesTag tag)
 Constructor that copies the old values, if necessary.
 
 ~WriteSentinel ()=default
 Destructor.
 
internal auto operator[] (const Array::Handle &handle) const noexcept -> void *
 Gets a raw memory element.
 
template<typename Type >
auto operator[] (const Array::ObjectHandle< Type > &handle) const noexcept -> Type &
 Gets an element containing a C++ object.
 
auto commit (std::chrono::system_clock::time_point timeStamp) -> void
 Commits the changes.
 
template<std::same_as< process::Event >... AdditionalEvents>
requires (sizeof...(AdditionalEvents) > 0)
auto commit (std::chrono::system_clock::time_point timeStamp, const AdditionalEvents &...additionalEvents) -> void
 Commits the changes, raising additional events.
 
auto commit (std::chrono::system_clock::time_point timeStamp, std::span< std::reference_wrapper< const process::Event > > additionalEvents) -> void
 Commits the changes, raising a list of additional events.
 
auto commit () -> void
 deprecated Deprecated overload of commit() that uses the current time as time stamp.
 
auto discard () -> void
 Discards any uncommitted changes.
 
auto oldValues () const -> ConstArrayAccessor
 Creates an accessor for the old values of the block.
 

Detailed Description

A sentinel that protects write access to memory containing a heterogenious array.

Note
Objects of this class can be moved, but not copied.

Constructor & Destructor Documentation

◆ WriteSentinel() [1/2]

xentara::memory::WriteSentinel< Array >::WriteSentinel ( const ArrayBlock block)

Constructor.

Attention
The new values will be default constructed. To initialize the new values with the old values, use the other constructor.
Parameters
blockThe memory block you wish to write to

◆ WriteSentinel() [2/2]

xentara::memory::WriteSentinel< Array >::WriteSentinel ( const ArrayBlock block,
CopyOldValuesTag  tag 
)

Constructor that copies the old values, if necessary.

This constructor will initialize the new values with copies of the old values.

Parameters
blockThe memory block you wish to write to
tagAlways pass kCopyOldValues as this parameter

◆ ~WriteSentinel()

Destructor.

Discards any uncommitted changes.

Member Function Documentation

◆ commit() [1/4]

auto xentara::memory::WriteSentinel< Array >::commit ( ) -> void

deprecated Deprecated overload of commit() that uses the current time as time stamp.

Deprecated:
Replaced by commit(std::chrono::system_clock::time_point timeStamp)

◆ commit() [2/4]

auto xentara::memory::WriteSentinel< Array >::commit ( std::chrono::system_clock::time_point  timeStamp) -> void

Commits the changes.

Warning
Do not access the data after you have called commit() or discard()!
Parameters
timeStampThe time stamp to be used when raising change events.

◆ commit() [3/4]

template<std::same_as< process::Event >... AdditionalEvents>
requires (sizeof...(AdditionalEvents) > 0)
auto xentara::memory::WriteSentinel< Array >::commit ( std::chrono::system_clock::time_point  timeStamp,
const AdditionalEvents &...  additionalEvents 
) -> void

Commits the changes, raising additional events.

This overload allows you to specify one or more additional events to raise together with any change events resulting from the commit. The change events and additional events will be raised atomically as a block, as described in process::Event::raise().

Warning
Do not access the data after you have called commit() or discard()!
Parameters
timeStampThe time stamp to be used when raising events.
additionalEventsAdditional events to raise together with the change events.

◆ commit() [4/4]

auto xentara::memory::WriteSentinel< Array >::commit ( std::chrono::system_clock::time_point  timeStamp,
std::span< std::reference_wrapper< const process::Event > >  additionalEvents 
) -> void

Commits the changes, raising a list of additional events.

This overload allows you to specify a list of additional events to raise together with any change events resulting from the commit. The change events and additional events will be raised atomically as a block, as described in process::Event::raise().

Warning
Do not access the data after you have called commit() or discard()!
Parameters
timeStampThe time stamp to be used when raising events.
additionalEventsAdditional events to raise together with the change events.
See also
process::EventList
process::FixedEventList
process::StaticEventList

◆ discard()

auto xentara::memory::WriteSentinel< Array >::discard ( ) -> void

Discards any uncommitted changes.

Warning
Do not access the data after you have called commit() or discard()!

◆ oldValues()

auto xentara::memory::WriteSentinel< Array >::oldValues ( ) const -> ConstArrayAccessor

Creates an accessor for the old values of the block.

This function can be used to access the old values of the block for memory resources that write by allocating a new block and swapping it in for the old one on commit. For memory resources that write data in place, the returned object provides access to the same memory as the writer itself.

Returns
An accessor suitable for accessing the old (current) values of the block.
Warning
Do not access the data after you have called commit() or discard()!

◆ operator[]() [1/2]

internal auto xentara::memory::WriteSentinel< Array >::operator[] ( const Array::Handle handle) const -> void *
noexcept

Gets a raw memory element.

Parameters
handleThe element handle
Returns
The placement of the corresponding element

◆ operator[]() [2/2]

template<typename Type >
auto xentara::memory::WriteSentinel< Array >::operator[] ( const Array::ObjectHandle< Type > &  handle) const -> Type &
noexcept

Gets an element containing a C++ object.

Parameters
handleThe element handle
Returns
A reference to the corresponding element