Raven Engine v0.1
Loading...
Searching...
No Matches
Raven::ScopedBuffer Struct Reference

A wrapper around Buffer that ensures automatic release of memory when it goes out of scope. More...

#include <Buffer.h>

Public Member Functions

 ScopedBuffer (Buffer buffer)
 Constructs a ScopedBuffer from a Buffer.
 ScopedBuffer (u64 size)
 Constructs a ScopedBuffer by allocating a buffer of the specified size.
 ~ScopedBuffer ()
 Destructor that releases the buffer's memory.
u8Data () const
 Accessor for the buffer's raw data.
u64 Size () const
 Accessor for the buffer's size.
template<typename T>
T * As ()
 Casts the buffer's raw data to a specific type.
 operator bool () const
 Converts the ScopedBuffer to a boolean value.

Detailed Description

A wrapper around Buffer that ensures automatic release of memory when it goes out of scope.

This class encapsulates a Buffer and ensures that the memory is released automatically when the object is destroyed. It is useful when you need to manage buffer memory in a scope-bound manner.

Constructor & Destructor Documentation

◆ ScopedBuffer() [1/2]

Raven::ScopedBuffer::ScopedBuffer ( Buffer buffer)
inlineexplicit

Constructs a ScopedBuffer from a Buffer.

Parameters
bufferThe buffer to wrap in this scoped object.

◆ ScopedBuffer() [2/2]

Raven::ScopedBuffer::ScopedBuffer ( u64 size)
inlineexplicit

Constructs a ScopedBuffer by allocating a buffer of the specified size.

Parameters
sizeThe size of the buffer to allocate.

◆ ~ScopedBuffer()

Raven::ScopedBuffer::~ScopedBuffer ( )
inline

Destructor that releases the buffer's memory.

Member Function Documentation

◆ As()

template<typename T>
T * Raven::ScopedBuffer::As ( )
inline

Casts the buffer's raw data to a specific type.

Template Parameters
TThe type to cast to.
Returns
A pointer to the buffer's data as type T.

◆ Data()

u8 * Raven::ScopedBuffer::Data ( ) const
inlinenodiscard

Accessor for the buffer's raw data.

Returns
A pointer to the buffer's data.

◆ operator bool()

Raven::ScopedBuffer::operator bool ( ) const
inlineexplicit

Converts the ScopedBuffer to a boolean value.

Returns
true if the buffer contains data, false otherwise.

◆ Size()

u64 Raven::ScopedBuffer::Size ( ) const
inlinenodiscard

Accessor for the buffer's size.

Returns
The size of the buffer.

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