CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Box Class Reference

A value type that can hold any alongside it's type information. More...

#include <CeresEngine/Reflection/Box.hpp>

Inheritance diagram for CeresEngine::Box:
CeresEngine::Box::Array CeresEngine::Box::Iterable CeresEngine::Box::Iterator CeresEngine::Box::Map CeresEngine::Box::Pointer

Classes

class  Array
 
class  Iterable
 
class  Iterator
 
class  Map
 
class  Pointer
 
union  Storage
 A type that contains storage for the Box. More...
 
struct  TypeCastOperation
 Implementation for type casting in Box. More...
 
struct  TypeCheckOperation
 Implementation for type checks in Box. More...
 
struct  TypeConversionOperation
 Implementation for type conversion in Box. More...
 

Public Member Functions

 Box () noexcept
 Creates a new variant holding an empty value.
 
 Box (const Box &other)
 Creates a new variant by copying another, if possible.
 
Boxoperator= (const Box &other)
 Assigns a variant a new value by copying another, if possible.
 
 Box (Box &&other) noexcept
 Creates a new variant by moving another, if possible.
 
Boxoperator= (Box &&other) noexcept
 Assigns a variant a new value by moving another, if possible.
 
template<typename T >
requires (!std::is_same_v<std::decay_t<T>, Box>)
 Box (T &&value)
 Creates a new variant from a C++ value.
 
template<typename T >
requires (!std::is_same_v<std::decay_t<T>, Box>)
Boxoperator= (T &&value)
 Assigns the variant a new value a C++ value.
 
template<typename T >
requires (!std::is_same_v<T, Box>)
 Box (std::reference_wrapper< T > value)
 Creates a new variant from a C++ value.
 
template<typename T , typename... Args>
requires (!std::is_same_v<T, Box>)
 Box (std::in_place_type_t< T >, Args &&... args)
 
 Box (const void *ptr, const TypeInfo *typeInfo)
 
 ~Box () noexcept
 Destroys the variant. Will call the contained object destructor.
 
bool isSmall () const noexcept
 Determines if the value fits on the small buffer storage.
 
void clear () noexcept
 Clears the variant and makes it empty.
 
bool empty () const noexcept
 Checks if the variant is empty (i.e. holds no value).
 
 operator bool () const noexcept
 Checks if the variant is not empty (i.e. holds a value).
 
template<typename T >
bool eq (const T &value) const
 Checks if a variant holds the same value as another.
 
template<typename T >
bool neq (const T &value) const
 Checks if a variant holds the same value as another.
 
TypeID getTypeID () const noexcept
 Gets the ID of the type held by the variant.
 
Type getType () const noexcept
 Gets the type held by the variant.
 
Type getClassType () const noexcept
 Gets the type held by the variant.
 
const ClassgetClass () const noexcept
 
const EnumgetMetaEnum () const noexcept
 
template<typename T >
bool is () const
 Checks if the value held by the variant is T.
 
bool is (const Type &type) const
 
Box copy () const
 Makes a copy of the object.
 
Box ref () const &
 Gets a reference to the meta value.
 
Box cref () const &
 Gets a reference to the meta value.
 
Box rref () &&
 Gets a reference to the meta value.
 
Box ref () &&
 Gets a reference to the meta value.
 
template<typename T >
Tref () const &
 Gets the value of the variant as a reference to T.
 
template<>
Boxref () const &
 
template<typename T >
T && ref () &&
 Gets the value of the variant as a reference to T.
 
template<>
Box && ref () &&
 
template<typename T >
const Tcref () const
 Gets the value of the variant as a const reference to T.
 
template<>
const Boxcref () const
 
template<typename T >
T && rref () &&
 Gets the value of the variant as a r-value reference to T.
 
template<>
Box && rref () &&
 
voiddata () noexcept
 Returns pointer to decayed type.
 
const voiddata () const noexcept
 Returns pointer to decayed type.
 
template<typename T >
Tdata () const
 Gets the value of the variant as a pointer to const T.
 
template<typename T >
bool canConvert () const
 Checks if the value held by the variant is convertible to T.
 
bool canConvert (const TypeID &target) const
 Checks if the value held by the variant is convertible to T.
 
bool canConvert (const Type &target) const
 Checks if the value held by the variant is convertible to T.
 
bool canConvert (const TypeInfo &target) const
 Checks if the value held by the variant is convertible to T.
 
template<typename T >
T to () const &
 Gets the value of the variant as a T.
 
template<>
Box to () const &
 
Box to (const TypeID &target) const
 Gets the value of the variant as a T.
 
Box to (const Type &target) const
 Gets the value of the variant as a T.
 
Box to (const TypeInfo &target) const
 Gets the value of the variant as a T.
 
template<typename T >
void convert ()
 Converts the variant to type T.
 
template<typename T >
bool tryConvert ()
 Tries to convert the variant to type T.
 
Iterable asIterable () const &
 Views the Box as an Iterable type.
 
Iterable asIterable () &&
 
Iterator asIterator () const &
 Views the Box as an Iterator type.
 
Iterator asIterator () &&
 
Array asArray () const &
 Views the Box as an Array type.
 
Array asArray () &&
 
Map asMap () const &
 Views the Box as an Map type.
 
Map asMap () &&
 
Pointer asPointer () const &
 Views the Box as an Pointer type.
 
Pointer asPointer () &&
 

Static Public Member Functions

template<typename T , typename... Args>
static Box create (Args &&... args)
 

Private Member Functions

voidcast ()
 
voidstorage () noexcept
 Returns pointer to decayed type.
 
const voidstorage () const noexcept
 Returns pointer to decayed type.
 
voidallocate (const TypeInfo *typeInfo)
 
void destroy ()
 
void swap (Box &other) noexcept
 Swaps the values of two variants.
 
TypeID getInternalTypeID (TypeAttribute attr=TypeAttribute::NONE) const noexcept
 Gets the type ID for the given type attribute.
 
ClassInfo getClassInfo () const noexcept
 Gets the ClassInfo of the stored value.
 

Private Attributes

Storage mStorage
 The value storage.
 
const TypeInfomTypeInfo = nullptr
 The stored value type.
 

Static Private Attributes

static constexpr const size_t kSmallSize = sizeof(void*) * 2
 

Friends

class Type
 
class MetaArgument
 
bool operator== (const Box &lhs, const Box &rhs)
 Checks if a variant holds the same value as another.
 
bool operator!= (const Box &lhs, const Box &rhs)
 Checks if a variant holds the same value as another.
 
void swap (Box &, Box &) noexcept
 

Detailed Description

A value type that can hold any alongside it's type information.

Constructor & Destructor Documentation

◆ Box() [1/7]

CeresEngine::Box::Box ( )
noexcept

Creates a new variant holding an empty value.

◆ Box() [2/7]

CeresEngine::Box::Box ( const Box other)

Creates a new variant by copying another, if possible.

◆ Box() [3/7]

CeresEngine::Box::Box ( Box &&  other)
noexcept

Creates a new variant by moving another, if possible.

◆ Box() [4/7]

template<typename T >
requires (!std::is_same_v<std::decay_t<T>, Box>)
CeresEngine::Box::Box ( T &&  value)

Creates a new variant from a C++ value.

◆ Box() [5/7]

template<typename T >
requires (!std::is_same_v<T, Box>)
CeresEngine::Box::Box ( std::reference_wrapper< T value)

Creates a new variant from a C++ value.

◆ Box() [6/7]

template<typename T , typename... Args>
requires (!std::is_same_v<T, Box>)
CeresEngine::Box::Box ( std::in_place_type_t< T ,
Args &&...  args 
)
explicit

◆ Box() [7/7]

CeresEngine::Box::Box ( const void ptr,
const TypeInfo typeInfo 
)
explicit

◆ ~Box()

CeresEngine::Box::~Box ( )
noexcept

Destroys the variant. Will call the contained object destructor.

Member Function Documentation

◆ allocate()

void * CeresEngine::Box::allocate ( const TypeInfo typeInfo)
private

◆ asArray() [1/2]

Array CeresEngine::Box::asArray ( ) &&

◆ asArray() [2/2]

Array CeresEngine::Box::asArray ( ) const &

Views the Box as an Array type.

◆ asIterable() [1/2]

Iterable CeresEngine::Box::asIterable ( ) &&

◆ asIterable() [2/2]

Iterable CeresEngine::Box::asIterable ( ) const &

Views the Box as an Iterable type.

◆ asIterator() [1/2]

Iterator CeresEngine::Box::asIterator ( ) &&

◆ asIterator() [2/2]

Iterator CeresEngine::Box::asIterator ( ) const &

Views the Box as an Iterator type.

◆ asMap() [1/2]

Map CeresEngine::Box::asMap ( ) &&

◆ asMap() [2/2]

Map CeresEngine::Box::asMap ( ) const &

Views the Box as an Map type.

◆ asPointer() [1/2]

Pointer CeresEngine::Box::asPointer ( ) &&

◆ asPointer() [2/2]

Pointer CeresEngine::Box::asPointer ( ) const &

Views the Box as an Pointer type.

◆ canConvert() [1/4]

template<typename T >
bool CeresEngine::Box::canConvert ( ) const
inline

Checks if the value held by the variant is convertible to T.

Template Parameters
TThe check conversion.

◆ canConvert() [2/4]

bool CeresEngine::Box::canConvert ( const Type target) const
inline

Checks if the value held by the variant is convertible to T.

Template Parameters
TThe check conversion.

◆ canConvert() [3/4]

bool CeresEngine::Box::canConvert ( const TypeID target) const
inline

Checks if the value held by the variant is convertible to T.

Template Parameters
TThe check conversion.

◆ canConvert() [4/4]

bool CeresEngine::Box::canConvert ( const TypeInfo target) const

Checks if the value held by the variant is convertible to T.

Template Parameters
TThe check conversion.

◆ cast()

void * CeresEngine::Box::cast ( )
private

◆ clear()

void CeresEngine::Box::clear ( )
noexcept

Clears the variant and makes it empty.

◆ convert()

template<typename T >
void CeresEngine::Box::convert ( )
inline

Converts the variant to type T.

The variant will have it's value reassigned to the coverted value.

Template Parameters
TThe type to convert to.

◆ copy()

Box CeresEngine::Box::copy ( ) const

Makes a copy of the object.

Unlike the copy constructor, this method returns a copy even if the meta value points to a reference.

◆ create()

template<typename T , typename... Args>
static Box CeresEngine::Box::create ( Args &&...  args)
inlinestatic

◆ cref() [1/3]

template<typename T >
const T & CeresEngine::Box::cref ( ) const
inline

Gets the value of the variant as a const reference to T.

Template Parameters
TThe type to get the value as.

◆ cref() [2/3]

template<>
const Box & CeresEngine::Box::cref ( ) const
inline

◆ cref() [3/3]

Box CeresEngine::Box::cref ( ) const &

Gets a reference to the meta value.

If the value is already a reference, a copy of the reference is returned.

◆ data() [1/3]

template<typename T >
T * CeresEngine::Box::data ( ) const
inline

Gets the value of the variant as a pointer to const T.

If the type doesn't match, nullptr is returned.

Template Parameters
TThe type to get the value as.

◆ data() [2/3]

const void * CeresEngine::Box::data ( ) const
noexcept

Returns pointer to decayed type.

◆ data() [3/3]

void * CeresEngine::Box::data ( )
inlinenoexcept

Returns pointer to decayed type.

◆ destroy()

void CeresEngine::Box::destroy ( )
private

◆ empty()

bool CeresEngine::Box::empty ( ) const
noexcept

Checks if the variant is empty (i.e. holds no value).

◆ eq()

template<typename T >
bool CeresEngine::Box::eq ( const T value) const

Checks if a variant holds the same value as another.

◆ getClass()

const Class * CeresEngine::Box::getClass ( ) const
noexcept

◆ getClassInfo()

ClassInfo CeresEngine::Box::getClassInfo ( ) const
privatenoexcept

Gets the ClassInfo of the stored value.

◆ getClassType()

Type CeresEngine::Box::getClassType ( ) const
noexcept

Gets the type held by the variant.

◆ getInternalTypeID()

TypeID CeresEngine::Box::getInternalTypeID ( TypeAttribute  attr = TypeAttribute::NONE) const
privatenoexcept

Gets the type ID for the given type attribute.

◆ getMetaEnum()

const Enum * CeresEngine::Box::getMetaEnum ( ) const
noexcept

◆ getType()

Type CeresEngine::Box::getType ( ) const
noexcept

Gets the type held by the variant.

◆ getTypeID()

TypeID CeresEngine::Box::getTypeID ( ) const
inlinenoexcept

Gets the ID of the type held by the variant.

◆ is() [1/2]

template<typename T >
bool CeresEngine::Box::is ( ) const
inline

Checks if the value held by the variant is T.

◆ is() [2/2]

bool CeresEngine::Box::is ( const Type type) const

◆ isSmall()

bool CeresEngine::Box::isSmall ( ) const
noexcept

Determines if the value fits on the small buffer storage.

◆ neq()

template<typename T >
bool CeresEngine::Box::neq ( const T value) const
inline

Checks if a variant holds the same value as another.

◆ operator bool()

CeresEngine::Box::operator bool ( ) const
inlineexplicitnoexcept

Checks if the variant is not empty (i.e. holds a value).

◆ operator=() [1/3]

Box & CeresEngine::Box::operator= ( Box &&  other)
noexcept

Assigns a variant a new value by moving another, if possible.

◆ operator=() [2/3]

Box & CeresEngine::Box::operator= ( const Box other)

Assigns a variant a new value by copying another, if possible.

◆ operator=() [3/3]

template<typename T >
requires (!std::is_same_v<std::decay_t<T>, Box>)
Box & CeresEngine::Box::operator= ( T &&  value)

Assigns the variant a new value a C++ value.

◆ ref() [1/6]

Box CeresEngine::Box::ref ( ) &&
inline

Gets a reference to the meta value.

If the value is already a reference, a copy of the reference is returned.

◆ ref() [2/6]

template<typename T >
T && CeresEngine::Box::ref ( ) &&
inline

Gets the value of the variant as a reference to T.

Template Parameters
TThe type to get the value as.

◆ ref() [3/6]

template<>
Box && CeresEngine::Box::ref ( ) &&
inline

◆ ref() [4/6]

Box CeresEngine::Box::ref ( ) const &

Gets a reference to the meta value.

If the value is already a reference, a copy of the reference is returned.

◆ ref() [5/6]

template<typename T >
T & CeresEngine::Box::ref ( ) const &
inline

Gets the value of the variant as a reference to T.

Template Parameters
TThe type to get the value as.

◆ ref() [6/6]

template<>
Box & CeresEngine::Box::ref ( ) const &
inline

◆ rref() [1/3]

Box CeresEngine::Box::rref ( ) &&

Gets a reference to the meta value.

If the value is already a reference, a copy of the reference is returned.

◆ rref() [2/3]

template<typename T >
T && CeresEngine::Box::rref ( ) &&
inline

Gets the value of the variant as a r-value reference to T.

Template Parameters
TThe type to get the value as.

◆ rref() [3/3]

template<>
Box && CeresEngine::Box::rref ( ) &&
inline

◆ storage() [1/2]

const void * CeresEngine::Box::storage ( ) const
inlineprivatenoexcept

Returns pointer to decayed type.

◆ storage() [2/2]

void * CeresEngine::Box::storage ( )
inlineprivatenoexcept

Returns pointer to decayed type.

◆ swap()

void CeresEngine::Box::swap ( Box other)
privatenoexcept

Swaps the values of two variants.

Parameters
otherThe other variant to swap the value with.

◆ to() [1/5]

template<typename T >
T CeresEngine::Box::to ( ) const &
inline

Gets the value of the variant as a T.

Will perform a conversion if one is available and needed.

Template Parameters
TThe type to get the value as.

◆ to() [2/5]

template<>
Box CeresEngine::Box::to ( ) const &
inline

◆ to() [3/5]

Box CeresEngine::Box::to ( const Type target) const
inline

Gets the value of the variant as a T.

Will perform a conversion if one is available and needed.

Template Parameters
TThe type to get the value as.

◆ to() [4/5]

Box CeresEngine::Box::to ( const TypeID target) const
inline

Gets the value of the variant as a T.

Will perform a conversion if one is available and needed.

Template Parameters
TThe type to get the value as.

◆ to() [5/5]

Box CeresEngine::Box::to ( const TypeInfo target) const

Gets the value of the variant as a T.

Will perform a conversion if one is available and needed.

Template Parameters
TThe type to get the value as.

◆ tryConvert()

template<typename T >
bool CeresEngine::Box::tryConvert ( )
inline

Tries to convert the variant to type T.

The variant will have it's value reassigned to the coverted value.

Returns
true if the conversion was sucesfull, false otherwise.
Template Parameters
TThe type to convert to.

Friends And Related Symbol Documentation

◆ MetaArgument

◆ operator!=

bool operator!= ( const Box lhs,
const Box rhs 
)
friend

Checks if a variant holds the same value as another.

◆ operator==

bool operator== ( const Box lhs,
const Box rhs 
)
friend

Checks if a variant holds the same value as another.

◆ swap

void swap ( Box lhs,
Box rhs 
)
friend

◆ Type

friend class Type
friend

Member Data Documentation

◆ kSmallSize

constexpr const size_t CeresEngine::Box::kSmallSize = sizeof(void*) * 2
staticconstexprprivate

◆ mStorage

Storage CeresEngine::Box::mStorage
private

The value storage.

◆ mTypeInfo

const TypeInfo* CeresEngine::Box::mTypeInfo = nullptr
private

The stored value type.


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