- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
qi::TypeInterface Class Referenceabstract

`#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)

## Detailed Description

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:

struct MyUnion {
enum Type type;
union Data {
int i;
float f;
} data;
};
+-----------------------+ <-- storage of Dynamic
| Type type |
| +-------------------+ | <-- storage returned when get() is called
| | int i / float f | |
| +-------------------+ |
+-----------------------+

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:

- cloning/destruction in clone() and destroy()
- Access to value from storage and storage creation in ptrFromStorage() and initializeStorage()
- Type of specialized interface through kind()

Our aim is to transport arbitrary values through:

- synchronous calls: Nothing to do, values are just transported and converted.
- asynchronous call/thread change: Values are copied.
- process change: Values are serialized.

Definition at line 129 of file typeinterface.hpp.

## Constructor & Destructor Documentation

virtual qi::TypeInterface::~TypeInterface | ( |  | ) |
| virtual default

## Member Function Documentation

virtual void* qi::TypeInterface::clone | ( | void * |  | ) |
| 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.

virtual void qi::TypeInterface::destroy | ( | void * |  | ) |
| 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 TypeInterface* qi::TypeInterface::fromSignature | ( | const qi::Signature & | sig | ) |
| static

Returns
  a Type on which signature() returns sig.

virtual const TypeInfo& qi::TypeInterface::info | ( |  | ) |
| 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.

const char* qi::TypeInterface::infoString | ( |  | ) |
| inline

Definition at line 178 of file typeinterface.hpp.

virtual void* qi::TypeInterface::initializeStorage | ( | void * | ptr = `nullptr` | ) |
| 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.

TypeKind qi::TypeInterface::kind | ( |  | ) |
| inline virtual

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.

Definition at line 99 of file type.hxx.

virtual bool qi::TypeInterface::less | ( | void * | a,
|  | void * | b
| ) |  |
| 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.

virtual void* qi::TypeInterface::ptrFromStorage | ( | void ** |  | ) |
| 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`
| ) |  |

Returns
  the serialization signature corresponding to what the type would emit

Parameters

  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]

Warning
  if resolveDynamic is true, a valid storage must be given

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

- /home/opennao/work/release-2.8/sdk/libqi/qi/type/detail/typeinterface.hpp
- /home/opennao/work/release-2.8/sdk/libqi/qi/type/detail/type.hxx