RAVENNAKIT
Loading...
Searching...
No Matches
rav::BufferView< Type > Class Template Reference

A class similar to std::string_view but for raw data buffers. More...

#include <buffer_view.hpp>

Public Member Functions

 BufferView ()=default
 BufferView (const BufferView &other)=default
BufferView & operator= (const BufferView &other)=default
 BufferView (BufferView &&other) noexcept=default
BufferView & operator= (BufferView &&other) noexcept=default
 BufferView (Type *data, const size_t size)
 Construct a view pointing to given data.
template<size_t S>
 BufferView (const std::array< Type, S > &array)
 Construct a view from a std::array.
template<typename T = Type, std::enable_if_t<!std::is_const_v< T >, int > = 0>
 BufferView (const std::vector< Type > &vector)
 Construct a view from a std::vector.
template<typename T = Type, std::enable_if_t<!std::is_const_v< T >, int > = 0>
 BufferView (std::vector< Type > &vector)
 Construct a view from a std::vector.
Type & operator[] (size_t index) const
const Type * data () const
Type * data ()
size_t size () const
size_t size_bytes () const
bool empty () const
template<typename ValueType, std::enable_if_t< std::is_trivially_copyable_v< ValueType >, bool > = true>
ValueType read_ne (const size_t offset) const
 Reads a value from the data in native byte order (not to be confused with network-endian).
template<typename ValueType, std::enable_if_t< std::is_trivially_copyable_v< ValueType >, bool > = true>
ValueType read_be (const size_t offset) const
 Reads a big-endian value from the given data.
template<typename ValueType, std::enable_if_t< std::is_trivially_copyable_v< ValueType >, bool > = true>
ValueType read_le (const size_t offset) const
 Reads a little-endian value from the given data.
BufferView subview (size_t offset) const
BufferView subview (size_t offset, const size_t size) const
BufferView< std::add_const_t< Type > > const_view () const
template<class NewType>
BufferView< NewType > reinterpret () const
 Returns a new buffer_view pointing to the same data, but reinterpreted as a different type.

Detailed Description

template<class Type>
class rav::BufferView< Type >

A class similar to std::string_view but for raw data buffers.

Template Parameters
TypeThe data type.

Definition at line 41 of file buffer_view.hpp.

Constructor & Destructor Documentation

◆ BufferView() [1/7]

template<class Type>
rav::BufferView< Type >::BufferView ( )
default

◆ BufferView() [2/7]

template<class Type>
rav::BufferView< Type >::BufferView ( const BufferView< Type > & other)
default

◆ BufferView() [3/7]

template<class Type>
rav::BufferView< Type >::BufferView ( BufferView< Type > && other)
defaultnoexcept

◆ BufferView() [4/7]

template<class Type>
rav::BufferView< Type >::BufferView ( Type * data,
const size_t size )
inline

Construct a view pointing to given data.

Parameters
dataThe data to refer to.
sizeThe number of elements in the buffer.

Definition at line 56 of file buffer_view.hpp.

◆ BufferView() [5/7]

template<class Type>
template<size_t S>
rav::BufferView< Type >::BufferView ( const std::array< Type, S > & array)
inlineexplicit

Construct a view from a std::array.

Template Parameters
SThe size of the array.
Parameters
arrayThe array to refer to.

Definition at line 68 of file buffer_view.hpp.

◆ BufferView() [6/7]

template<class Type>
template<typename T = Type, std::enable_if_t<!std::is_const_v< T >, int > = 0>
rav::BufferView< Type >::BufferView ( const std::vector< Type > & vector)
inlineexplicit

Construct a view from a std::vector.

Parameters
vectorThe vector to refer to.

Definition at line 75 of file buffer_view.hpp.

◆ BufferView() [7/7]

template<class Type>
template<typename T = Type, std::enable_if_t<!std::is_const_v< T >, int > = 0>
rav::BufferView< Type >::BufferView ( std::vector< Type > & vector)
inlineexplicit

Construct a view from a std::vector.

Parameters
vectorThe vector to refer to.

Definition at line 82 of file buffer_view.hpp.

Member Function Documentation

◆ const_view()

template<class Type>
BufferView< std::add_const_t< Type > > rav::BufferView< Type >::const_view ( ) const
inline
Returns
A new buffer_view pointing to the same data, but reinterpreted as a const type.

Definition at line 184 of file buffer_view.hpp.

◆ data() [1/2]

