xentara-plugin v1.2.1
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::memory::WriteSentinel< RawMemory > Class Referencefinal

A sentinel that protects write access to raw memory. More...

#include <memory/WriteSentinel_RawMemory.hpp>

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

Public Member Functions

 WriteSentinel (const RawMemoryBlock &block)
 Constructor.
 
 WriteSentinel (const RawMemoryBlock &block, CopyOldValuesTag tag)
 Constructor that copies the old values, if necessary.
 
 ~WriteSentinel ()
 Destructor.
 
internal auto commit () -> void
 Commits the changes.
 
auto discard () -> void
 Discards any uncommitted changes.
 
auto placement () const noexcept -> void *
 Gets the placement of the containing data.
 
auto oldData () const -> const void *
 Gets a pointer to the old data of the block.
 

Detailed Description

A sentinel that protects write access to raw memory.

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

Constructor & Destructor Documentation

◆ WriteSentinel() [1/2]

xentara::memory::WriteSentinel< RawMemory >::WriteSentinel ( const RawMemoryBlock 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< RawMemory >::WriteSentinel ( const RawMemoryBlock 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 WriteSentinel::kCopyOldValues as this parameter

◆ ~WriteSentinel()

Destructor.

Discards any uncommitted changes.

Member Function Documentation

◆ commit()

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

Commits the changes.

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

◆ discard()

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

Discards any uncommitted changes.

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

◆ oldData()

auto xentara::memory::WriteSentinel< RawMemory >::oldData ( ) const -> const void *

Gets a pointer to the old data of the block.

This function can be used to access the old data 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 pointer is the same as placement().

Returns
A pointer to the old (current) values of the block.
Warning
Do not access the data after you have called commit() or discard()!

◆ placement()

auto xentara::memory::WriteSentinel< RawMemory >::placement ( ) const -> void *
noexcept

Gets the placement of the containing data.

Returns