CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::ValuePtr< T, SmallSize > Class Template Referencefinal

A pointer type that has value semantics. More...

#include <CeresEngine/Foundation/SmartPtr.hpp>

Classes

struct  ConstructTag
 A tag used for tagged dispatching the object constructing constructor. More...
 
struct  VTable
 

Public Member Functions

bool isCopyable () const noexcept
 Checks if the ValuePtr copy constructor can be safely called.
 
 ValuePtr (const ValuePtr &other)
 Creates a new ValuePtr by copying an existing one.
 
ValuePtroperator= (const ValuePtr &other)
 Assigns a ValuePtr by copying an existing one.
 
bool isMovable () const noexcept
 Checks if the ValuePtr move constructor can be safely called.
 
 ValuePtr (ValuePtr &&other) noexcept
 Creates a new ValuePtr by moving an existing one.
 
ValuePtroperator= (ValuePtr &&other)
 Assigns a ValuePtr by moving an existing one.
 
 ValuePtr (std::nullptr_t) noexcept
 Creates a new empty ValuePtr.
 
ValuePtroperator= (std::nullptr_t) noexcept
 Assigns the ValuePtr a nullptr value.
 
 ~ValuePtr () noexcept
 Destroys the ValuePtr and destroys the object is present.
 
template<bool B = std::is_default_constructible_v<T>&& std::is_copy_constructible_v<T>, typename = std::enable_if_t<B>>
 ValuePtr () noexcept
 Creates a new empty ValuePtr.
 
template<typename... Args, typename = std::enable_if_t<std::is_constructible_v<T, Args...>>>
 ValuePtr (Args &&... args)
 Creates a new ValuePtr that holds a newly constructed object of type T.
 
template<typename TT >
requires (std::is_convertible_v<TT*, T*>)
 ValuePtr (TT object)
 Creates a new ValuePtr that holds a copy constructed object of type TT.
 
template<typename TT , typename... Args, typename = std::enable_if_t<std::is_constructible_v<TT, Args...>>>
TTemplace (Args &&... args)
 Emplace a new object of type TT into the ValuePtr.
 
bool valid () const
 Checks if the pointer has a valid object stored in it.
 
bool empty () const
 Checks if the pointer has a valid object stored in it.
 
Tget () const
 
void reset ()
 Resets the stored object into an empty state.
 
 operator bool () const
 Checks if the pointer has a valid object stored in it.
 
Toperator-> () const
 
Toperator* () const
 

Static Public Member Functions

template<typename... Args>
static ValuePtr< T, SmallSizecreate (Args &&... args)
 Create a new ValuePtr with an object of type T
 
template<typename U , typename... Args>
static ValuePtr< T, SmallSizecreate (Args &&... args)
 Create a new ValuePtr with an object of type U
 

Static Public Attributes

template<typename U >
static constexpr bool isSmall = sizeof(U) <= SmallSize
 true if an object of type U will cause an allocation.
 

Private Member Functions

template<typename TT , typename... Args, typename = std::enable_if_t<std::is_convertible_v<TT*, T*> && std::is_constructible_v<TT, Args...>>>
 ValuePtr (ConstructTag< TT >, Args &&... args)
 Creates a new ValuePtr that holds a newly constructed object of type TT.
 

Private Attributes

const VTablevtable = nullptr
 A VTable that contains implementation for copy, move and destroy.
 
UInt8 raw [SmallSize]
 The underlying storage memory.
 

Detailed Description

template<typename T, size_t SmallSize = sizeof(int*) * 4>
class CeresEngine::ValuePtr< T, SmallSize >

A pointer type that has value semantics.

When creating a new ValuePtr, an object of type T or that has T as a base is created. When copying ValuePtr objects, the object is copied by calling its copy constructor.

When a ValuePtr is destroyed any object that might be contained in it is also destroyed.

Template Parameters
Tthe object type
SmallSizeif the concrete object is up to this size, it will be allocated on internal storage and no heap allocation will take place. By default, limits to the size of 4 ints.

Constructor & Destructor Documentation

◆ ValuePtr() [1/7]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
CeresEngine::ValuePtr< T, SmallSize >::ValuePtr ( const ValuePtr< T, SmallSize > &  other)
inline

Creates a new ValuePtr by copying an existing one.

Parameters
otherThe instance to copy from

◆ ValuePtr() [2/7]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
CeresEngine::ValuePtr< T, SmallSize >::ValuePtr ( ValuePtr< T, SmallSize > &&  other)
inlinenoexcept

Creates a new ValuePtr by moving an existing one.

Parameters
otherThe instance to move from

◆ ValuePtr() [3/7]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
CeresEngine::ValuePtr< T, SmallSize >::ValuePtr ( std::nullptr_t  )
inlinenoexcept

Creates a new empty ValuePtr.

◆ ~ValuePtr()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
CeresEngine::ValuePtr< T, SmallSize >::~ValuePtr ( )
inlinenoexcept

Destroys the ValuePtr and destroys the object is present.

◆ ValuePtr() [4/7]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<typename TT , typename... Args, typename = std::enable_if_t<std::is_convertible_v<TT*, T*> && std::is_constructible_v<TT, Args...>>>
CeresEngine::ValuePtr< T, SmallSize >::ValuePtr ( ConstructTag< TT ,
Args &&...  args 
)
inlineexplicitprivate

Creates a new ValuePtr that holds a newly constructed object of type TT.

Template Parameters
TTthe object type
Argsthe object constructor argument types
Parameters
argsThe object constructor arguments

◆ ValuePtr() [5/7]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<bool B = std::is_default_constructible_v<T>&& std::is_copy_constructible_v<T>, typename = std::enable_if_t<B>>
CeresEngine::ValuePtr< T, SmallSize >::ValuePtr ( )
inlinenoexcept

Creates a new empty ValuePtr.

◆ ValuePtr() [6/7]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<typename... Args, typename = std::enable_if_t<std::is_constructible_v<T, Args...>>>
CeresEngine::ValuePtr< T, SmallSize >::ValuePtr ( Args &&...  args)
inlineexplicit

Creates a new ValuePtr that holds a newly constructed object of type T.

Template Parameters
Argsthe object constructor argument types
Parameters
argsThe object constructor arguments

◆ ValuePtr() [7/7]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<typename TT >
requires (std::is_convertible_v<TT*, T*>)
CeresEngine::ValuePtr< T, SmallSize >::ValuePtr ( TT  object)
inline

Creates a new ValuePtr that holds a copy constructed object of type TT.

Template Parameters
TTthe object type

Member Function Documentation

◆ create() [1/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<typename... Args>
static ValuePtr< T, SmallSize > CeresEngine::ValuePtr< T, SmallSize >::create ( Args &&...  args)
inlinestatic

Create a new ValuePtr with an object of type T

Template Parameters
Argsthe constructor argument types of T
Parameters
argsThe constructor arguments of T
Returns
A ValuePtr<T> holding an object of type T

◆ create() [2/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<typename U , typename... Args>
static ValuePtr< T, SmallSize > CeresEngine::ValuePtr< T, SmallSize >::create ( Args &&...  args)
inlinestatic

Create a new ValuePtr with an object of type U

Template Parameters
Uthe object type to be created
Argsthe constructor argument types of U
Parameters
argsThe constructor arguments of U
Returns
A ValuePtr<T> holding an object of type U

◆ emplace()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<typename TT , typename... Args, typename = std::enable_if_t<std::is_constructible_v<TT, Args...>>>
TT & CeresEngine::ValuePtr< T, SmallSize >::emplace ( Args &&...  args)
inline

Emplace a new object of type TT into the ValuePtr.

Template Parameters
TTthe object type
Argsthe object constructor argument types
Parameters
argsThe object constructor arguments

◆ empty()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
bool CeresEngine::ValuePtr< T, SmallSize >::empty ( ) const
inline

Checks if the pointer has a valid object stored in it.

Returns
true if the stored object is not valid

◆ get()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
T * CeresEngine::ValuePtr< T, SmallSize >::get ( ) const
inline
Returns
A pointer to the stored object, if any.

◆ isCopyable()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
bool CeresEngine::ValuePtr< T, SmallSize >::isCopyable ( ) const
inlinenoexcept

Checks if the ValuePtr copy constructor can be safely called.

◆ isMovable()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
bool CeresEngine::ValuePtr< T, SmallSize >::isMovable ( ) const
inlinenoexcept

Checks if the ValuePtr move constructor can be safely called.

◆ operator bool()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
CeresEngine::ValuePtr< T, SmallSize >::operator bool ( ) const
inlineexplicit

Checks if the pointer has a valid object stored in it.

Returns
true if the stored object is valid

◆ operator*()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
T & CeresEngine::ValuePtr< T, SmallSize >::operator* ( ) const
inline
Returns
A reference to the stored object

◆ operator->()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
T * CeresEngine::ValuePtr< T, SmallSize >::operator-> ( ) const
inline
Returns
A pointer to the stored object

◆ operator=() [1/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
ValuePtr & CeresEngine::ValuePtr< T, SmallSize >::operator= ( const ValuePtr< T, SmallSize > &  other)
inline

Assigns a ValuePtr by copying an existing one.

Parameters
otherThe instance to copy from
Returns
*this

◆ operator=() [2/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
ValuePtr & CeresEngine::ValuePtr< T, SmallSize >::operator= ( std::nullptr_t  )
inlinenoexcept

Assigns the ValuePtr a nullptr value.

Returns
*this

◆ operator=() [3/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4>
ValuePtr & CeresEngine::ValuePtr< T, SmallSize >::operator= ( ValuePtr< T, SmallSize > &&  other)
inline

Assigns a ValuePtr by moving an existing one.

Parameters
otherThe instance to move from
Returns
*this

◆ reset()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
void CeresEngine::ValuePtr< T, SmallSize >::reset ( )
inline

Resets the stored object into an empty state.

If an object is present, it will be deconstructed.

◆ valid()

template<typename T , size_t SmallSize = sizeof(int*) * 4>
bool CeresEngine::ValuePtr< T, SmallSize >::valid ( ) const
inline

Checks if the pointer has a valid object stored in it.

Returns
true if the stored object is valid

Member Data Documentation

◆ isSmall

template<typename T , size_t SmallSize = sizeof(int*) * 4>
template<typename U >
constexpr bool CeresEngine::ValuePtr< T, SmallSize >::isSmall = sizeof(U) <= SmallSize
inlinestaticconstexpr

true if an object of type U will cause an allocation.

◆ raw

template<typename T , size_t SmallSize = sizeof(int*) * 4>
UInt8 CeresEngine::ValuePtr< T, SmallSize >::raw[SmallSize]
mutableprivate

The underlying storage memory.

◆ vtable

template<typename T , size_t SmallSize = sizeof(int*) * 4>
const VTable* CeresEngine::ValuePtr< T, SmallSize >::vtable = nullptr
private

A VTable that contains implementation for copy, move and destroy.


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