Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::BufferRef< T > Class Template Reference

A reference to a modifiable buffer and its size. More...

#include <gf/BufferRef.h>

Public Member Functions

constexpr BufferRef ()
 Default constructor. More...
 
constexpr BufferRef (std::nullptr_t)
 Null constructor. More...
 
constexpr BufferRef (T *data, std::size_t size)
 Constructor from a pointer and a size. More...
 
 BufferRef (std::vector< T > &values)
 Constructor from a std::vector More...
 
template<std::size_t N>
 BufferRef (std::array< T, N > &values)
 Constructor from a std::array More...
 
template<std::size_t N>
constexpr BufferRef (T(&data)[N])
 Constructor from a static array. More...
 
TgetData () noexcept
 Get a pointer to the elements. More...
 
constexpr std::size_t getSize () const noexcept
 Get the number of elements. More...
 
constexpr bool isEmpty () const noexcept
 Check if the buffer is empty. More...
 
Tbegin () noexcept
 Get an iterator to the first element. More...
 
Tend () noexcept
 Get an iterator past the last element. More...
 
Toperator[] (std::size_t index)
 Get an element at a given index. More...
 

Detailed Description

template<typename T>
class gf::BufferRef< T >

A reference to a modifiable buffer and its size.

This class stores a pointer to a buffer and its size. It can be built from various inputs: std::vector, std::array, static array, pointer and size.

See also
gf::ArrayRef, gf::StringRef

Constructor & Destructor Documentation

◆ BufferRef() [1/6]

template<typename T>
constexpr gf::BufferRef< T >::BufferRef ( )
inline

Default constructor.

Data is nullptr and size is 0.

◆ BufferRef() [2/6]

template<typename T>
constexpr gf::BufferRef< T >::BufferRef ( std::nullptr_t  )
inline

Null constructor.

Data is nullptr and size is 0.

◆ BufferRef() [3/6]

template<typename T>
constexpr gf::BufferRef< T >::BufferRef ( T data,
std::size_t  size 
)
inline

Constructor from a pointer and a size.

Parameters
dataA pointer to a buffer
sizeThe number of elements in the buffer

◆ BufferRef() [4/6]

template<typename T>
gf::BufferRef< T >::BufferRef ( std::vector< T > &  values)
inline

Constructor from a std::vector

Parameters
valuesThe vector of elements

◆ BufferRef() [5/6]

template<typename T>
template<std::size_t N>
gf::BufferRef< T >::BufferRef ( std::array< T, N > &  values)
inline

Constructor from a std::array

Parameters
valuesThe array of elements

◆ BufferRef() [6/6]

template<typename T>
template<std::size_t N>
constexpr gf::BufferRef< T >::BufferRef ( T(&)  data[N])
inline

Constructor from a static array.

The size is computed at compile-time.

Parameters
dataThe static array

Member Function Documentation

◆ begin()

template<typename T>
T* gf::BufferRef< T >::begin ( )
inlinenoexcept

Get an iterator to the first element.

Returns
A pointer to the first element
See also
end()

◆ end()

template<typename T>
T* gf::BufferRef< T >::end ( )
inlinenoexcept

Get an iterator past the last element.

Returns
A pointer past the last element
See also
begin()

◆ getData()

template<typename T>
T* gf::BufferRef< T >::getData ( )
inlinenoexcept

Get a pointer to the elements.

Returns
A pointer to the first element in the array

◆ getSize()

template<typename T>
constexpr std::size_t gf::BufferRef< T >::getSize ( ) const
inlinenoexcept

Get the number of elements.

Returns
The number of elements in the array

◆ isEmpty()

template<typename T>
constexpr bool gf::BufferRef< T >::isEmpty ( ) const
inlinenoexcept

Check if the buffer is empty.

Returns
True if the buffer has no elements

◆ operator[]()

template<typename T>
T& gf::BufferRef< T >::operator[] ( std::size_t  index)
inline

Get an element at a given index.

No verification is done on the index.

Parameters
indexThe index of the element
Returns
The element at the given index