Cogs.Core
Public Member Functions | Private Attributes | List of all members
Cogs::MappedBuffer< MappedDataType > Struct Template Reference

Provides RAII style mapping of a buffer resource. More...

#include <IBuffers.h>

Public Member Functions

 MappedBuffer (struct IContext *context, BufferHandle bufferHandle, MapMode::EMapMode mapMode=MapMode::Read, size_t size=0)
 Constructs a mapped buffer, initializing the mapped contents from the context and buffer handle given.
 
 MappedBuffer (const MappedBuffer &other)=delete
 Deleted copy constructor.
 
 ~MappedBuffer ()
 Destructs the mapped buffer.
 
MappedDataType * get ()
 Get the raw pointer to the mapped data.
 
MappedDataType * operator-> ()
 Pointer operator to allow using the mapped structure as if it was a raw pointer to the data.
 
const MappedDataType * operator-> () const
 Const overload of pointer operator.
 
 operator MappedDataType * ()
 Implicit cast to mapped data type to allow passing the mapped structure to methods expecting a raw pointer.
 
 operator bool () const
 Boolean conversion operator provided to allow pointer-like semantics when checking the validity of the mapped data.
 
MappedDataType & operator[] (size_t index)
 Indexing operator provided to perform optional boundary checks on the mapped data.
 
const MappedDataType & operator[] (size_t index) const
 Indexing operator provided to perform optional boundary checks on the mapped data.
 
uint32_t getStride () const
 Get the stride of the mapped resource in bytes.
 

Private Attributes

struct IContextcontext = nullptr
 
BufferHandle bufferHandle
 
MappedDataType * data = nullptr
 
size_t size = 0
 
uint32_t stride = 0
 

Detailed Description

template<typename MappedDataType>
struct Cogs::MappedBuffer< MappedDataType >

Provides RAII style mapping of a buffer resource.

Definition at line 159 of file IBuffers.h.

Constructor & Destructor Documentation

◆ MappedBuffer()

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::MappedBuffer ( struct IContext context,
BufferHandle  bufferHandle,
MapMode::EMapMode  mapMode = MapMode::Read,
size_t  size = 0 
)
inline

Constructs a mapped buffer, initializing the mapped contents from the context and buffer handle given.

Parameters
contextPointer to the current graphics context.
bufferHandleHandle to the buffer to map data from.
mapModeMode to map the buffer in.

Definition at line 168 of file IBuffers.h.

References Cogs::IContext::map().

◆ ~MappedBuffer()

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::~MappedBuffer ( )
inline

Destructs the mapped buffer.

If the buffer was successfully mapped, it will be unmapped.

Definition at line 182 of file IBuffers.h.

References Cogs::IContext::unmap().

Member Function Documentation

◆ get()

template<typename MappedDataType >
MappedDataType * Cogs::MappedBuffer< MappedDataType >::get ( )
inline

Get the raw pointer to the mapped data.

Returns
Pointer to mapped data, nullptr if the mapping was not successful.

Definition at line 194 of file IBuffers.h.

◆ getStride()

template<typename MappedDataType >
uint32_t Cogs::MappedBuffer< MappedDataType >::getStride ( ) const
inline

Get the stride of the mapped resource in bytes.

Definition at line 257 of file IBuffers.h.

◆ operator bool()

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::operator bool ( ) const
inlineexplicit

Boolean conversion operator provided to allow pointer-like semantics when checking the validity of the mapped data.

MappedBuffer<float> data(context, bufferHandle);
if (data) {
// Mapped data is valid and can worked with.
*data = 1.0f;
}
Provides RAII style mapping of a buffer resource.
Definition: IBuffers.h:160

Definition at line 224 of file IBuffers.h.

◆ operator MappedDataType *()

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::operator MappedDataType * ( )
inline

Implicit cast to mapped data type to allow passing the mapped structure to methods expecting a raw pointer.

Definition at line 209 of file IBuffers.h.

◆ operator->() [1/2]

template<typename MappedDataType >
MappedDataType * Cogs::MappedBuffer< MappedDataType >::operator-> ( )
inline

Pointer operator to allow using the mapped structure as if it was a raw pointer to the data.

Definition at line 200 of file IBuffers.h.

◆ operator->() [2/2]

template<typename MappedDataType >
const MappedDataType * Cogs::MappedBuffer< MappedDataType >::operator-> ( ) const
inline

Const overload of pointer operator.

Definition at line 203 of file IBuffers.h.

◆ operator[]() [1/2]

template<typename MappedDataType >
MappedDataType & Cogs::MappedBuffer< MappedDataType >::operator[] ( size_t  index)
inline

Indexing operator provided to perform optional boundary checks on the mapped data.

Parameters
indexIndex of the element in the array to access.
Returns
Reference to the mapped element.

Definition at line 232 of file IBuffers.h.

◆ operator[]() [2/2]

template<typename MappedDataType >
const MappedDataType & Cogs::MappedBuffer< MappedDataType >::operator[] ( size_t  index) const
inline

Indexing operator provided to perform optional boundary checks on the mapped data.

Parameters
indexIndex of the element in the array to access.
Returns
Const reference to the mapped element.

Definition at line 247 of file IBuffers.h.

Member Data Documentation

◆ bufferHandle

template<typename MappedDataType >
BufferHandle Cogs::MappedBuffer< MappedDataType >::bufferHandle
private

Definition at line 261 of file IBuffers.h.

◆ context

template<typename MappedDataType >
struct IContext* Cogs::MappedBuffer< MappedDataType >::context = nullptr
private

Definition at line 260 of file IBuffers.h.

◆ data

template<typename MappedDataType >
MappedDataType* Cogs::MappedBuffer< MappedDataType >::data = nullptr
private

Definition at line 262 of file IBuffers.h.

◆ size

template<typename MappedDataType >
size_t Cogs::MappedBuffer< MappedDataType >::size = 0
private

Definition at line 263 of file IBuffers.h.

◆ stride

template<typename MappedDataType >
uint32_t Cogs::MappedBuffer< MappedDataType >::stride = 0
private

Definition at line 264 of file IBuffers.h.


The documentation for this struct was generated from the following file: