cubos::core::reflection::Type class final

Describes a reflected type.

Holds the name of a type and the traits associated with it. Traits can be of any type, which means you can define your own custom traits.

Public static functions

static auto create(std::string name) -> Type&
Constructs with a type the given name.
static void destroy(Type& type)
Destroys the given type.

Public functions

auto name() const -> const std::string&
Returns the name of the type.
auto shortName() const -> const std::string&
Returns the name of the type without any namespaces.
template<typename T>
auto is() const -> bool
Checks if this type represents the type T.
template<typename T>
auto with(T trait) -> Type&
Adds the given trait to the type.
auto with(const Type& type, void* trait, void(*)(void*) deleter) -> Type&
Adds the given trait to the type.
template<typename T>
auto has() const -> bool
Returns whether the type has the given trait.
auto has(const Type& type) const -> bool
Returns whether the type has the given trait.
template<typename T>
auto get() const -> const T&
Returns the given trait of the type.
auto get(const Type& type) const -> const void*
Returns the given trait of the type.
auto operator==(const Type& other) const -> bool
Equality operator.

Function documentation

static Type& cubos::core::reflection::Type::create(std::string name)

Constructs with a type the given name.

Parameters
name Name of the type.
Returns Reference to the type.

static void cubos::core::reflection::Type::destroy(Type& type)

Destroys the given type.

Parameters
type Type to destroy.

const std::string& cubos::core::reflection::Type::name() const

Returns the name of the type.

Returns Name of the type.

const std::string& cubos::core::reflection::Type::shortName() const

Returns the name of the type without any namespaces.

Returns Name of the type without any namespaces.

template<typename T>
bool cubos::core::reflection::Type::is() const

Checks if this type represents the type T.

Template parameters
T Type to check.
Returns Whether this type represents the type T.

template<typename T>
Type& cubos::core::reflection::Type::with(T trait)

Adds the given trait to the type.

Template parameters
T Trait type.
Parameters
trait Trait value.
Returns Reference to this type, for chaining.

Aborts if the trait is already present in the type.

Type& cubos::core::reflection::Type::with(const Type& type, void* trait, void(*)(void*) deleter)

Adds the given trait to the type.

Parameters
type
trait Allocated trait value.
deleter Used to delete the trait when the type is destroyed.
Returns Reference to this type, for chaining.

template<typename T>
bool cubos::core::reflection::Type::has() const

Returns whether the type has the given trait.

Template parameters
T Trait type.
Returns Whether the type has the given trait.

bool cubos::core::reflection::Type::has(const Type& type) const

Returns whether the type has the given trait.

Returns Whether the type has the given trait.

template<typename T>
const T& cubos::core::reflection::Type::get() const

Returns the given trait of the type.

Template parameters
T Trait type.
Returns Reference to the trait.

Aborts if the type does not have the given trait.

const void* cubos::core::reflection::Type::get(const Type& type) const

Returns the given trait of the type.

Parameters
type Trait type.
Returns Pointer to the trait.

Aborts if the type does not have the given trait.

bool cubos::core::reflection::Type::operator==(const Type& other) const

Equality operator.

Parameters
other Type object to compare.
Returns Whether the objects have the same address, which indicates equality.