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

A constant reference to an array and its size. More...

#include <gf/ArrayRef.h>

Public Member Functions

constexpr ArrayRef ()
 Default constructor. More...
 
constexpr ArrayRef (std::nullptr_t)
 Null constructor. More...
 
constexpr ArrayRef (const T *data, std::size_t size)
 Constructor from a pointer and a size. More...
 
 ArrayRef (const std::vector< T > &values)
 Constructor from a std::vector More...
 
template<std::size_t N>
 ArrayRef (const std::array< T, N > &values)
 Constructor from a std::array More...
 
template<std::size_t N>
constexpr ArrayRef (const T(&data)[N])
 Constructor from a static array. More...
 
constexpr const T * getData () const 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 array is empty. More...
 
constexpr ArrayRef< T > sub (std::size_t index)
 Create an array starting at a specified index. More...
 
constexpr const T * begin () const noexcept
 Get an iterator to the first element. More...
 
constexpr const T * end () const noexcept
 Get an iterator past the last element. More...
 
constexpr const T & operator[] (std::size_t index) const
 Get an element at a given index. More...
 

Detailed Description

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

A constant reference to an array and its size.

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

See also
gf::BufferRef, gf::StringRef, gf::array()

Constructor & Destructor Documentation

◆ ArrayRef() [1/6]

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

Default constructor.

Data is nullptr and size is 0.

◆ ArrayRef() [2/6]

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

Null constructor.

Data is nullptr and size is 0.

◆ ArrayRef() [3/6]

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

Constructor from a pointer and a size.

Parameters
dataA pointer to the elements in the array
sizeThe number of elements in the array

◆ ArrayRef() [4/6]

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

Constructor from a std::vector

Parameters
valuesThe vector of elements

◆ ArrayRef() [5/6]

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

Constructor from a std::array

Parameters
valuesThe array of elements

◆ ArrayRef() [6/6]

template<typename T>
template<std::size_t N>
constexpr gf::ArrayRef< T >::ArrayRef ( const 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>
constexpr const T* gf::ArrayRef< T >::begin ( ) const
inlinenoexcept

Get an iterator to the first element.

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

◆ end()

template<typename T>
constexpr const T* gf::ArrayRef< T >::end ( ) const
inlinenoexcept

Get an iterator past the last element.

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

◆ getData()

template<typename T>
constexpr const T* gf::ArrayRef< T >::getData ( ) const
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::ArrayRef< T >::getSize ( ) const
inlinenoexcept

Get the number of elements.

Returns
The number of elements in the array

◆ isEmpty()

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

Check if the array is empty.

Returns
True if the array has no elements

◆ operator[]()

template<typename T>
constexpr const T& gf::ArrayRef< T >::operator[] ( std::size_t  index) const
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

◆ sub()

template<typename T>
constexpr ArrayRef<T> gf::ArrayRef< T >::sub ( std::size_t  index)
inline

Create an array starting at a specified index.

Parameters
indexThe starting index of the new array
Returns
A sub-array starting at the new index