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

libqi-api 2.8.7.4

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
typedispatcher.hxx
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6
7 #include <qi/type/typeobject.hpp>
8 #include <qi/anyobject.hpp>
9
10 namespace qi {
11
12 template<typename TypeDispatcher>
13 TypeDispatcher& typeDispatch(TypeDispatcher &v, AnyReference value)
14 {
15 if (!value.type())
16 throw std::runtime_error("NULL type");
17 switch(value.kind())
18 {
19 case TypeKind_Void:
20 v.visitVoid();
21 break;
22 case TypeKind_Unknown:
23 v.visitUnknown(value);
24 break;
25 case TypeKind_Int:
26 {
27 IntTypeInterface* tint = static_cast<IntTypeInterface*>(value.type());
28
29 v.visitInt(value.toInt(), tint->isSigned(), tint->size());
30 break;
31 }
32 case TypeKind_Float:
33 {
34 FloatTypeInterface* tfloat = static_cast<FloatTypeInterface*>(value.type());
35 v.visitFloat(value.toDouble(), tfloat->size());
36 break;
37 }
38 case TypeKind_String:
39 {
40 StringTypeInterface* tstring = static_cast<StringTypeInterface*>(value.type());
41 StringTypeInterface::ManagedRawString content = tstring->get(value.rawValue());
42 v.visitString(content.first.first, content.first.second);
43 if (content.second)
44 content.second(content.first);
45 break;
46 }
47 case TypeKind_List:
48 {
49 v.visitList(value.begin(), value.end());
50 break;
51 }
52 case TypeKind_Map:
53 {
54 v.visitMap(value.begin(), value.end());
55 break;
56 }
57 case TypeKind_Object:
58 {
59 v.visitObject(GenericObject(static_cast<ObjectTypeInterface*>(value.type()), value.rawValue()));
60 break;
61 }
62 case TypeKind_Pointer:
63 {
64 AnyReference pointee = *value;
65 PointerTypeInterface* type = static_cast<PointerTypeInterface*>(value.type());
66 if (type->pointerKind() == PointerTypeInterface::Shared
67 && pointee.kind() == TypeKind_Object)
68 { // shared_ptr<Foo> p with Foo object type.
69 // Create our own shared_ptr, that holds p and delete it on destruction
70 qiLogDebug("qitype.typedispatcher") << "Detected object shared ptr";
71 AnyReference shared_ptr = value.clone();
72 AnyObject ao(new GenericObject(static_cast<ObjectTypeInterface*>(pointee.type()), pointee.rawValue()),
73 boost::bind(&AnyObject::deleteCustomDeleter, _1, (boost::function<void(Empty*)>)boost::bind(&AnyReference::destroy, shared_ptr)));
74 v.visitAnyObject(ao);
75 }
76 else
77 v.visitPointer(pointee);
78 break;
79 }
80 case TypeKind_Tuple:
81 {
82 StructTypeInterface* ttuple = static_cast<StructTypeInterface*>(value.type());
83 AnyReferenceVector tuple = ttuple->values(value.rawValue());
84 v.visitTuple(ttuple->className(), tuple, ttuple->elementsName());
85 break;
86 }
87 case TypeKind_Dynamic:
88 {
89 if (value.type()->info() == typeOf<AnyObject>()->info())
90 {
91 AnyObject* o = value.ptr<AnyObject>(false);
92 v.visitAnyObject(*o);
93 }
94 else
95 v.visitDynamic(value.content());
96 break;
97 }
98 case TypeKind_Raw:
99 {
100 v.visitRaw(value);
101 break;
102 }
103 case TypeKind_Iterator:
104 {
105 v.visitIterator(value);
106 break;
107 }
108 case TypeKind_VarArgs:
109 v.visitVarArgs(value.begin(), value.end());
110 break;
111 case TypeKind_Optional:
112 v.visitOptional(value);
113 break;
114
115 case TypeKind_Function:
116 case TypeKind_Signal:
117 case TypeKind_Property:
118 qiLogError("qitype.typedispatcher") << "Signal and Property not handled";
119
120 }
121 return v;
122 }
123
124 }
qi::StructTypeInterface::className
virtual std::string className()
Get the type name of the struct.
Definition: typeinterface.hpp:266
qi::TypeKind_Map
Definition: fwd.hpp:62
qi::StringTypeInterface
Definition: typeinterface.hpp:104
qi::FloatTypeInterface::size
virtual unsigned int size()=0
Return the size in bytes.
qi::Empty
Definition: object.hxx:35
qi::detail::AnyReferenceBase::ptr
T * ptr(bool check=true)
Definition: anyreference.hxx:111
qi::TypeKind_Dynamic
Definition: fwd.hpp:66
qi::IntTypeInterface::isSigned
virtual bool isSigned()=0
Return true if the integer is signed.
qi::typeDispatch
TypeDispatcher & typeDispatch(TypeDispatcher &v, AnyReference value)
Definition: typedispatcher.hxx:13
qiLogDebug
#define qiLogDebug(...)
Definition: log.hpp:76
qi::AnyReference
Definition: anyreference.hpp:360
qi::TypeKind_VarArgs
Definition: fwd.hpp:72
qi::StructTypeInterface::values
AnyReferenceVector values(void *storage)
Get all the fields of the structure.
qi::TypeKind_Optional
Definition: fwd.hpp:73
qi::TypeKind_Void
Definition: fwd.hpp:57
qi::TypeKind_Unknown
Definition: fwd.hpp:56
qi::StringTypeInterface::ManagedRawString
std::pair< RawString, Deleter > ManagedRawString
Definition: typeinterface.hpp:109
qi::detail::AnyReferenceBase::destroy
void destroy()
Deletes storage.
Definition: anyreference.hxx:34
qi::detail::AnyReferenceBase::toInt
int64_t toInt() const
Definition: anyreference.hxx:166
qiLogError
#define qiLogError(...)
Log in error mode.
Definition: log.hpp:120
qi::IntTypeInterface::size
virtual unsigned int size()=0
Return the size in bytes.
qi::TypeKind_Function
Definition: fwd.hpp:69
qi::GenericObject
Definition: genericobject.hpp:41
qi::TypeKind_Object
Definition: fwd.hpp:63
qi::detail::AnyReferenceBase::begin
AnyIterator begin() const
Return an iterator on the beginning of the container.
qi::AnyReferenceVector
std::vector< AnyReference > AnyReferenceVector
Definition: anyreference.hpp:26
qi::TypeKind_Pointer
Definition: fwd.hpp:64
qi::detail::AnyReferenceBase::type
TypeInterface * type() const
Definition: anyreference.hpp:348
qi::StringTypeInterface::get
virtual ManagedRawString get(void *storage)=0
qi::TypeKind_Signal
Definition: fwd.hpp:70
qi::TypeKind_Int
Definition: fwd.hpp:58
qi::detail::AnyReferenceBase::rawValue
void * rawValue() const
Definition: anyreference.hpp:351
qi::TypeKind_List
Definition: fwd.hpp:61
qi::FloatTypeInterface
Definition: typeinterface.hpp:92
qi::detail::AnyReferenceBase::kind
TypeKind kind() const
Definition: anyreference.hxx:71
typeobject.hpp
qi::PointerTypeInterface::Shared
Definition: typeinterface.hpp:143
qi::TypeInterface::info
virtual const TypeInfo & info()=0
Get the TypeInfo corresponding to this type.
qi::Object
Definition: object.hxx:243
qi::TypeKind_Float
Definition: fwd.hpp:59
qi::StructTypeInterface::elementsName
virtual std::vector< std::string > elementsName()
Get the names of the fields of the struct.
Definition: typeinterface.hpp:264
qi::detail::AnyReferenceBase::content
AnyReference content() const
qi::detail::AnyReferenceBase::end
AnyIterator end() const
Return an iterator on the end of the container.
qi::IntTypeInterface
Definition: typeinterface.hpp:78
qi::PointerTypeInterface
Definition: typeinterface.hpp:137
qi::detail::AnyReferenceBase::clone
AnyReference clone() const
Definition: anyreference.hxx:18
qi::TypeKind_String
Definition: fwd.hpp:60
qi::TypeKind_Tuple
Definition: fwd.hpp:65
anyobject.hpp
qi::TypeKind_Iterator
Definition: fwd.hpp:68
qi::StructTypeInterface
Definition: typeinterface.hpp:241
qi::PointerTypeInterface::pointerKind
virtual PointerKind pointerKind()=0
Return whether the pointer has raw or shared semantics.
qi::TypeKind_Raw
Definition: fwd.hpp:67
qi::bind
std::enable_if< std::is_function< RF >::value, boost::function< RF > >::type bind(AF &&fun, Arg0 &&arg0, Args &&...args)
Definition: trackable.hxx:308
qi::Object< Empty >::deleteCustomDeleter
static void deleteCustomDeleter(GenericObject *obj, boost::function< void(Empty *)> deleter)
Definition: object.hxx:318
qi::detail::AnyReferenceBase::toDouble
double toDouble() const
Definition: anyreference.hxx:181
qi::TypeKind_Property
Definition: fwd.hpp:71