Cogs.Foundation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Cogs::Reflection::Type Class Reference

Represents a discrete type definition, describing a native type class. More...

#include <Type.h>

Public Member Functions

 Type ()=default
 Default constructor.
 
 Type (const Type &other)=delete
 Copying type instances is disallowed.
 
 Type (Type &&other) noexcept=default
 Default move constructor.
 
Typeoperator= (const Type &other)=delete
 Disallow copy assignment.
 
Typeoperator= (Type &&other) noexcept=delete
 Default move assignment.
 
template<size_t count>
TypesetFields (Field(&fields)[count])
 Set the fields of the type to the given array of field instances.
 
template<size_t count>
TypesetMethods (Method(&functions)[count])
 Set the methods of the type to the given array of method instances.
 
TypesetMethods (Method *functions, size_t count)
 Set the methods of the type to the given method instances.
 
template<size_t count>
TypesetEnumerators (const EnumeratorDef(&enumerators)[count])
 Set the enumerators of the type to the given array of enumerator instances.
 
TypesetEnumerators (const EnumeratorDef *enumerators, size_t count)
 Set the enumerators of the type to the given enumerator instances.
 
TypesetBase (const Type *base)
 Set the base type of this base. If base is nullptr, there will be no base type.
 
template<typename BaseType >
TypesetBase ()
 Set the base of this type to the given type.
 
const TypegetBase () const
 Get the base type.
 
template<typename DestinationType >
bool canCastTo () const
 Check if this type can be cast to the destination type.
 
bool canCastTo (const Type &destination) const
 Check if this type can be cast to the destination type.
 
bool canCastTo (const TypeId &destinationId) const
 Check if this type can be cast to the destination type.
 
constexpr bool operator== (const Type &other) const
 Check if this type is equal to other.
 
constexpr const NamegetName () const
 Get the unique name of the type.
 
constexpr size_t getSize () const
 Get the size of an instance of the reflected type, in bytes.
 
const FieldgetField (const Name &name) const
 Get a pointer to the field info of the field with the given name.
 
FieldId getFieldId (const Field *field) const
 Get the Reflection::FieldId of the given field.
 
size_t getNumFields () const
 Get the number of fields in the type.
 
size_t getNumHierarchyFields () const
 Get the number of fields in the type + types in all base types.
 
const FieldgetField (const FieldId id) const
 Get a pointer to the field with the given id.
 
FieldId getFieldId (size_t offset) const
 Get the id of the field located at offset bytes from the start of the structure.
 
template<typename ClassType , typename FieldType >
FieldId getFieldId (FieldType ClassType::*field) const
 Get the id of the field given by pointer to member.
 
const MethodgetMethod (const Name &name) const
 Get a pointer to the method with the given name.
 
MethodId getMethodId (const Method *method) const
 Get the Reflection::MethodId of the given method.
 
const MethodgetMethod (const MethodId id) const
 Get a pointer to the method with the given id.
 
const EnumeratorgetEnumerator (const Name &name) const
 Get a pointer to the enumerator with the given name.
 
const EnumeratorgetEnumerator (const size_t index) const
 Get the enumerator with the given index.
 
bool isEnum () const
 Get if the type is an enumeration type.
 
size_t getNumEnumerators () const
 Get the number of enumerators in the type.
 
constexpr TypeId getTypeId () const
 Get the unique Reflection::TypeId of this instance.
 
constexpr bool isValid () const
 Gets if the type is considered a valid, registered type.
 
constexpr void setFlags (uint32_t flags)
 Set type flags.
 
bool isEnumFlags () const
 Get if the type is a flag enumeration type.
 
constexpr TypesetEnumFlags ()
 Indicate the type is a flag enum.
 
template<typename BaseType >
Cogs::Reflection::TypesetBase ()
 

Static Public Member Functions

static FieldId getFieldId (TypeId componentTypeId, const Name &name)
 Utility to Lookup component type and get field with given name.
 

Private Member Functions

TypesetFields (Field *fields, size_t count)
 

Private Attributes

Name name
 Unique name of the type.
 
size_t size = 0
 Size of an instance of a class with this type in bytes.
 
uint32_t flags = TypeFlags::None
 Type flags.
 
TypeId typeId = NoType
 Unique type id for this type.
 
