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

A memory block containing an array of elements. More...

#include <memory/ArrayBlock.hpp>

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

Public Types

using ElementHandle = RawMemoryHandle
 A handle for accessing an array element.
 
template<typename Type >
using ObjectElementHandle = ObjectHandle< Type >
 A handle for accessing an object array element.
 
template<ObjectType Object>
using ObjectElementHandleFor = ObjectHandleFor< Object >
 A handle for accessing an object array element.
 
template<utils::tools::UnsignedIntegral Type>
using BitFieldElementHandle = BitFieldHandle< Type >
 A handle for accessing a bit field array element.
 
template<BitFieldType BitField>
using BitFieldElementHandleFor = BitFieldHandleFor< BitField >
 A handle for accessing a bit field array element.
 
using BitElementHandle = BitHandle
 A handle for accessing a bit within a bit field array element.
 

Public Member Functions

 MemoryBlock (std::reference_wrapper< const Array > array) noexcept
 Default constructor.
 
 MemoryBlock (std::reference_wrapper< const Array > array, std::nullptr_t) noexcept
 Conversion from an null pointer.
 
 MemoryBlock (MemoryBlock &&other) noexcept
 Move constructor.
 
 MemoryBlock (std::reference_wrapper< const Array > array, MemoryBlock &&other) noexcept
 Pseudo-Move constructor that also updates the array.
 
 ~MemoryBlock ()=default
 Destructor.
 
auto operator= (MemoryBlock &&other) noexcept -> MemoryBlock &=default
 Move assignment operator.
 
auto operator= (std::nullptr_t) noexcept -> MemoryBlock &
 Assignment operator for a null pointer.
 
auto operator== (std::nullptr_t) const -> bool
 Comparison operator with a null pointer.
 
 operator bool () const noexcept
 Boolean operator.
 
auto create (MemoryResource &memoryResource) -> Initializer< Array >
 Allocates memory for the array and default initializes the elements.
 
auto destroy () noexcept -> void
 Destroys any created object and turns the object into a null object.
 
auto initializer () -> Initializer< Array >
 Recovers the initializer for additional initialization.
 
auto array () const -> const Array &
 returns the array associated with the block
 
auto handle (const Array::Handle &elementHandle) const noexcept -> ElementHandle
 Returns a memory handle for an array element's memory.
 
template<typename Type >
auto handle (const Array::ObjectHandle< Type > &objectHandle) const noexcept -> ObjectElementHandle< Type >
 Returns an object handle for an object array element's memory.
 
template<typename ObjectType , typename ObjectOrBaseType , typename MemberType >
requires std::derived_from<ObjectType, ObjectOrBaseType>
auto member (const Array::ObjectHandle< ObjectType > &objectHandle, MemberType ObjectOrBaseType::*member) const noexcept -> ObjectElementHandle< MemberType >
 Returns an object handle to a member of an object array element.
 
template<typename Type >
requires utils::tools::UnsignedIntegral<Type>
auto bits (const Array::ObjectHandle< Type > &baseObjectHandle, Type mask) const noexcept -> BitFieldElementHandle< Type >
 Returns a bit field handle for a bit field array element's memory.
 
template<typename Type >
requires utils::tools::UnsignedIntegral<Type>
auto bit (const Array::ObjectHandle< Type > &baseObjectHandle, Type mask) const noexcept -> BitElementHandle
 Returns a Boolean handle to single bit in a bit field array element's memory.
 
auto memoryResource () const noexcept -> MemoryResource &
 Returns the memory resource that the block was allocated in.
 
auto rawBlock () const noexcept -> const RawMemoryBlock &
 Returns the raw memory block that holds the array.
 
auto rawBlock () noexcept -> RawMemoryBlock &
 Returns the raw memory block that holds the array.
 

Protected Member Functions

auto blockTraits () const noexcept -> BlockTraits final
 Gets the size and alignment info for the block.
 
auto constructAt (void *placement) const -> void final
 Called by the framework to construct a block in an existing placement.
 
auto constructAt (void *placement, const void *init) const -> void final
 Called by the framework to construct a block in an existing placement using copy construction.
 
auto destroyAt (void *placement) const noexcept -> void final
 Called by the framework to destroy the block in an existing placement.
 

Detailed Description

A memory block containing an array of elements.

This class can be moved but not copied.

Member Typedef Documentation

◆ BitElementHandle

