CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Poly< T, SmallSize, Copyable, BaseType > Class Template Reference

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

#include <CeresEngine/Foundation/Poly.hpp>

Classes

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

Public Member Functions

bool isCopyable () const noexcept
 Checks if the Poly copy constructor can be safely called.
 
 Poly (const Poly &other)
 Creates a new Poly by copying an existing one.
 
Polyoperator= (const Poly &other)
 Assigns a Poly by copying an existing one.
 
bool isMovable () const noexcept
 Checks if the Poly move constructor can be safely called.
 
 Poly (Poly &&other) noexcept
 Creates a new Poly by moving an existing one.
 
Polyoperator= (Poly &&other)
 Assigns a Poly by moving an existing one.
 
 Poly (std::nullptr_t) noexcept
 Creates a new empty Poly.
 
Polyoperator= (std::nullptr_t) noexcept
 Assigns the Poly a nullptr value.
 
 ~Poly () noexcept
 Destroys the Poly and destroys the object is present.
 
template<typename TT = T>
requires (std::is_default_constructible_v<TT>)
 Poly () noexcept
 Creates a new empty Poly.
 
template<typename TT , typename... Args>
requires (std::is_convertible_v<TT*, T*>&& std::is_constructible_v<TT, Args&&...>)
 Poly (std::in_place_type_t< TT >, Args &&... args)
 Creates a new Poly that holds a newly constructed object of type TT.
 
template<typename... Args>
requires (std::is_constructible_v<T, Args...>)
 Poly (Args &&... args)
 Creates a new Poly that holds a newly constructed object of type T.
 
template<typename TT >
requires (std::is_convertible_v<TT*, T*> && Copyable)
 Poly (TT object)
 Creates a new Poly that holds a copy constructed object of type TT.
 
template<typename TT >
requires (std::is_convertible_v<TT*, T*> && !Copyable)
 Poly (TT &&object)
 Creates a new Poly that holds a copy constructed object of type TT.
 
 Poly (T *const instance)
 Creates a new Poly instance by referencing another.
 
template<typename TT , typename... Args>
requires std::is_constructible_v<TT, Args...>
TTemplace (Args &&... args)
 Emplace a new object of type TT into the Poly.
 
template<typename TT >
TTemplace (TT &&instance)
 
template<typename U >
requires (Copyable)
 Poly (const Poly< U, SmallSize, Copyable, BaseType > &other)
 Creates a new Poly instance by referencing another.
 
template<typename U >
 Poly (Poly< U, SmallSize, Copyable, BaseType > &&other)
 Creates a new Poly instance by referencing another.
 
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.
 
 operator bool () const
 Checks if the pointer has a valid object stored in it.
 
Tget ()
 
const Tget () const
 
Toperator-> ()
 
const Toperator-> () const
 
const Toperator* () const &
 
Toperator* () &
 &
 
T && operator* () &&
 &
 
const std::type_info & getTypeID () const
 
template<typename TT >
requires std::is_convertible_v<TT*, T*>
bool is () const
 Checks if the hold object is of type TT.
 
template<typename TT >
requires std::is_convertible_v<TT*, T*>
TTbeing ()
 Safely casts the hold type to TT.
 
template<typename TT >
requires std::is_convertible_v<TT*, T*>
const TTbeing () const
 Safely casts the hold type to TT.
 
template<typename TT >
requires std::is_convertible_v<TT*, T*>
TTas () &
 Casts the hold type to TT.
 
template<typename TT >
requires std::is_convertible_v<TT*, T*>
TT && as () &&
 Casts the hold type to TT.
 
template<typename TT >
requires std::is_convertible_v<TT*, T*>
const TTas () const &
 Casts the hold type to TT.
 

Static Public Attributes

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

Private Types

using Implementation = impl::PolyImplementation< BaseType >
 

Private Member Functions

template<typename TT , typename... Args>
requires (std::is_convertible_v<TT*, T*>&& std::is_constructible_v<TT, Args&&...>)
 Poly (ConstructTag< TT >, Args &&... args)
 Creates a new Poly that holds a newly constructed object of type TT.
 
