Cogs.Core
Public Member Functions | List of all members
Cogs::Core::BufferView< T > Struct Template Reference

BufferView provides a typed, reference-counted, span of an underlying buffer resource. More...

#include <Buffer.h>

Inheritance diagram for Cogs::Core::BufferView< T >:
Cogs::Core::ResourceHandle_t< BufferResource > Cogs::Core::ResourceHandleBase

Public Member Functions

 BufferView ()=default
 Default constructor. A default view has no underlying resource.
 
 BufferView (BufferResource *b)
 Construct a buffer view to the given buffer resource b.
 
 BufferView (const ResourceBufferHandle &other)
 Construct a buffer view from the given untyped handle.
 
size_t size () const
 Gets the size of the buffer in number of elements of type T.
 
bool empty () const
 Gets if the buffer is empty.
 
void resize (size_t size)
 Resize the buffer to accomodate size number of elements of type T.
 
T * data ()
 Get a pointer to the underlying data. Returns nullptr if no storage is allocated.
 
const T * data () const
 
T * map ()
 Map the buffer contents, providing write access until unmapped.
 
void unmap ()
 Unmap the buffer storage.
 
T * begin ()
 Get an iterator to the first element of type T in the buffer.
 
T * end ()
 Get an iterator pointing to one past the final element of type T in the buffer.
 
uint8_t getGeneration () const
 Get the generation counter.
 
T & operator[] (size_t index)
 Access the element of type T at index.
 
const T & operator[] (size_t index) const
 Access the element of type T at index.
 
- Public Member Functions inherited from Cogs::Core::ResourceHandle_t< BufferResource >
 ResourceHandle_t ()=default
 Default construct a resource handle.
 
 ResourceHandle_t (ResourceBase *resource)
 Constructs a handle from the given resource pointer.
 
 ResourceHandle_t (const ResourceHandle_t &other)
 Copy construct a handle.
 
 ResourceHandle_t (ResourceHandle_t &&other) noexcept
 Move construct a handle from the given r-value.
 
 ResourceHandle_t (const ResourceHandleBase &other)
 
ResourceHandle_toperator= (const ResourceHandle_t &other)
 Copy assign the handle from the given other handle.
 
BufferResourceresolve () const
 Resolve the handle, returning a pointer to the actual resource.
 
BufferResourceoperator-> () const
 Pointer operator, returns the held resource.
 
- Public Member Functions inherited from Cogs::Core::ResourceHandleBase
 ResourceHandleBase ()=default
 Constructs an empty handle, holding no resource.
 
 ResourceHandleBase (ResourceBase *resource)
 Constructs a handle with the given integer handle and resource pointer pair.
 
 ResourceHandleBase (const ResourceHandleBase &other)
 Copy constructs a handle from the given other handle.
 
 ResourceHandleBase (ResourceHandleBase &&other) noexcept
 Move constructs a handle from the given other handle.
 
 ~ResourceHandleBase ()
 Destructs a handle, and if a resource is held, releases the reference to this resource.
 
ResourceHandleBaseoperator= (const ResourceHandleBase &other)
 Assign the handle from the given other handle.
 
bool operator== (const ResourceHandleBase &other) const
 Compares this instance against the contents of other.
 
bool operator!= (const ResourceHandleBase &other) const
 Compares this instance against other for inequality.
 
 operator bool () const
 Implicit bool conversion operator.
 
ResourceBaseoperator-> ()
 
const ResourceBaseoperator-> () const
 
ResourceBaseget ()
 
const ResourceBaseget () const
 
void reset (ResourceBase *otherResource)
 Reset the contents of this instance to the given handle and resource.
 
ResourceId getId () const
 Get the resource id of the held resource.
 
size_t hash (size_t hashValue=Cogs::hash()) const
 

Additional Inherited Members

- Static Public Attributes inherited from Cogs::Core::ResourceHandle_t< BufferResource >
static const ResourceHandle_t NoHandle
 Handle representing a default (or none if default not present) resource.
 
- Static Public Attributes inherited from Cogs::Core::ResourceHandleBase
static const ResourceHandleBase NoHandle = Cogs::Core::ResourceHandleBase(nullptr)
 Provided as shorthand for empty resource handles.
 
- Protected Member Functions inherited from Cogs::Core::ResourceHandleBase
void resetInternal (ResourceBase *otherResource)
 Reset the contents of this instance to the given handle and resource.
 
