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

A sentinel that protects write access to memory containing a single C++ object. More...

#include <memory/WriteSentinel_Object.hpp>

+ Inheritance diagram for xentara::memory::WriteSentinel< Object< Type > >:

Public Types

using TargetObject = memory::Object< Type >
 The object type describing the structure.
 
using Element = typename TargetObject::Element
 The C++ object type.
 

Public Member Functions

 WriteSentinel (const ObjectBlock< Type > &block)
 Constructor.
 
 WriteSentinel (const ObjectBlock< Type > &block, CopyOldValuesTag tag)
 Constructor that copies the old values, if necessary.
 
 ~WriteSentinel ()=default
 Destructor.
 
internal auto get () const noexcept -> Element &
 Gets the object.
 
auto operator* () const noexcept -> Element &
 Gets the object.
 
auto operator-> () const noexcept -> Element *
 Member access operator.
 
auto commit () -> void
 Commits the changes.
 
auto discard () -> void
 Discards any uncommitted changes.
 
auto oldValue () const -> const Element &
 Returns the old value of the block.
 

Detailed Description

template<typename Type>
class xentara::memory::WriteSentinel< Object< Type > >

A sentinel that protects write access to memory containing a single C++ object.

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

Member Typedef Documentation

◆ Element

template<typename Type >
using xentara::memory::WriteSentinel< Object< Type > >::Element = typename TargetObject::Element

The C++ object type.

◆ TargetObject

template<typename Type >
using xentara::memory::WriteSentinel< Object< Type > >::TargetObject = memory::Object<Type>

The object type describing the structure.

Constructor & Destructor Documentation

◆ WriteSentinel() [1/2]

template<typename Type >
xentara::memory::WriteSentinel< Object< Type > >::WriteSentinel ( const ObjectBlock< Type > &  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]

template<typename Type >
xentara::memory::WriteSentinel< Object< Type > >::WriteSentinel ( const ObjectBlock< Type > &  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()

template<typename Type >
xentara::memory::WriteSentinel< Object< Type > >::~WriteSentinel ( )
default

Destructor.

Discards any uncommitted changes.

Member Function Documentation

◆ commit()

template<typename Type >
auto xentara::memory::WriteSentinel< Object< Type > >::commit ( ) -> void

Commits the changes.

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

◆ discard()

template<typename Type >
auto xentara::memory::WriteSentinel< Object< Type > >::discard ( ) -> void

Discards any uncommitted changes.

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

◆ get()

template<typename Type >
internal auto xentara::memory::WriteSentinel< Object< Type > >::get ( ) const -> Element &
noexcept

Gets the object.

Returns
The object

◆ oldValue()

template<typename Type >
auto xentara::memory::WriteSentinel< Object< Type > >::oldValue ( ) const -> const Element &

Returns the old value of the block.

This function can be used to access the old value 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
A reference to the old (current) value of the block.
Warning
Do not access the data after you have called commit() or discard()!

◆ operator*()

template<typename Type >
auto xentara::memory::WriteSentinel< Object< Type > >::operator* ( ) const -> Element &
noexcept

Gets the object.

Returns
The object

◆ operator->()

template<typename Type >
auto xentara::memory::WriteSentinel< Object< Type > >::operator-> ( ) const -> Element *
noexcept

Member access operator.

Returns
A pointer to the object