void reset ()
 Resets the stored object into an empty state.
 

Static Private Member Functions

template<typename TT >
static const Implementationcreate ()
 Creates a new implementation for the concrete type TT.
 
static const ImplementationgetReference ()
 Gets the implementation table for referencing the polymorphic object as a reference.
 

Private Attributes

Byte mRaw [SmallSize]
 The underlying storage memory.
 
const ImplementationmImplementation = nullptr
 A Implementation that contains implementation for copy, move and destroy.
 

Friends

template<typename , size_t , bool , typename >
class Poly
 

Detailed Description

template<typename T, size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
class CeresEngine::Poly< T, SmallSize, Copyable, BaseType >

A pointer type that has value semantics.

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

When a Poly 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.
CopyableIf true, indicates that the Poly object is copyable.

Member Typedef Documentation

◆ Implementation

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
using CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Implementation = impl::PolyImplementation<BaseType>
private

Constructor & Destructor Documentation

◆ Poly() [1/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( const Poly< T, SmallSize, Copyable, BaseType > &  other)
inline

Creates a new Poly by copying an existing one.

Parameters
otherThe instance to copy from

◆ Poly() [2/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( Poly< T, SmallSize, Copyable, BaseType > &&  other)
inlinenoexcept

Creates a new Poly by moving an existing one.

Parameters
otherThe instance to move from

◆ Poly() [3/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( std::nullptr_t  )
inlinenoexcept

Creates a new empty Poly.

◆ ~Poly()

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::~Poly ( )
inlinenoexcept

Destroys the Poly and destroys the object is present.

◆ Poly() [4/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT , typename... Args>
requires (std::is_convertible_v<TT*, T*>&& std::is_constructible_v<TT, Args&&...>)
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( ConstructTag< TT ,
Args &&...  args 
)
inlineexplicitprivate

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

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

◆ Poly() [5/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT = T>
requires (std::is_default_constructible_v<TT>)
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( )
inlinenoexcept

Creates a new empty Poly.

◆ Poly() [6/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT , typename... Args>
requires (std::is_convertible_v<TT*, T*>&& std::is_constructible_v<TT, Args&&...>)
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( std::in_place_type_t< TT ,
Args &&...  args 
)
inlineexplicit

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

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

◆ Poly() [7/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename... Args>
requires (std::is_constructible_v<T, Args...>)
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( Args &&...  args)
inlineexplicit

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

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

◆ Poly() [8/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires (std::is_convertible_v<TT*, T*> && Copyable)
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( TT  object)
inline

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

Template Parameters
TTthe object type

◆ Poly() [9/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires (std::is_convertible_v<TT*, T*> && !Copyable)
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( TT &&  object)
inline

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

Template Parameters
TTthe object type

◆ Poly() [10/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( T *const  instance)
inline

Creates a new Poly instance by referencing another.

This will not copy the object and will always reference to the original instance.

Parameters
instanceThe instance to create a new Poly reference from.

◆ Poly() [11/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename U >
requires (Copyable)
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( const Poly< U, SmallSize, Copyable, BaseType > &  other)
inline

Creates a new Poly instance by referencing another.

This will not copy the object and will always reference to the original instance.

Parameters
instanceThe instance to create a new Poly reference from.

◆ Poly() [12/12]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename U >
CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::Poly ( Poly< U, SmallSize, Copyable, BaseType > &&  other)
inline

Creates a new Poly instance by referencing another.

This will not copy the object and will always reference to the original instance.

Parameters
instanceThe instance to create a new Poly reference from.

Member Function Documentation

◆ as() [1/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires std::is_convertible_v<TT*, T*>
TT & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::as ( ) &
inline

Casts the hold type to TT.

If the type is invalid, the behavior is undefined.

Template Parameters
TTthe type to cast to
Returns
The casted object

◆ as() [2/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires std::is_convertible_v<TT*, T*>
TT && CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::as ( ) &&
inline

Casts the hold type to TT.

If the type is invalid, the behavior is undefined.

Template Parameters
TTthe type to cast to
Returns
The casted object

◆ as() [3/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires std::is_convertible_v<TT*, T*>
const TT & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::as ( ) const &
inline

Casts the hold type to TT.

If the type is invalid, the behavior is undefined.

Template Parameters
TTthe type to cast to
Returns
The casted object

◆ being() [1/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires std::is_convertible_v<TT*, T*>
TT * CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::being ( )
inline

Safely casts the hold type to TT.

If the type is invalid, nullptr is returned.

Template Parameters
TTthe type to cast to
Returns
The casted object or nullptr if TT is not the hold type.

◆ being() [2/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires std::is_convertible_v<TT*, T*>
const TT * CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::being ( ) const
inline

Safely casts the hold type to TT.

If the type is invalid, nullptr is returned.

Template Parameters
TTthe type to cast to
Returns
The casted object or nullptr if TT is not the hold type.

◆ create()

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
static const Implementation * CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::create ( )
inlinestaticprivate

Creates a new implementation for the concrete type TT.

◆ emplace() [1/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT , typename... Args>
requires std::is_constructible_v<TT, Args...>
TT & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::emplace ( Args &&...  args)
inline

Emplace a new object of type TT into the Poly.

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

◆ emplace() [2/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
TT & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::emplace ( TT &&  instance)
inline

◆ empty()

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

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

Returns
true if the stored object is valid

◆ get() [1/2]

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

◆ get() [2/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
const T * CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::get ( ) const
inline

Returns
A pointer to the stored object, if any.

◆ getReference()

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
static const Implementation * CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::getReference ( )
inlinestaticprivate

Gets the implementation table for referencing the polymorphic object as a reference.

◆ getTypeID()

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
const std::type_info & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::getTypeID ( ) const
inline
Returns
The std::type_info of the hold object type

◆ is()

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename TT >
requires std::is_convertible_v<TT*, T*>
bool CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::is ( ) const
inline

Checks if the hold object is of type TT.

This can be costly.

Template Parameters
TTthe type to check for
Returns
true if the hold type is TT.

◆ isCopyable()

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

Checks if the Poly copy constructor can be safely called.

◆ isMovable()

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

Checks if the Poly move constructor can be safely called.

◆ operator bool()

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

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

Returns
true if the stored object is valid

◆ operator*() [1/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
T & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::operator* ( ) &
inline

&

&

◆ operator*() [2/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
T && CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::operator* ( ) &&
inline

&

&

◆ operator*() [3/3]

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

◆ operator->() [1/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
T * CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::operator-> ( )
inline
Returns
A pointer to the stored object

◆ operator->() [2/2]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
const T * CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::operator-> ( ) const
inline

Returns
A pointer to the stored object

◆ operator=() [1/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
Poly & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::operator= ( const Poly< T, SmallSize, Copyable, BaseType > &  other)
inline

Assigns a Poly 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, bool Copyable = true, typename BaseType = T>
Poly & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::operator= ( Poly< T, SmallSize, Copyable, BaseType > &&  other)
inline

Assigns a Poly by moving an existing one.

Parameters
otherThe instance to move from
Returns
*this

◆ operator=() [3/3]

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
Poly & CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::operator= ( std::nullptr_t  )
inlinenoexcept

Assigns the Poly a nullptr value.

Returns
*this

◆ reset()

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
void CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::reset ( )
inlineprivate

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 Copyable = true, typename BaseType = T>
bool CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::valid ( ) const
inline

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

Returns
true if the stored object is valid

Friends And Related Symbol Documentation

◆ Poly

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename , size_t , bool , typename >
friend class Poly
friend

Member Data Documentation

◆ isSmall

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
template<typename U >
constexpr bool CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::isSmall = sizeof(U) <= SmallSize&& std::is_move_constructible_v<U>
inlinestaticconstexpr

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

◆ mImplementation

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
const Implementation* CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::mImplementation = nullptr
private

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

◆ mRaw

template<typename T , size_t SmallSize = sizeof(int*) * 4, bool Copyable = true, typename BaseType = T>
Byte CeresEngine::Poly< T, SmallSize, Copyable, BaseType >::mRaw[SmallSize]
mutableprivate

The underlying storage memory.


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