- Protected Attributes inherited from Cogs::Core::ResourceHandleBase
ResourceBaseresource = nullptr
 Pointer to held resource.
 

Detailed Description

template<typename T>
struct Cogs::Core::BufferView< T >

BufferView provides a typed, reference-counted, span of an underlying buffer resource.

TODO: Reconsider naming, as "view" is typically used for immutable storage.

Definition at line 117 of file Buffer.h.

Constructor & Destructor Documentation

◆ BufferView() [1/2]

template<typename T >
Cogs::Core::BufferView< T >::BufferView ( BufferResource b)
inline

Construct a buffer view to the given buffer resource b.

Definition at line 123 of file Buffer.h.

◆ BufferView() [2/2]

template<typename T >
Cogs::Core::BufferView< T >::BufferView ( const ResourceBufferHandle other)
inline

Construct a buffer view from the given untyped handle.

Definition at line 126 of file Buffer.h.

References Cogs::Core::ResourceHandle_t< BufferResource >::operator=().

Member Function Documentation

◆ begin()

template<typename T >
T * Cogs::Core::BufferView< T >::begin ( )
inline

Get an iterator to the first element of type T in the buffer.

Definition at line 148 of file Buffer.h.

References Cogs::Core::BufferView< T >::data().

◆ data() [1/2]

template<typename T >
T * Cogs::Core::BufferView< T >::data ( )
inline

Get a pointer to the underlying data. Returns nullptr if no storage is allocated.

Definition at line 138 of file Buffer.h.

References Cogs::Core::BufferResource::data(), and Cogs::Core::ResourceHandle_t< BufferResource >::resolve().

Referenced by Cogs::Core::BufferView< T >::begin(), Cogs::Core::BufferView< T >::end(), and Cogs::Core::BufferView< T >::operator[]().

◆ data() [2/2]

template<typename T >
const T * Cogs::Core::BufferView< T >::data ( ) const
inline

Definition at line 139 of file Buffer.h.

◆ empty()

template<typename T >
bool Cogs::Core::BufferView< T >::empty ( ) const
inline

Gets if the buffer is empty.

Definition at line 132 of file Buffer.h.

References Cogs::Core::BufferResource::empty(), and Cogs::Core::ResourceHandle_t< BufferResource >::resolve().

◆ end()

template<typename T >
T * Cogs::Core::BufferView< T >::end ( )
inline

Get an iterator pointing to one past the final element of type T in the buffer.

Definition at line 151 of file Buffer.h.

References Cogs::Core::BufferView< T >::data(), and Cogs::Core::BufferView< T >::size().

◆ getGeneration()

template<typename T >
uint8_t Cogs::Core::BufferView< T >::getGeneration ( ) const
inline

Get the generation counter.

Definition at line 154 of file Buffer.h.

References Cogs::Core::ResourceHandle_t< BufferResource >::resolve().

◆ map()

template<typename T >
T * Cogs::Core::BufferView< T >::map ( )
inline

Map the buffer contents, providing write access until unmapped.

Definition at line 142 of file Buffer.h.

References Cogs::Core::BufferResource::map(), and Cogs::Core::ResourceHandle_t< BufferResource >::resolve().

◆ operator[]() [1/2]

template<typename T >
T & Cogs::Core::BufferView< T >::operator[] ( size_t  index)
inline

◆ operator[]() [2/2]

template<typename T >
const T & Cogs::Core::BufferView< T >::operator[] ( size_t  index) const
inline

◆ resize()

template<typename T >
void Cogs::Core::BufferView< T >::resize ( size_t  size)
inline

Resize the buffer to accomodate size number of elements of type T.

Definition at line 135 of file Buffer.h.

References Cogs::Core::BufferResource::resize(), Cogs::Core::ResourceHandle_t< BufferResource >::resolve(), and Cogs::Core::BufferView< T >::size().

◆ size()

template<typename T >
size_t Cogs::Core::BufferView< T >::size ( ) const
inline

◆ unmap()

template<typename T >
void Cogs::Core::BufferView< T >::unmap ( )
inline

Unmap the buffer storage.

Definition at line 145 of file Buffer.h.

References Cogs::Core::ResourceHandle_t< BufferResource >::resolve(), and Cogs::Core::BufferResource::unmap().


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