3#include "TypeDatabase.h"
7 assert(
enumerators.empty() &&
"Enumeration cannot contain methods.");
8 assert(this->
methods.empty() &&
"set only.");
11 for (
size_t i = 0; i < count; ++i) {
12 this->
methods.emplace_back(std::move(functions[i]));
20 assert(fields.empty() &&
"Enumeration cannot contain fields.");
21 assert(methods.empty() &&
"Enumeration cannot contain methods.");
22 assert(this->enumerators.empty() &&
"set only.");
24 this->enumerators.reserve(this->enumerators.size() + count);
25 for (
size_t i = 0; i < count; ++i) {
26 this->enumerators.emplace_back(enumerators[i].getName(), enumerators[i].getValue());
34 if (base ==
NoType)
return nullptr;
41 if (this->getTypeId() == destinationId) {
45 const Type* typeBase = getBase();
46 while (typeBase && (typeBase->
getTypeId() != destinationId)) {
50 return (typeBase !=
nullptr);
55 for (
const Field & item : fields) {
56 if (item.getName() == name) {
62 return baseType ? baseType->
getField(name) :
nullptr;
67 if (field < fields.data() || field >(fields.data() + fields.size())) {
78 return static_cast<FieldId>(field - fields.data());
83 assert(componentTypeId !=
NoType);
103 return getNumFields();
114 else if (
id >= myFieldCount) {
116 return baseType ? baseType->
getField(
id - myFieldCount) :
nullptr;
124 for (
size_t i = 0; i < fields.size(); ++i) {
125 if (fields[i].getOffset() == offset) {
126 return static_cast<FieldId>(i);
135 for (
const Method& item : methods) {
136 if (item.getName() == name) {
142 return baseType ? baseType->
getMethod(name) :
nullptr;
148 if (item.getName() == name) {
159 assert(enumerators.empty() &&
"Enumeration cannot contain fields.");
160 assert(this->fields.empty() &&
"set only.");
162 this->fields.reserve(count);
163 for (
size_t i = 0; i < count; ++i) {
164 this->fields.emplace_back(std::move(fields[i]));
Field definition describing a single data member of a data structure.
Simple method definition.
static const Type & getType()
Get the Type of the given template argument.
Represents a discrete type definition, describing a native type class.
FieldId getFieldId(const Field *field) const
Get the Reflection::FieldId of the given field.
const Type * getBase() const
Get the base type.
const Enumerator * getEnumerator(const Name &name) const
Get a pointer to the enumerator with the given name.
std::vector< Enumerator > enumerators
Collection of enumerators if the type is an enum type.
const Method * getMethod(const Name &name) const
Get a pointer to the method with the given name.
size_t getNumHierarchyFields() const
Get the number of fields in the type + types in all base types.
std::vector< Method > methods
Collection of methods available on the type.
const Field * getField(const Name &name) const
Get a pointer to the field info of the field with the given name.
Type & setEnumerators(const EnumeratorDef(&enumerators)[count])
Set the enumerators of the type to the given array of enumerator instances.
bool canCastTo() const
Check if this type can be cast to the destination type.
Type & setMethods(Method(&functions)[count])
Set the methods of the type to the given array of method instances.
constexpr TypeId getTypeId() const
Get the unique Reflection::TypeId of this instance.
Type & setFields(Field(&fields)[count])
Set the fields of the type to the given array of field instances.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
uint16_t FieldId
Type used to index fields.
constexpr FieldId NoField
No field id.
constexpr TypeId NoType
Definition of no type.
Single integral constant enumerator.
Represents an unique name.