Cogs.Foundation
|
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. | |
Type & | operator= (const Type &other)=delete |
Disallow copy assignment. | |
Type & | operator= (Type &&other) noexcept=delete |
Default move assignment. | |
template<size_t count> | |
Type & | setFields (Field(&fields)[count]) |
Set the fields of the type to the given array of field instances. | |
template<size_t count> | |
Type & | setMethods (Method(&functions)[count]) |
Set the methods of the type to the given array of method instances. | |
Type & | setMethods (Method *functions, size_t count) |
Set the methods of the type to the given method instances. | |
template<size_t count> | |
Type & | setEnumerators (const EnumeratorDef(&enumerators)[count]) |
Set the enumerators of the type to the given array of enumerator instances. | |
Type & | setEnumerators (const EnumeratorDef *enumerators, size_t count) |
Set the enumerators of the type to the given enumerator instances. | |
Type & | setBase (const Type *base) |
Set the base type of this base. If base is nullptr, there will be no base type. | |
template<typename BaseType > | |
Type & | setBase () |
Set the base of this type to the given type. | |
const Type * | getBase () 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 Name & | getName () 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 Field * | getField (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 Field * | getField (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 Method * | getMethod (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 Method * | getMethod (const MethodId id) const |
Get a pointer to the method with the given id. | |
const Enumerator * | getEnumerator (const Name &name) const |
Get a pointer to the enumerator with the given name. | |
const Enumerator * | getEnumerator (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 Type & | setEnumFlags () |
Indicate the type is a flag enum. | |
template<typename BaseType > | |
Cogs::Reflection::Type & | setBase () |
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 | |
Type & | setFields (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< Field > | fields |
Collection of fields available on the type. | |
std::vector< Method > | methods |
Collection of methods available on the type. | |
std::vector< Enumerator > | enumerators |
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 |
Represents a discrete type definition, describing a native type class.
|
default |
Default constructor.
|
delete |
Copying type instances is disallowed.
|
defaultnoexcept |
Default move constructor.
|
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.
DestinationType | Type of the destination type. |
|
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.
destination | Type of the destination type. |
References getTypeId().
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
destinationId | TypeId of the destination type. |
References getBase(), and getTypeId().
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().
const Cogs::Reflection::Enumerator * Cogs::Reflection::Type::getEnumerator | ( | const Name & | name | ) | const |
Get a pointer to the enumerator with the given name.
References getEnumerator().
Referenced by getEnumerator().
|
inline |
Get the enumerator with the given index.
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.
id | Field id (index) |
References getField(), and Cogs::Reflection::NoField.
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.
References getField().
Referenced by getField(), and getFieldId().
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().
|
inline |
Get the id of the field given by pointer to member.
field | Pointer to member of the field in this type. |
References Cogs::memberOffset().
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.
offset | Offset of the field in bytes from the start of the structure. |
References Cogs::Reflection::NoField.
|
static |
Utility to Lookup component type and get field with given name.
References getField(), getFieldId(), Cogs::Reflection::TypeDatabase::getType(), Cogs::Reflection::NoField, and Cogs::Reflection::NoType.
Get a pointer to the method with the given id.
const Cogs::Reflection::Method * Cogs::Reflection::Type::getMethod | ( | const Name & | name | ) | const |
Get a pointer to the method with the given name.
References getMethod().
Referenced by getMethod().
Get the Reflection::MethodId of the given method.
The results are undefined if the method is not a member of this type.
|
inlineconstexpr |
Get the unique name of the type.
|
inline |
Get the number of enumerators in the type.
|
inline |
Get the number of fields in the type.
Use
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[]..
References getNumHierarchyFields().
Referenced by getNumHierarchyFields().
|
inlineconstexpr |
Get the size of an instance of the reflected type, in bytes.
Referenced by Cogs::Reflection::TypeDatabase::constructInstance().
|
inlineconstexpr |
Get the unique Reflection::TypeId of this instance.
Referenced by canCastTo(), Cogs::ComponentModel::Entity::getComponentHandle(), and Cogs::ComponentModel::Component::getComponentTypeId().
|
inline |
Get if the type is an enumeration type.
|
inline |
Get if the type is a flag enumeration type.
|
inlineconstexpr |
Gets if the type is considered a valid, registered type.
References Cogs::Reflection::NoType.
Referenced by Cogs::Reflection::TypeDatabase::constructInstance().
|
inlineconstexpr |
Check if this type is equal to other.
References typeId.
Type & Cogs::Reflection::Type::setBase | ( | ) |
Set the base of this type to the given type.
Referenced by setBase().
|
inline |
References setBase().
Set the base type of this base. If base is nullptr, there will be no base type.
References Cogs::Reflection::NoType, and typeId.
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().
|
inline |
Set the enumerators of the type to the given array of enumerator instances.
|
inlineconstexpr |
Indicate the type is a flag enum.
|
private |
Set the fields of the type to the given array of field instances.
|
inlineconstexpr |
Set type flags.
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.
Set the methods of the type to the given array of method instances.
|
friend |
Reflection::TypeId of the Type this type is derived from. Reflection::NoType if no base exists.
|
private |
Method used to construct an instance using placement new.
Referenced by Cogs::Reflection::TypeDatabase::constructInstance().
|
private |
Method used to create a new instance using operator new.
Referenced by Cogs::Reflection::TypeDatabase::createInstance().
|
private |
Optional description of the type.
|
private |
Method used to destroy an existing instance using operator delete.
|
private |
Method used to destruct an instance previously created with placement new, manually calling the destructor.
Referenced by Cogs::Reflection::TypeDatabase::destructInstance().
|
private |
Collection of enumerators if the type is an enum type.
Referenced by setMethods().
|
private |
Collection of fields available on the type.
|
private |
Type flags.
|
private |
Collection of methods available on the type.
Referenced by setMethods().
|
private |
Unique name of the type.
|
private |
Size of an instance of a class with this type in bytes.
Referenced by Cogs::Reflection::TypeDatabase::getTypes().
Unique type id for this type.
Referenced by Cogs::Reflection::TypeDatabase::getType(), operator==(), and setBase().