TypeId base = NoType
 Reflection::TypeId of the Type this type is derived from. Reflection::NoType if no base exists.
 
std::vector< Fieldfields
 Collection of fields available on the type.
 
std::vector< Methodmethods
 Collection of methods available on the type.
 
std::vector< Enumeratorenumerators
 Collection of enumerators if the type is an enum type.
 
CreateInstance createInstance = nullptr
 Method used to create a new instance using operator new.
 
DestroyInstance destroyInstance = nullptr
 Method used to destroy an existing instance using operator delete.
 
ConstructInstance constructInstance = nullptr
 Method used to construct an instance using placement new.
 
DestructInstance destructInstance = nullptr
 
StringView description
 Optional description of the type.
 

Friends

class TypeDatabase
 

Detailed Description

Represents a discrete type definition, describing a native type class.

Constructor & Destructor Documentation

◆ Type() [1/3]

Cogs::Reflection::Type::Type ( )
default

Default constructor.

◆ Type() [2/3]

Cogs::Reflection::Type::Type ( const Type other)
delete

Copying type instances is disallowed.

◆ Type() [3/3]

Cogs::Reflection::Type::Type ( Type &&  other)
defaultnoexcept

Default move constructor.

Member Function Documentation

◆ canCastTo() [1/3]

template<typename DestinationType >
bool Cogs::Reflection::Type::canCastTo
inline

Check if this type can be cast to the destination type.

E.g. if this type is equal to the destination or the destination is a base type of this.

Template Parameters
DestinationTypeType of the destination type.
Returns
A boolean indicating if the cast is valid.

◆ canCastTo() [2/3]

bool Cogs::Reflection::Type::canCastTo ( const Type destination) const
inline

Check if this type can be cast to the destination type.

E.g. if this type is equal to the destination or the destination is a base type of this.

Parameters
destinationType of the destination type.
Returns
A boolean indicating if the cast is valid.

References getTypeId().

◆ canCastTo() [3/3]

bool Cogs::Reflection::Type::canCastTo ( const TypeId destinationId) const

Check if this type can be cast to the destination type.

E.g. if this type is equal to the destination or the destination is a base type of this.

For examples

See also
Cogs::ComponentModel::Component that cannot have virtual members and 'safe' casting can only be checked using this type system.
Parameters
destinationIdTypeId of the destination type.
Returns
A boolean indicating if the cast is valid.

References getBase(), and getTypeId().

◆ getBase()

const Cogs::Reflection::Type * Cogs::Reflection::Type::getBase ( ) const

Get the base type.

References Cogs::Reflection::TypeDatabase::getType(), and Cogs::Reflection::NoType.

Referenced by canCastTo().

◆ getEnumerator() [1/2]

const Cogs::Reflection::Enumerator * Cogs::Reflection::Type::getEnumerator ( const Name name) const

Get a pointer to the enumerator with the given name.

Returns
A pointer to a Enumerator structure, or nullptr if no matching enumerator is found.

References getEnumerator().

Referenced by getEnumerator().

◆ getEnumerator() [2/2]

const Enumerator * Cogs::Reflection::Type::getEnumerator ( const size_t  index) const
inline

Get the enumerator with the given index.

Returns
A pointer to a Enumerator structure, or nullptr if no matching enumerator is found.

◆ getField() [1/2]

const Cogs::Reflection::Field * Cogs::Reflection::Type::getField ( const FieldId  id) const

Get a pointer to the field with the given id.

If id outside own field count the base type is searched.

Parameters
idField id (index)

References getField(), and Cogs::Reflection::NoField.

◆ getField() [2/2]

const Cogs::Reflection::Field * Cogs::Reflection::Type::getField ( const Name name) const

Get a pointer to the field info of the field with the given name.

Returns
A pointer to a Field structure, or nullptr if no matching field is found.

References getField().

Referenced by getField(), and getFieldId().

◆ getFieldId() [1/4]

Cogs::Reflection::FieldId Cogs::Reflection::Type::getFieldId ( const Field field) const

Get the Reflection::FieldId of the given field.

The results are undefined if the field is not a member of this type or its base types.

References getFieldId(), and Cogs::Reflection::NoField.

Referenced by getFieldId().

◆ getFieldId() [2/4]

