A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
owning_span< T > Class Template Reference

#include <Types.hh>

Description

template<typename T>
class owning_span< T >

A contiguous storage container that manages the lifecycle of a buffer of a given size.

Similar to std::unique_ptr in that we guarantee memory safety, however owning_span points to a buffer rather than an object.

Template Parameters
Ttype contained within the buffer

Definition at line 27 of file Types.hh.

Public Member Functions

 owning_span ()
 Uninitialized buffer.
 
 owning_span (size_t count)
 Allocates a buffer of T elements. Does not initialize any elements.
 
 owning_span (const std::span< const T > &span)
 Performs a deep copy from a std::span of const T.
 
 owning_span (const owning_span &rhs)
 Copy constructor.
 
 owning_span (owning_span &&rhs)
 Move constructor.
 
owning_spanoperator= (const owning_span &rhs)
 Copy assignment operator.
 
owning_spanoperator= (owning_span &&rhs)
 Move assignment operator.
 
 ~owning_span ()
 Destroys the underlying buffer on teardown.
 
T & operator[] (size_t idx)
 Indexes into the underlying buffer.
 
const T & operator[] (size_t idx) const
 Indexes into the underlying buffer.
 
T & front ()
 Retrieves the first element in the buffer.
 
const T & front () const
 Retrieves the first element in the buffer.
 
T & back ()
 Retrieves the last element in the buffer.
 
const T & back () const
 Retrieves the last element in the buffer.
 
T * begin ()
 
T * end ()
 
const T * begin () const
 
const T * end () const
 
bool empty () const
 Returns true if the buffer is uninitialized.
 
size_t size () const
 Returns the number of elements that fit in the buffer.
 
std::span< const T > view () const
 Returns a read-only view of the entire buffer.
 

Private Attributes

T * m_data
 Pointer to the underlying buffer.
 
size_t m_size
 The number of T elements that fit in the buffer.
 

Constructor & Destructor Documentation

◆ owning_span() [1/5]

template<typename T >
owning_span< T >::owning_span ( )
inline

Uninitialized buffer.

Definition at line 30 of file Types.hh.

◆ owning_span() [2/5]

template<typename T >
owning_span< T >::owning_span ( size_t count)
inline

Allocates a buffer of T elements. Does not initialize any elements.

Definition at line 33 of file Types.hh.

◆ owning_span() [3/5]

template<typename T >
owning_span< T >::owning_span ( const std::span< const T > & span)
inline

Performs a deep copy from a std::span of const T.

Will compile to a memcpy for trivially copyable types

Definition at line 37 of file Types.hh.

◆ owning_span() [4/5]

template<typename T >
owning_span< T >::owning_span ( const owning_span< T > & rhs)
inline

Copy constructor.

Performs a deep copy

Definition at line 43 of file Types.hh.

◆ owning_span() [5/5]

template<typename T >
owning_span< T >::owning_span ( owning_span< T > && rhs)
inline

Move constructor.

Transfers ownership of the buffer and leaves rhs in an invalid state

Definition at line 50 of file Types.hh.

◆ ~owning_span()

template<typename T >
owning_span< T >::~owning_span ( )
inline

Destroys the underlying buffer on teardown.

Definition at line 86 of file Types.hh.

Member Function Documentation

◆ back() [1/2]

template<typename T >
T & owning_span< T >::back ( )
inlinenodiscard

Retrieves the last element in the buffer.

Definition at line 117 of file Types.hh.

◆ back() [2/2]

template<typename T >
const T & owning_span< T >::back ( ) const
inlinenodiscard

Retrieves the last element in the buffer.

Definition at line 123 of file Types.hh.

◆ begin() [1/2]

template<typename T >
T * owning_span< T >::begin ( )
inlinenodiscard

Definition at line 128 of file Types.hh.

◆ begin() [2/2]

template<typename T >
const T * owning_span< T >::begin ( ) const
inlinenodiscard

Definition at line 136 of file Types.hh.

◆ empty()

template<typename T >
bool owning_span< T >::empty ( ) const
inlinenodiscard

Returns true if the buffer is uninitialized.

Definition at line 145 of file Types.hh.

◆ end() [1/2]

template<typename T >
T * owning_span< T >::end ( )
inlinenodiscard

Definition at line 132 of file Types.hh.

◆ end() [2/2]

template<typename T >
const T * owning_span< T >::end ( ) const
inlinenodiscard

Definition at line 140 of file Types.hh.

◆ front() [1/2]

template<typename T >
T & owning_span< T >::front ( )
inlinenodiscard

Retrieves the first element in the buffer.

Definition at line 105 of file Types.hh.

◆ front() [2/2]

template<typename T >
const T & owning_span< T >::front ( ) const
inlinenodiscard

Retrieves the first element in the buffer.

Definition at line 111 of file Types.hh.

◆ operator=() [1/2]

template<typename T >
owning_span & owning_span< T >::operator= ( const owning_span< T > & rhs)
inline

Copy assignment operator.

Deletes the existing buffer and performs a deep copy

Definition at line 60 of file Types.hh.

◆ operator=() [2/2]

template<typename T >
owning_span & owning_span< T >::operator= ( owning_span< T > && rhs)
inline

Move assignment operator.

Transfers ownership of the buffer and leaves rhs in an invalid state

Definition at line 73 of file Types.hh.

◆ operator[]() [1/2]

template<typename T >
T & owning_span< T >::operator[] ( size_t idx)
inlinenodiscard

Indexes into the underlying buffer.

Parameters
idxThe index of the element in the buffer to retrieve

Definition at line 92 of file Types.hh.

◆ operator[]() [2/2]

template<typename T >
const T & owning_span< T >::operator[] ( size_t idx) const
inlinenodiscard

Indexes into the underlying buffer.

Parameters
idxThe index of the element in the buffer to retrieve

Definition at line 99 of file Types.hh.

◆ size()

template<typename T >
size_t owning_span< T >::size ( ) const
inlinenodiscard

Returns the number of elements that fit in the buffer.

Definition at line 150 of file Types.hh.

◆ view()

template<typename T >
std::span< const T > owning_span< T >::view ( ) const
inlinenodiscard

Returns a read-only view of the entire buffer.

Definition at line 155 of file Types.hh.

Member Data Documentation

◆ m_data

template<typename T >
T* owning_span< T >::m_data
private

Pointer to the underlying buffer.

Definition at line 160 of file Types.hh.

◆ m_size

template<typename T >
size_t owning_span< T >::m_size
private

The number of T elements that fit in the buffer.

Definition at line 161 of file Types.hh.