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

A memory block containing a single C++ object. More...

#include <memory/ObjectBlock.hpp>

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

Public Types

using TargetObject = memory::Object< Type >
 The object type describing the structure of this block.
 
using Element = typename TargetObject::Element
 The C++ object type contained in this memory block.
 
using Handle = ObjectHandle< Type >
 A handle for accessing the object.
 

Public Member Functions

 MemoryBlock () noexcept=default
 Default constructor.
 
 MemoryBlock (std::nullptr_t) noexcept
 Conversion from an null pointer.
 
 MemoryBlock (MemoryBlock &&other) noexcept=default
 Move constructor.
 
 ~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< TargetObject >
 Allocates memory for the object and default initializes it.
 
auto destroy () noexcept -> void
 Destroys any created object and turns the block into a null block.
 
auto initializer () -> Initializer< TargetObject >
 Recovers the initializer for additional initialization.
 
auto handle () const noexcept -> Handle
 Returns an object handle for the object's memory.
 
template<typename TypeOrBase , typename MemberType >
requires std::derived_from<Type, TypeOrBase>
auto member (MemberType TypeOrBase::*member) const noexcept -> ObjectHandle< MemberType >
 Returns an object handle to one of the object's members.
 
template<std::same_as< Type > BitFieldType = Type>
requires utils::tools::UnsignedIntegral<BitFieldType>
auto bits (Type mask) const noexcept -> BitFieldHandle< BitFieldType >
 Returns a handle to a bit field using the object's value.
 
template<std::same_as< Type > BitFieldType = Type>
requires utils::tools::UnsignedIntegral<BitFieldType>
auto bit (BitFieldType mask) const noexcept -> BitHandle
 Returns a Boolean handle to single bit in a bit field using the object's value.
 
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 object.
 
auto rawBlock () noexcept -> RawMemoryBlock &
 Returns the raw memory block that holds the object.
 

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

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

A memory block containing a single C++ object.

This class can be moved but not copied.

Template Parameters
TypeThe type of the C++ object contained in the block

Member Typedef Documentation

◆ Element

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

The C++ object type contained in this memory block.

◆ Handle

template<typename Type >
using xentara::memory::MemoryBlock< Object< Type > >::Handle = ObjectHandle<Type>

A handle for accessing the object.

◆ TargetObject

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

The object type describing the structure of this block.

Constructor & Destructor Documentation

◆ MemoryBlock() [1/3]

template<typename Type >
xentara::memory::MemoryBlock< Object< Type > >::MemoryBlock ( )
defaultnoexcept

Default constructor.

This constructor constructs a null object without an allocated block

◆ MemoryBlock() [2/3]

template<typename Type >
xentara::memory::MemoryBlock< Object< Type > >::MemoryBlock ( std::nullptr_t  )
noexcept

Conversion from an null pointer.

This constructor constructs a null object without an allocated block

◆ MemoryBlock() [3/3]

template<typename Type >
xentara::memory::MemoryBlock< Object< Type > >::MemoryBlock ( MemoryBlock< Object< Type > > &&  other)
defaultnoexcept

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()

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

Destructor.

Destroys any allocated object

Member Function Documentation

◆ bit()

template<typename Type >
template<std::same_as< Type > BitFieldType = Type>
requires utils::tools::UnsignedIntegral<BitFieldType>
auto xentara::memory::MemoryBlock< Object< Type > >::bit ( BitFieldType  mask) const -> BitHandle
noexcept

Returns a Boolean handle to single bit in a bit field using the object's value.

Requirements:
This function is only available for unsigned integer types.
Parameters
maskA mask describing the desired bit. Must have exactly one bit set.
Returns
A handle to a bit field containing the specified bit
See also
utils::tools::UnsignedIntegral

◆ bits()

template<typename Type >
template<std::same_as< Type > BitFieldType = Type>
requires utils::tools::UnsignedIntegral<BitFieldType>
auto xentara::memory::MemoryBlock< Object< Type > >::bits ( Type  mask) const -> BitFieldHandle<BitFieldType>
noexcept

Returns a handle to a bit field using the object's value.

Requirements:
This function is only available for unsigned integer types.
Parameters
maskA mask describing the relevant bits
Returns
A handle to a bit field containing the specified bits
See also
utils::tools::UnsignedIntegral

◆ blockTraits()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::blockTraits ( ) const -> BlockTraits
finalprotectedvirtualnoexcept

Gets the size and alignment info for the block.

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

◆ constructAt() [1/2]

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::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]

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::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()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::create ( MemoryResource memoryResource) -> Initializer<TargetObject>

Allocates memory for the object and default initializes it.

Any previously created object is destroyed

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

◆ destroy()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::destroy ( ) -> void
noexcept

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

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

◆ destroyAt()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::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()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::handle ( ) const -> Handle
noexcept

Returns an object handle for the object's memory.

◆ initializer()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::initializer ( ) -> Initializer<TargetObject>

Recovers the initializer for additional initialization.

This function can be used to perform additional initialization of the object 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 object

◆ member()

template<typename Type >
template<typename TypeOrBase , typename MemberType >
requires std::derived_from<Type, TypeOrBase>
auto xentara::memory::MemoryBlock< Object< Type > >::member ( MemberType TypeOrBase::*  member) const -> ObjectHandle<MemberType>
noexcept

Returns an object handle to one of the object's members.

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

◆ memoryResource()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::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()

template<typename Type >
xentara::memory::MemoryBlock< Object< Type > >::operator bool ( ) const
explicitnoexcept

Boolean operator.

This operator checks whether the object has an allocated memory block

◆ operator=() [1/2]

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::operator= ( MemoryBlock< Object< Type > > &&  other) -> MemoryBlock &=default
defaultnoexcept

Move assignment operator.

This operator swaps the allocated memory with other.

◆ operator=() [2/2]

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::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==()

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::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]

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::rawBlock ( ) const -> const RawMemoryBlock &
noexcept

Returns the raw memory block that holds the object.

◆ rawBlock() [2/2]

template<typename Type >
auto xentara::memory::MemoryBlock< Object< Type > >::rawBlock ( ) -> RawMemoryBlock &
noexcept

Returns the raw memory block that holds the object.