template<typename ClassType , typename FieldType >
FieldId Cogs::Reflection::Type::getFieldId ( FieldType ClassType::*  field) const
inline

Get the id of the field given by pointer to member.

Parameters
fieldPointer to member of the field in this type.
Returns
FieldId of the field.

References Cogs::memberOffset().

◆ getFieldId() [3/4]

Cogs::Reflection::FieldId Cogs::Reflection::Type::getFieldId ( size_t  offset) const

Get the id of the field located at offset bytes from the start of the structure.

Parameters
offsetOffset of the field in bytes from the start of the structure.
Returns
FieldId of the field, Reflection::NoField if no such field is found.

References Cogs::Reflection::NoField.

◆ getFieldId() [4/4]

Cogs::Reflection::FieldId Cogs::Reflection::Type::getFieldId ( TypeId  componentTypeId,
const Name name 
)
static

Utility to Lookup component type and get field with given name.

Parameters
componentTypeIdType is of the owning component.
nameName of the field.

References getField(), getFieldId(), Cogs::Reflection::TypeDatabase::getType(), Cogs::Reflection::NoField, and Cogs::Reflection::NoType.

◆ getMethod() [1/2]

const Method * Cogs::Reflection::Type::getMethod ( const MethodId  id) const
inline

Get a pointer to the method with the given id.

◆ getMethod() [2/2]

const Cogs::Reflection::Method * Cogs::Reflection::Type::getMethod ( const Name name) const

Get a pointer to the method with the given name.

Returns
A pointer to a Method structure, or nullptr if no matching method is found.

References getMethod().

Referenced by getMethod().

◆ getMethodId()

MethodId Cogs::Reflection::Type::getMethodId ( const Method method) const
inline

Get the Reflection::MethodId of the given method.

The results are undefined if the method is not a member of this type.

◆ getName()

constexpr const Name & Cogs::Reflection::Type::getName ( ) const
inlineconstexpr

Get the unique name of the type.

◆ getNumEnumerators()

size_t Cogs::Reflection::Type::getNumEnumerators ( ) const
inline

Get the number of enumerators in the type.

Returns
Number of enumerators.

◆ getNumFields()

size_t Cogs::Reflection::Type::getNumFields ( ) const
inline

Get the number of fields in the type.

Use

See also
getNumHierarchyFields to also count fields in base types.
Returns
Number of fields.

◆ getNumHierarchyFields()

size_t Cogs::Reflection::Type::getNumHierarchyFields ( ) const

Get the number of fields in the type + types in all base types.

Can be used to iterate over all fields available to this type. Layout: own fields[] + base fields[] + base.base fields[]..

Returns
Number of fields.

References getNumHierarchyFields().

Referenced by getNumHierarchyFields().

◆ getSize()

constexpr size_t Cogs::Reflection::Type::getSize ( ) const
inlineconstexpr

Get the size of an instance of the reflected type, in bytes.

Referenced by Cogs::Reflection::TypeDatabase::constructInstance().

◆ getTypeId()

constexpr TypeId Cogs::Reflection::Type::getTypeId ( ) const
inlineconstexpr

◆ isEnum()

bool Cogs::Reflection::Type::isEnum ( ) const
inline

Get if the type is an enumeration type.

◆ isEnumFlags()

bool Cogs::Reflection::Type::isEnumFlags ( ) const
inline

Get if the type is a flag enumeration type.

◆ isValid()

constexpr bool Cogs::Reflection::Type::isValid ( ) const
inlineconstexpr

Gets if the type is considered a valid, registered type.

References Cogs::Reflection::NoType.

Referenced by Cogs::Reflection::TypeDatabase::constructInstance().

◆ operator=() [1/2]

Type & Cogs::Reflection::Type::operator= ( const Type other)
delete

Disallow copy assignment.

◆ operator=() [2/2]

Type & Cogs::Reflection::Type::operator= ( Type &&  other)
deletenoexcept

Default move assignment.

◆ operator==()

constexpr bool Cogs::Reflection::Type::operator== ( const Type other) const
inlineconstexpr

Check if this type is equal to other.

Returns
A boolean indicating if the types are the same, that is if the type ids of both instances match.

References typeId.

◆ setBase() [1/3]

template<typename BaseType >
Type & Cogs::Reflection::Type::setBase ( )

