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

Manages all Type instances currently created in the system. More...

#include <TypeDatabase.h>

Public Member Functions

 ~TypeDatabase ()
 

Static Public Member Functions

static void initializeBaseTypes ()
 Initialize the set of types describing built in C++ types like int, float etc.
 
static void clear ()
 Clear the database, removing all existing types. Invalidates all existing Reflection::TypeId instances.
 
template<typename T >
static TypecreateType (bool isAbstract=false)
 Create a new Type from the provided template type.
 
template<typename T >
static TypecreateAbstractType ()
 Create a new abstract Type from the provided template type.
 
static const TypegetType (const TypeId typeId)
 Get the Type with the given type id.
 
static const TypegetType (const Name &name)
 Get the Type with the given unique name.
 
template<typename T >
static const TypegetType ()
 Get the Type of the given template argument.
 
static void constructInstance (const Type &type, void *data, const size_t dataSize)
 Construct an instance of the given type into the given data.
 
static void destructInstance (const Type &type, void *data)
 Destruct an instance of the given type located in data.
 
template<typename T >
static TcreateInstance (const StringView &name)
 Create an instance of the type with the given name.
 
static void * createInstance (const Type &type)
 Create an instance of the given type.
 
static const TypegetTypes (size_t &count)
 Get a pointer to the array of types currently in the type database.
 
static TypecreateType (const StringView &name, size_t size, CreateInstance createInstance, DestroyInstance destroyInstance, ConstructInstance constructInstance, DestructInstance destructInstance, bool isAbstract=false)
 Create a new type from the native type with the given name.
 

Static Private Attributes

static std::unique_ptr< class TypeStoretypeStore = std::make_unique<TypeStore>()
 Stores registered types.
 

Detailed Description

Manages all Type instances currently created in the system.

Constructor & Destructor Documentation

◆ ~TypeDatabase()

Cogs::Reflection::TypeDatabase::~TypeDatabase ( )

Member Function Documentation

◆ clear()

void Cogs::Reflection::TypeDatabase::clear ( )
static

Clear the database, removing all existing types. Invalidates all existing Reflection::TypeId instances.

◆ constructInstance()

void Cogs::Reflection::TypeDatabase::constructInstance ( const Type type,
void *  data,
const size_t  dataSize 
)
static

Construct an instance of the given type into the given data.

The instance will be constructed using placement new into the provided storage.

Parameters
typeA reference to a non-abstract type.
dataPointer to data where an instance of type can be constructed.
dataSizeSize of the pointed-to memory area. Used to ensure there is enough space to construct the instance.

References Cogs::Reflection::Type::constructInstance, Cogs::Reflection::Type::getSize(), and Cogs::Reflection::Type::isValid().

Referenced by Cogs::ComponentModel::ComponentPoolBase::allocateComponent().

◆ createAbstractType()

template<typename T >
static Type & Cogs::Reflection::TypeDatabase::createAbstractType ( )
inlinestatic

Create a new abstract Type from the provided template type.

Abstract types can not be instantiated.

References Cogs::T.

◆ createInstance() [1/2]

template<typename T >
static T * Cogs::Reflection::TypeDatabase::createInstance ( const StringView name)
inlinestatic

Create an instance of the type with the given name.

The returned pointer will be cast to the given template type.

Parameters
nameName of the type to instantiate.

References Cogs::T.

◆ createInstance() [2/2]

void * Cogs::Reflection::TypeDatabase::createInstance ( const Type type)
static

Create an instance of the given type.

Returns
Pointer to the newly created instance.

References Cogs::Reflection::Type::createInstance.

◆ createType() [1/2]

template<typename T >
static Type & Cogs::Reflection::TypeDatabase::createType ( bool  isAbstract = false)
inlinestatic

Create a new Type from the provided template type.

Parameters
isAbstractA boolean indicating if the type should be abstract. Abstract types can not be instantiated.
Template Parameters
TThe type of class/struct to create a new type from. Must provide specialization of the getName function.

References Cogs::T.

◆ createType() [2/2]

Cogs::Reflection::Type & Cogs::Reflection::TypeDatabase::createType ( const StringView name,
size_t  size,
CreateInstance  createInstance,
DestroyInstance  destroyInstance,
ConstructInstance  constructInstance,
DestructInstance  destructInstance,
bool  isAbstract = false 
)
static

Create a new type from the native type with the given name.

References debug_assert, and Cogs::StringView::empty().

◆ destructInstance()

void Cogs::Reflection::TypeDatabase::destructInstance ( const Type type,
void *  data 
)
static

Destruct an instance of the given type located in data.

No memory will be freed by this operation, just invoking the destructor.

Parameters
typeA reference to the type used to construct the element.
dataPointer to the location in memory of the instance to destruct.

References Cogs::Reflection::Type::destructInstance.

Referenced by Cogs::ComponentModel::ComponentPoolBase::deallocateComponent().

◆ getType() [1/3]

template<typename T >
static const Type & Cogs::Reflection::TypeDatabase::getType ( )
inlinestatic

◆ getType() [2/3]

const Cogs::Reflection::Type & Cogs::Reflection::TypeDatabase::getType ( const Name name)
static

Get the Type with the given unique name.

References Cogs::Reflection::Name::getId().

◆ getType() [3/3]

const Cogs::Reflection::Type & Cogs::Reflection::TypeDatabase::getType ( const TypeId  typeId)
static

Get the Type with the given type id.

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

◆ getTypes()

const Cogs::Reflection::Type * Cogs::Reflection::TypeDatabase::getTypes ( size_t &  count)
static

Get a pointer to the array of types currently in the type database.

Parameters
countReturns the count of available types. Can be used to iterate over the type array.
Returns
Pointer to the start of the Type array.

References Cogs::Reflection::Type::size.

◆ initializeBaseTypes()

void Cogs::Reflection::TypeDatabase::initializeBaseTypes ( )
static

Initialize the set of types describing built in C++ types like int, float etc.

Member Data Documentation

◆ typeStore

std::unique_ptr< TypeStore > Cogs::Reflection::TypeDatabase::typeStore = std::make_unique<TypeStore>()
staticprivate

Stores registered types.


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