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

#include <Types.hh>

Description

template<typename T>
class Kinoko::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 29 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 >
Kinoko::owning_span< T >::owning_span ( )
inline

Uninitialized buffer.

Definition at line 32 of file Types.hh.

◆ owning_span() [2/5]

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

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

Definition at line 35 of file Types.hh.

◆ owning_span() [3/5]

template<typename T >
Kinoko::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 39 of file Types.hh.

◆ owning_span() [4/5]

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

Copy constructor.

Performs a deep copy

Definition at line 45 of file Types.hh.

◆ owning_span() [5/5]

template<typename T >
Kinoko::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 52 of file Types.hh.

◆ ~owning_span()

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

Destroys the underlying buffer on teardown.

Definition at line 88 of file Types.hh.

Member Function Documentation

◆ back() [1/2]

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

Retrieves the last element in the buffer.

Definition at line 119 of file Types.hh.

◆ back() [2/2]

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

Retrieves the last element in the buffer.

Definition at line 125 of file Types.hh.

◆ begin() [1/2]

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

Definition at line 130 of file Types.hh.

◆ begin() [2/2]

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

Definition at line 138 of file Types.hh.

◆ empty()

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

Returns true if the buffer is uninitialized.

Definition at line 147 of file Types.hh.

◆ end() [1/2]

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

Definition at line 134 of file Types.hh.

◆ end() [2/2]

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

Definition at line 142 of file Types.hh.

◆ front() [1/2]

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

Retrieves the first element in the buffer.

Definition at line 107 of file Types.hh.

◆ front() [2/2]

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

Retrieves the first element in the buffer.

Definition at line 113 of file Types.hh.

◆ operator=() [1/2]

template<typename T >
owning_span & Kinoko::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 62 of file Types.hh.

◆ operator=() [2/2]

template<typename T >
owning_span & Kinoko::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 75 of file Types.hh.

◆ operator[]() [1/2]

template<typename T >
T & Kinoko::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 94 of file Types.hh.

◆ operator[]() [2/2]

template<typename T >
const T & Kinoko::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 101 of file Types.hh.

◆ size()

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

Returns the number of elements that fit in the buffer.

Definition at line 152 of file Types.hh.

◆ view()

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

Returns a read-only view of the entire buffer.

Definition at line 157 of file Types.hh.

Member Data Documentation

◆ m_data

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

Pointer to the underlying buffer.

Definition at line 162 of file Types.hh.

◆ m_size

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

The number of T elements that fit in the buffer.

Definition at line 163 of file Types.hh.