libqi-api
2.8.7.4
|
#include <typeinterface.hpp>
Public Member Functions | |
virtual | ~TypeInterface ()=default |
virtual const TypeInfo & | info ()=0 |
Get the TypeInfo corresponding to this type. More... | |
virtual void * | initializeStorage (void *ptr=nullptr)=0 |
virtual void * | ptrFromStorage (void **)=0 |
virtual void * | clone (void *)=0 |
Allocate a storage and copy the value given as an argument. More... | |
virtual void | destroy (void *)=0 |
Free all resources of a storage. More... | |
virtual TypeKind | kind () |
virtual bool | less (void *a, void *b)=0 |
const char * | infoString () |
qi::Signature | signature (void *storage=nullptr, bool resolveDynamic=false) |
Static Public Member Functions | |
static TypeInterface * | fromSignature (const qi::Signature &sig) |
TypeInterface base interface. Further interfaces inheriting from TypeInterface define operations specific to some type (like lists, strings, integral values...).
Type erasure is implemented using the following model. A value or a reference is represented by a void* paired with a TypeInterface to manipulate the data.
A TypeInterface implements basic operations on values of the type it represents. It manipulates said value through an opaque storage pointer, initialized by clone() or initializeStorage(). Thus, TypeInterface instances do not usually hold any data, may exist as singletons inside programs and must not be freed.
To obtain a TypeInterface for a known C++ type, use typeOf<>() or typeFromSignature().
Great care must be taken when manipulating storage: depending on the circunstances, it can point to a value allocated by the TypeInterface on the heap, or to a user-provided value on the heap or on the stack.
As an example, here is a type erased union:
DynamicTypeInterface::get() checks the type with the internal Type enum and returns a reference with the right TypeInterface to manipulate the inner data and a pointer to that inner data.
This base TypeInterface has all the operations we need on any type:
Our aim is to transport arbitrary values through:
Definition at line 129 of file typeinterface.hpp.
|
virtualdefault |
|
pure virtual |
Allocate a storage and copy the value given as an argument.
Implemented in qi::TypeImpl< void >, qi::DefaultTypeImpl< T, _Access >, qi::DefaultTypeImpl< int >, qi::DefaultTypeImpl< T >, qi::TypeImpl< char[I]>, qi::detail::StaticObjectTypeBase, and qi::TypeCStringImpl.
|
pure virtual |
Free all resources of a storage.
Implemented in qi::TypeImpl< void >, qi::DefaultTypeImpl< T, _Access >, qi::DefaultTypeImpl< int >, qi::DefaultTypeImpl< T >, qi::TypeImpl< char[I]>, qi::detail::StaticObjectTypeBase, and qi::TypeCStringImpl.
|
static |
|
pure virtual |
Get the TypeInfo corresponding to this type.
Implemented in qi::TypeImpl< void >, qi::DefaultTypeImpl< T, _Access >, qi::DefaultTypeImpl< int >, qi::DefaultTypeImpl< T >, and qi::detail::StaticObjectTypeBase.
|
inline |
Definition at line 178 of file typeinterface.hpp.
|
pure virtual |
Initialize and return a new storage, from nothing or a T*.
If ptr is not null, it should be used as a storage (the method can usually just return ptr in that case).
Implemented in qi::TypeImpl< void >, qi::DefaultTypeImpl< T, _Access >, qi::DefaultTypeImpl< int >, qi::DefaultTypeImpl< T >, and qi::detail::StaticObjectTypeBase.
|
inlinevirtual |
Get the kind of the data.
This is used to downcast the TypeInterface object to a specialized interface.
Reimplemented in qi::OptionalTypeInterface, qi::VarArgsTypeInterface, qi::TypeImpl< void >, qi::DynamicTypeInterface, qi::StructTypeInterface, qi::MapTypeInterface, qi::ListTypeInterface, qi::IteratorTypeInterface, qi::PointerTypeInterface, qi::RawTypeInterface, qi::StringTypeInterface, qi::FloatTypeInterface, qi::IntTypeInterface, and qi::ObjectTypeInterface.
|
pure virtual |
Return true if a is less than b
Less must always work: compare pointers if you have to.
Implemented in qi::TypeImpl< void >, qi::DefaultTypeImpl< T, _Access >, qi::DefaultTypeImpl< int >, qi::DefaultTypeImpl< T >, and qi::detail::StaticObjectTypeBase.
|
pure virtual |
Get pointer to type from pointer to storage.
This allows for storing an integer value (for instance) directily into the pointer and avoid an allocation.
This method should be called on storage before casting it to a specific type.
Implemented in qi::TypeImpl< void >, qi::DefaultTypeImpl< T, _Access >, qi::DefaultTypeImpl< int >, qi::DefaultTypeImpl< T >, and qi::detail::StaticObjectTypeBase.
qi::Signature qi::TypeInterface::signature | ( | void * | storage = nullptr , |
bool | resolveDynamic = false |
||
) |
storage | the storage of the value (used only when resolveDynamic is true) |
resolveDynamic | if true, resolve dynamic types as deep as possible for example a list<AnyReference> that happens to only contain int32 will return [i] |