using xentara::memory::MemoryBlock< Array >::BitElementHandle = BitHandle

A handle for accessing a bit within a bit field array element.

◆ BitFieldElementHandle

template<utils::tools::UnsignedIntegral Type>
using xentara::memory::MemoryBlock< Array >::BitFieldElementHandle = BitFieldHandle<Type>

A handle for accessing a bit field array element.

◆ BitFieldElementHandleFor

template<BitFieldType BitField>
using xentara::memory::MemoryBlock< Array >::BitFieldElementHandleFor = BitFieldHandleFor<BitField>

A handle for accessing a bit field array element.

◆ ElementHandle

A handle for accessing an array element.

◆ ObjectElementHandle

template<typename Type >
using xentara::memory::MemoryBlock< Array >::ObjectElementHandle = ObjectHandle<Type>

A handle for accessing an object array element.

◆ ObjectElementHandleFor

template<ObjectType Object>
using xentara::memory::MemoryBlock< Array >::ObjectElementHandleFor = ObjectHandleFor<Object>

A handle for accessing an object array element.

Constructor & Destructor Documentation

◆ MemoryBlock() [1/4]

xentara::memory::MemoryBlock< Array >::MemoryBlock ( std::reference_wrapper< const Array array)
noexcept

Default constructor.

This constructor constructs a null object without an allocated block

Parameters
arrayThe array that describes the contents

◆ MemoryBlock() [2/4]

xentara::memory::MemoryBlock< Array >::MemoryBlock ( std::reference_wrapper< const Array array,
std::nullptr_t   
)
noexcept

Conversion from an null pointer.

This constructor constructs a null object without an allocated block

Parameters
arrayThe array that describes the contents

◆ MemoryBlock() [3/4]

xentara::memory::MemoryBlock< Array >::MemoryBlock ( MemoryBlock< Array > &&  other)
noexcept

Move constructor.

This constructor transfers any allocated memory from other to this object. other is turned into as a null object without an allocated block.

◆ MemoryBlock() [4/4]

xentara::memory::MemoryBlock< Array >::MemoryBlock ( std::reference_wrapper< const Array array,
MemoryBlock< Array > &&  other 
)
noexcept

Pseudo-Move constructor that also updates the array.

This constructor transfers any allocated memory from other to this object. other is turned into as a null object without an allocated block.

◆ ~MemoryBlock()

Destructor.

Destroys any allocated array

Member Function Documentation

◆ array()

auto xentara::memory::MemoryBlock< Array >::array ( ) const -> const Array &

returns the array associated with the block

◆ bit()

template<typename Type >
requires utils::tools::UnsignedIntegral<Type>
auto xentara::memory::MemoryBlock< Array >::bit ( const Array::ObjectHandle< Type > &  baseObjectHandle,
Type  mask 
) const -> BitElementHandle
noexcept

Returns a Boolean handle to single bit in a bit field array element's memory.

Requirements:
This function is only available for unsigned integer types.
Parameters
baseObjectHandleA handle to the base value containing the bit field
maskA mask describing the desired bit
Returns
A handle pointing to the bit's data within the block's data

◆ bits()

template<typename Type >
requires utils::tools::UnsignedIntegral<Type>
auto xentara::memory::MemoryBlock< Array >::bits ( const Array::ObjectHandle< Type > &  baseObjectHandle,
Type  mask 
) const -> BitFieldElementHandle<Type>
noexcept

Returns a bit field handle for a bit field array element's memory.

Requirements:
This function is only available for unsigned integer types.
Parameters
baseObjectHandleA handle to the base value containing the bit field
maskA mask describing the relevant bits
Returns
A handle pointing to the bit field's data within the block's data

◆ blockTraits()

auto xentara::memory::MemoryBlock< Array >::blockTraits ( ) const -> BlockTraits
finalprotectedvirtualnoexcept

Gets the size and alignment info for the block.

Implements xentara::memory::MemoryResource::BlockHandler.

◆ constructAt() [1/2]

auto xentara::memory::MemoryBlock< Array >::constructAt ( void *  placement) const -> void
finalprotectedvirtual

Called by the framework to construct a block in an existing placement.

Parameters
placementThe placement of the block

Implements xentara::memory::MemoryResource::BlockHandler.

◆ constructAt() [2/2]