Set the base of this type to the given type.

Referenced by setBase().

◆ setBase() [2/3]

template<typename BaseType >
Cogs::Reflection::Type & Cogs::Reflection::Type::setBase ( )
inline

References setBase().

◆ setBase() [3/3]

Type & Cogs::Reflection::Type::setBase ( const Type base)
inline

Set the base type of this base. If base is nullptr, there will be no base type.

References Cogs::Reflection::NoType, and typeId.

◆ setEnumerators() [1/2]

Cogs::Reflection::Type & Cogs::Reflection::Type::setEnumerators ( const EnumeratorDef enumerators,
size_t  count 
)

Set the enumerators of the type to the given enumerator instances.

References getName().

◆ setEnumerators() [2/2]

template<size_t count>
Type & Cogs::Reflection::Type::setEnumerators ( const EnumeratorDef(&)  enumerators[count])
inline

Set the enumerators of the type to the given array of enumerator instances.

◆ setEnumFlags()

constexpr Type & Cogs::Reflection::Type::setEnumFlags ( )
inlineconstexpr

Indicate the type is a flag enum.

◆ setFields() [1/2]

Cogs::Reflection::Type & Cogs::Reflection::Type::setFields ( Field fields,
size_t  count 
)
private

◆ setFields() [2/2]

template<size_t count>
Type & Cogs::Reflection::Type::setFields ( Field(&)  fields[count])

Set the fields of the type to the given array of field instances.

◆ setFlags()

constexpr void Cogs::Reflection::Type::setFlags ( uint32_t  flags)
inlineconstexpr

Set type flags.

◆ setMethods() [1/2]

Cogs::Reflection::Type & Cogs::Reflection::Type::setMethods ( Method functions,
size_t  count 
)

Set the methods of the type to the given method instances.

References enumerators, and methods.

◆ setMethods() [2/2]

template<size_t count>
Type & Cogs::Reflection::Type::setMethods ( Method(&)  functions[count])

Set the methods of the type to the given array of method instances.

Friends And Related Function Documentation

◆ TypeDatabase

friend class TypeDatabase
friend

Member Data Documentation

◆ base

TypeId Cogs::Reflection::Type::base = NoType
private

Reflection::TypeId of the Type this type is derived from. Reflection::NoType if no base exists.

◆ constructInstance

ConstructInstance Cogs::Reflection::Type::constructInstance = nullptr
private

Method used to construct an instance using placement new.

Referenced by Cogs::Reflection::TypeDatabase::constructInstance().

◆ createInstance

CreateInstance Cogs::Reflection::Type::createInstance = nullptr
private

Method used to create a new instance using operator new.

Referenced by Cogs::Reflection::TypeDatabase::createInstance().

◆ description

StringView Cogs::Reflection::Type::description
private

Optional description of the type.

◆ destroyInstance

DestroyInstance Cogs::Reflection::Type::destroyInstance = nullptr
private

Method used to destroy an existing instance using operator delete.

◆ destructInstance

DestructInstance Cogs::Reflection::Type::destructInstance = nullptr
private

Method used to destruct an instance previously created with placement new, manually calling the destructor.

Referenced by Cogs::Reflection::TypeDatabase::destructInstance().

◆ enumerators

std::vector<Enumerator> Cogs::Reflection::Type::enumerators
private

Collection of enumerators if the type is an enum type.

Referenced by setMethods().

◆ fields

std::vector<Field> Cogs::Reflection::Type::fields
private

Collection of fields available on the type.

◆ flags

uint32_t Cogs::Reflection::Type::flags = TypeFlags::None
private

Type flags.

◆ methods

std::vector<Method> Cogs::Reflection::Type::methods
private

Collection of methods available on the type.

Referenced by setMethods().

◆ name

Name Cogs::Reflection::Type::name
private

Unique name of the type.

◆ size

size_t Cogs::Reflection::Type::size = 0
private

Size of an instance of a class with this type in bytes.

Referenced by Cogs::Reflection::TypeDatabase::getTypes().

◆ typeId

TypeId Cogs::Reflection::Type::typeId = NoType
private

Unique type id for this type.

Referenced by Cogs::Reflection::TypeDatabase::getType(), operator==(), and setBase().


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