template<class Type>
Type * rav::BufferView< Type >::data ( )
inlinenodiscard
Returns
A pointer to the data, or nullptr if this view is not pointing at any data.

Definition at line 102 of file buffer_view.hpp.

◆ data() [2/2]

template<class Type>
const Type * rav::BufferView< Type >::data ( ) const
inlinenodiscard
Returns
A pointer to the data, or nullptr if this view is not pointing at any data.

Definition at line 95 of file buffer_view.hpp.

◆ empty()

template<class Type>
bool rav::BufferView< Type >::empty ( ) const
inlinenodiscard
Returns
True if the buffer is empty.

Definition at line 123 of file buffer_view.hpp.

◆ operator=() [1/2]

template<class Type>
BufferView & rav::BufferView< Type >::operator= ( BufferView< Type > && other)
defaultnoexcept

◆ operator=() [2/2]

template<class Type>
BufferView & rav::BufferView< Type >::operator= ( const BufferView< Type > & other)
default

◆ operator[]()

template<class Type>
Type & rav::BufferView< Type >::operator[] ( size_t index) const
inline
Parameters
indexThe index to access.
Returns
Value for given index, without bounds checking.

Definition at line 88 of file buffer_view.hpp.

◆ read_be()

template<class Type>
template<typename ValueType, std::enable_if_t< std::is_trivially_copyable_v< ValueType >, bool > = true>
ValueType rav::BufferView< Type >::read_be ( const size_t offset) const
inline

Reads a big-endian value from the given data.

Template Parameters
ValueTypeThe type of the value to read.
Parameters
offsetThe offset to read from.
Returns
The decoded value.

Definition at line 147 of file buffer_view.hpp.

◆ read_le()

template<class Type>
template<typename ValueType, std::enable_if_t< std::is_trivially_copyable_v< ValueType >, bool > = true>
ValueType rav::BufferView< Type >::read_le ( const size_t offset) const
inline

Reads a little-endian value from the given data.

Template Parameters
ValueTypeThe type of the value to read.
Parameters
offsetThe offset to read from.
Returns
The decoded value.

Definition at line 158 of file buffer_view.hpp.

◆ read_ne()

template<class Type>
template<typename ValueType, std::enable_if_t< std::is_trivially_copyable_v< ValueType >, bool > = true>
ValueType rav::BufferView< Type >::read_ne ( const size_t offset) const
inline

Reads a value from the data in native byte order (not to be confused with network-endian).

Bounds are asserted, and behaviour depends on the RAV_ASSERT configuration.

Template Parameters
ValueTypeThe type of the value to read.
Parameters
offsetThe offset to read from.
Returns
The decoded value.

Definition at line 135 of file buffer_view.hpp.

◆ reinterpret()

template<class Type>
template<class NewType>
BufferView< NewType > rav::BufferView< Type >::reinterpret ( ) const
inline

Returns a new buffer_view pointing to the same data, but reinterpreted as a different type.

WARNING! Reinterpreting data can potentially lead to undefined behavior. Rules for reinterpret_cast apply.

Template Parameters
NewTypeThe type of the reinterpretation.
Returns
The new buffer_view.

Definition at line 195 of file buffer_view.hpp.

◆ size()

template<class Type>
size_t rav::BufferView< Type >::size ( ) const
inlinenodiscard
Returns
The number of elements in the buffer.

Definition at line 109 of file buffer_view.hpp.

◆ size_bytes()

template<class Type>
size_t rav::BufferView< Type >::size_bytes ( ) const
inlinenodiscard
Returns
The size of the buffer in bytes.

Definition at line 116 of file buffer_view.hpp.

◆ subview() [1/2]

template<class Type>
BufferView rav::BufferView< Type >::subview ( size_t offset) const
inlinenodiscard
Returns
A new buffer_view pointing to a sub-range of this buffer.
Parameters
offsetThe offset of the sub-range. Will be limited to the available size.

Definition at line 166 of file buffer_view.hpp.

◆ subview() [2/2]

template<class Type>
BufferView rav::BufferView< Type >::subview ( size_t offset,
const size_t size ) const
inlinenodiscard
Returns
A new buffer_view pointing to a sub-range of this buffer.
Parameters
offsetThe offset of the sub-range. Will be limited to the available size.
sizeThe number of elements in the sub-range. The size will be limited to the available size.

Definition at line 176 of file buffer_view.hpp.


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