auto xentara::memory::MemoryBlock< Array >::constructAt ( void *  placement,
const void *  init 
) const -> void
finalprotectedvirtual

Called by the framework to construct a block in an existing placement using copy construction.

Parameters
placementThe placement of the block
initThe placement of the block to copy. The block is guaranteed to have the same handler.

Implements xentara::memory::MemoryResource::BlockHandler.

◆ create()

auto xentara::memory::MemoryBlock< Array >::create ( MemoryResource memoryResource) -> Initializer<Array>

Allocates memory for the array and default initializes the elements.

Any previously created object is destroyed

Parameters
memoryResourceThe memory resource to use
Returns
An accessor object for the allocated array that you can use to initialize it

◆ destroy()

auto xentara::memory::MemoryBlock< Array >::destroy ( ) -> void
noexcept

Destroys any created object and turns the object into a null object.

Like operator new and std::free(), this method can safely be called on null objects.

◆ destroyAt()

auto xentara::memory::MemoryBlock< Array >::destroyAt ( void *  placement) const -> void
finalprotectedvirtualnoexcept

Called by the framework to destroy the block in an existing placement.

Parameters
placementThe placement of the block

Implements xentara::memory::MemoryResource::BlockHandler.

◆ handle() [1/2]

auto xentara::memory::MemoryBlock< Array >::handle ( const Array::Handle elementHandle) const -> ElementHandle
noexcept

Returns a memory handle for an array element's memory.

Parameters
elementHandleA handle to the element
Returns
A handle pointing to the desired offset within the element's data

◆ handle() [2/2]

template<typename Type >
auto xentara::memory::MemoryBlock< Array >::handle ( const Array::ObjectHandle< Type > &  objectHandle) const -> ObjectElementHandle<Type>
noexcept

Returns an object handle for an object array element's memory.

Parameters
objectHandleA handle to the object
Returns
A handle pointing to the object's data within the block's data

◆ initializer()

auto xentara::memory::MemoryBlock< Array >::initializer ( ) -> Initializer<Array>

Recovers the initializer for additional initialization.

This function can be used to perform additional initialization of the array from code locations where the initializer returned from create() is not available.

Attention
Do not call this function if any read or write sentinels may exist for the block, or if anyone may be holding any read handles or write handles to data within the block.
Returns
An initializer for additional initialization of the array

◆ member()

template<typename ObjectType , typename ObjectOrBaseType , typename MemberType >
requires std::derived_from<ObjectType, ObjectOrBaseType>
auto xentara::memory::MemoryBlock< Array >::member ( const Array::ObjectHandle< ObjectType > &  objectHandle,
MemberType ObjectOrBaseType::*  member 
) const -> ObjectElementHandle<MemberType>
noexcept

Returns an object handle to a member of an object array element.

Parameters
objectHandleA handle to the object
memberThe member
Returns
A handle to the object member at the specified offset

◆ memoryResource()

auto xentara::memory::MemoryBlock< Array >::memoryResource ( ) const -> MemoryResource &
noexcept

Returns the memory resource that the block was allocated in.

This function may not be called on null objects with no allocated block

◆ operator bool()

xentara::memory::MemoryBlock< Array >::operator bool ( ) const
explicitnoexcept

Boolean operator.

This operator checks whether the object has an allocated memory block

◆ operator=() [1/2]

auto xentara::memory::MemoryBlock< Array >::operator= ( MemoryBlock< Array > &&  other) -> MemoryBlock &=default
defaultnoexcept

Move assignment operator.

This operator swaps the allocated memory with other.

◆ operator=() [2/2]

auto xentara::memory::MemoryBlock< Array >::operator= ( std::nullptr_t  ) -> MemoryBlock &
noexcept

Assignment operator for a null pointer.

This operator deallocates any allocated data turns the object into a null object.

◆ operator==()

auto xentara::memory::MemoryBlock< Array >::operator== ( std::nullptr_t  ) const -> bool

Comparison operator with a null pointer.

This operator checks whether the object is a null object without an allocated block

◆ rawBlock() [1/2]

auto xentara::memory::MemoryBlock< Array >::rawBlock ( ) const -> const RawMemoryBlock &
noexcept

Returns the raw memory block that holds the array.

◆ rawBlock() [2/2]

auto xentara::memory::MemoryBlock< Array >::rawBlock ( ) -> RawMemoryBlock &
noexcept

Returns the raw memory block that holds the array.