- 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
typeinterface.hpp
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 #ifndef _QI_TYPE_TYPEINTERFACE_HPP_
8 #define _QI_TYPE_TYPEINTERFACE_HPP_
9
10 #include <typeinfo>
11 #include <string>
12
13 #include <boost/preprocessor.hpp>
14 #include <boost/function.hpp>
15 #include <boost/type_traits/is_function.hpp>
16 #include <boost/mpl/if.hpp>
17
18 #include <qi/log.hpp>
19 #include <qi/api.hpp>
20 #include <qi/type/fwd.hpp>
21 #include <qi/signature.hpp>
22 #include <qi/type/detail/typeinterface.hpp>
23
24 #ifdef _MSC_VER
25 # pragma warning( push )
26 # pragma warning( disable: 4251 )
27 // C4503 decorated name length exceeded, name was truncated
28 // The only workaround is to make structs to hide the template complexity
29 // We don't want to have to do that
30 # pragma warning( disable: 4503 )
31 #endif
32
33 /* A lot of class are found in this headers... to kill circular dependencies.
34 Futhermore we need that all "default template" types are registered (included)
35 when type.hpp is used. (for typeOf to works reliably)
36 */
37
38 namespace qi{
39
42 #define QI_TYPE_NOT_CONSTRUCTIBLE(T) \
43 namespace qi { namespace detail { \
44 template<> struct TypeManager<T>: public TypeManagerNotConstructible<T> {};}}
45
48 #define QI_NO_TYPE(T) namespace qi {template<> class TypeImpl<T>: public detail::ForbiddenInTypeSystem {};}
49
52 #define QI_TYPE_INTERFACE(T) \
53 namespace qi { namespace detail { \
54 template<> struct TypeManager<T>: public TypeManagerDefaultInterface<T> {};}}
55
58 #define QI_TYPE_CONCRETE(T) \
59 namespace qi { namespace detail { \
60 template<> struct TypeManager<T>: public TypeManagerDefaultStruct<T> {}; }}
61
64 #define QI_TYPE_REGISTER(t) \
65 QI_TYPE_REGISTER_CUSTOM(t, qi::TypeImpl<t>)
66
69 #define QI_TYPE_REGISTER_CUSTOM(type, typeimpl) \
70 static bool BOOST_PP_CAT(__qi_registration, __LINE__) QI_ATTR_UNUSED \
71 = qi::registerType(qi::typeId<type>(), new typeimpl)
72
73
74 class ListTypeInterface;
75 class StructTypeInterface;
76
77 // Interfaces for specialized types
78 class QI_API IntTypeInterface: public TypeInterface
79 {
80 public:
82 virtual int64_t get(void* value) = 0;
84 virtual unsigned int size() = 0;
86 virtual bool isSigned() = 0;
88 virtual void set(void** storage, int64_t value) = 0;
89 TypeKind kind() override { return TypeKind_Int;}
90 };
91
92 class QI_API FloatTypeInterface: public TypeInterface
93 {
94 public:
96 virtual double get(void* value) = 0;
98 virtual unsigned int size() = 0; // size in bytes
100 virtual void set(void** storage, double value) = 0;
101 TypeKind kind() override { return TypeKind_Float;}
102 };
103
104 class QI_API StringTypeInterface: public TypeInterface
105 {
106 public:
107 using RawString = std::pair<char*, size_t>;
108 using Deleter = boost::function<void(const RawString&)>;
109 using ManagedRawString = std::pair<RawString, Deleter>;
110
112 std::string getString(void* storage);
115 virtual ManagedRawString get(void* storage) = 0;
117 void set(void** storage, const std::string& value);
119 virtual void set(void** storage, const char* ptr, size_t sz) = 0;
120 TypeKind kind() override { return TypeKind_String; }
121
122 };
123
127 class QI_API RawTypeInterface: public TypeInterface
128 {
129 public:
131 virtual std::pair<char*, size_t> get(void* storage) = 0;
133 virtual void set(void** storage, const char* ptr, size_t sz) = 0;
134 TypeKind kind() override { return TypeKind_Raw; }
135 };
136
137 class QI_API PointerTypeInterface: public TypeInterface
138 {
139 public:
140 enum PointerKind
141 {
142 Raw,
143 Shared,
144 };
146 virtual PointerKind pointerKind() = 0;
148 virtual TypeInterface* pointedType() = 0;
150 virtual AnyReference dereference(void* storage) = 0;
152 virtual void set(void** storage, AnyReference pointer) = 0;
154 virtual void setPointee(void** storage, void* pointer) = 0;
155 TypeKind kind() override { return TypeKind_Pointer; }
156 };
157
164 class QI_API IteratorTypeInterface: public TypeInterface
165 {
166 public:
175 virtual AnyReference dereference(void* storage) = 0;
177 virtual void next(void** storage) = 0;
179 virtual bool equals(void* s1, void* s2) = 0;
180 TypeKind kind() override { return TypeKind_Iterator; }
181 };
182
188 class QI_API ListTypeInterface: public TypeInterface
189 {
190 public:
192 virtual TypeInterface* elementType() = 0;
194 virtual size_t size(void* storage) = 0;
196 virtual AnyIterator begin(void* storage) = 0;
199 virtual AnyIterator end(void* storage) = 0;
201 virtual void pushBack(void** storage, void* valueStorage) = 0;
203 virtual void* element(void* storage, int index);
204 TypeKind kind() override { return TypeKind_List;}
205 };
206
213 class QI_API MapTypeInterface: public TypeInterface
214 {
215 public:
217 virtual TypeInterface* elementType() = 0;
219 virtual TypeInterface* keyType() = 0;
221 virtual size_t size(void* storage) = 0;
223 virtual AnyIterator begin(void* storage) = 0;
226 virtual AnyIterator end(void* storage) = 0;
228 virtual void insert(void** storage, void* keyStorage, void* valueStorage) = 0;
235 virtual AnyReference element(void** storage, void* keyStorage, bool autoInsert) = 0;
236 TypeKind kind() override { return TypeKind_Map; }
237 // Since our typesystem has no erased operator < or operator ==,
238 // MapTypeInterface does not provide a find()
239 };
240
241 class QI_API StructTypeInterface: public TypeInterface
242 {
243 public:
245 AnyReferenceVector values(void* storage);
253 virtual std::vector<TypeInterface*> memberTypes() = 0;
255 virtual std::vector<void*> get(void* storage);
257 virtual void* get(void* storage, unsigned int index) = 0;
259 virtual void set(void** storage, const std::vector<void*>&);
261 virtual void set(void** storage, unsigned int index, void* valStorage) = 0;
262 TypeKind kind() override { return TypeKind_Tuple; }
264 virtual std::vector<std::string> elementsName() { return std::vector<std::string>();}
266 virtual std::string className() { return std::string(); }
267
287 virtual bool convertFrom(std::map<std::string, ::qi::AnyValue>& fields,
289 const std::vector<std::tuple<std::string, TypeInterface*>>& missing,
290 const std::map<std::string, ::qi::AnyReference>& dropfields)
291 {
292 return false;
293 }
295 virtual bool convertTo(std::map<std::string, ::qi::AnyValue>& fields,
296 const std::vector<std::tuple<std::string, TypeInterface*>>& missing,
297 const std::map<std::string, ::qi::AnyReference>& dropfields)
298 {
299 return false;
300 }
301
303 };
304
310 class QI_API DynamicTypeInterface: public TypeInterface
311 {
312 public:
314 virtual AnyReference get(void* storage) = 0;
316 virtual void set(void** storage, AnyReference source) = 0;
317 TypeKind kind() override { return TypeKind_Dynamic; }
318 };
319
323 class QI_API VarArgsTypeInterface: public ListTypeInterface
324 {
325 public:
326 //virtual AnyReference get(void *storage) = 0;
327 //virtual TypeInterface* elementType() = 0;
328 TypeKind kind() override { return TypeKind_VarArgs; }
329 };
330
334 class QI_API OptionalTypeInterface: public TypeInterface
335 {
336 public:
338 virtual TypeInterface* valueType() = 0;
340 virtual bool hasValue(void* storage) = 0;
342 virtual AnyReference value(void* storage) = 0;
344 virtual void set(void** storage, void* valueStorage) = 0;
346 virtual void reset(void** storage) = 0;
347 TypeKind kind() override { return TypeKind_Optional; }
348 };
349
350
354 QI_API TypeInterface* makeTypeOfKind(const qi::TypeKind& kind);
355
357 QI_API TypeInterface* makeFloatType(int bytelen);
358
360 QI_API TypeInterface* makeIntType(bool issigned, int bytelen);
361
363 QI_API TypeInterface* makeVarArgsType(TypeInterface* elementType);
364
366 QI_API TypeInterface* makeListType(TypeInterface* elementType);
367
369 QI_API TypeInterface* makeMapType(TypeInterface* keyType, TypeInterface* ElementType);
370
372 QI_API TypeInterface* makeTupleType(const std::vector<TypeInterface*>& memberTypes, const std::string &name = std::string(), const std::vector<std::string>& elementNames = std::vector<std::string>());
373
375 QI_API TypeInterface* makeOptionalType(TypeInterface* valueType);
376
377
378
382 #define QI_TEMPLATE_TYPE_DECLARE(n) \
383 namespace qi \
384 { \
385 template <typename T> \
386 class QITYPE_TEMPLATE_API TypeImpl<n<T> > : public TypeOfTemplateImpl<n, T> \
387 { \
388 }; \
389 }
390
394 #define QI_TEMPLATE_TYPE_GET(typeInst, templateName) \
395 dynamic_cast< ::qi::TypeOfTemplate<templateName>*>(typeInst)
396
400 #define QI_TYPE_ENUM(Enum) \
401 namespace qi \
402 { \
403 template <> \
404 class TypeImpl<Enum> : public IntTypeInterfaceImpl<int> \
405 { \
406 }; \
407 }
408
409 namespace detail
410 {
411 struct QI_API_DEPRECATED_MSG(Use 'QI_TYPE_ENUM' instead) QI_TYPE_ENUM_REGISTER_ {};
412 }
413
414 #define QI_TYPE_ENUM_REGISTER(Enum) \
415 namespace qi \
416 { \
417 template <> \
418 class TypeImpl<Enum> : public IntTypeInterfaceImpl<int> \
419 { \
420 static const detail::QI_TYPE_ENUM_REGISTER_ BLAH; \
421 }; \
422 }
423
424 #define QI_TYPE_STRUCT_DECLARE(name) \
425 __QI_TYPE_STRUCT_DECLARE(name, )
426
427 }
428
429
430 #include <qi/type/detail/typeimpl.hxx>
431 #include <qi/type/detail/type.hxx>
432 #include <qi/type/detail/inttypeinterface.hxx>
433 #include <qi/type/detail/listtypeinterface.hxx>
434 #include <qi/type/detail/maptypeinterface.hxx>
435 #include <qi/type/detail/stringtypeinterface.hxx>
436 #include <qi/type/detail/pointertypeinterface.hxx>
437 #include <qi/type/detail/structtypeinterface.hxx>
438 #include <qi/type/detail/buffertypeinterface.hxx>
439 #include <qi/type/detail/dynamictypeinterface.hxx>
440 #include <qi/type/detail/optionaltypeinterface.hxx>
441
442 QI_NO_TYPE(qi::TypeInterface)
443 QI_NO_TYPE(qi::TypeInterface*)
444
445 #ifdef _MSC_VER
446 # pragma warning( pop )
447 // restore the disabling of this warning
448 # pragma warning( disable: 4503 )
449 #endif
450
451 #endif // _QITYPE_TYPEINTERFACE_HPP_
qi::ListTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:204
qi::AnyIterator
Definition: anyiterator.hpp:16
dynamictypeinterface.hxx
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::IntTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:89
qi::makeTupleType
TypeInterface * makeTupleType(const std::vector< TypeInterface * > &memberTypes, const std::string &name=std::string(), const std::vector< std::string > &elementNames=std::vector< std::string >())
qi::StringTypeInterface
Definition: typeinterface.hpp:104
QI_TYPE_ENUM
#define QI_TYPE_ENUM(Enum)
Definition: typeinterface.hpp:400
qi::int64_t
int64_t int64_t
Definition: types.hpp:61
qi::IteratorTypeInterface
Definition: typeinterface.hpp:164
QI_API
#define QI_API
Definition: api.hpp:33
qi::detail::pushBack
void pushBack(T &container, E *element)
Definition: listtypeinterface.hxx:95
qi::makeFloatType
TypeInterface * makeFloatType(int bytelen)
structtypeinterface.hxx
qi::TypeKind_Dynamic
Definition: fwd.hpp:66
qi::StringTypeInterface::Deleter
boost::function< void(const RawString &)> Deleter
Definition: typeinterface.hpp:108
buffertypeinterface.hxx
qi::OptionalTypeInterface
Definition: typeinterface.hpp:334
qi::AnyReference
Definition: anyreference.hpp:360
qi::TypeKind_VarArgs
Definition: fwd.hpp:72
fwd.hpp
api.hpp
dll import/export and compiler message
qi::TypeKind_Optional
Definition: fwd.hpp:73
qi::VarArgsTypeInterface
Definition: typeinterface.hpp:323
qi::IteratorTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:180
qi::makeTypeOfKind
TypeInterface * makeTypeOfKind(const qi::TypeKind &kind)
qi::StringTypeInterface::ManagedRawString
std::pair< RawString, Deleter > ManagedRawString
Definition: typeinterface.hpp:109
qi::RawTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:134
qi::MapTypeInterface
Definition: typeinterface.hpp:213
listtypeinterface.hxx
inttypeinterface.hxx
qi::TypeInterface
Definition: typeinterface.hpp:129
qi::OptionalTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:347
signature.hpp
qi::DynamicTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:317
qi::makeMapType
TypeInterface * makeMapType(TypeInterface *keyType, TypeInterface *ElementType)
qi::AnyReferenceVector
std::vector< AnyReference > AnyReferenceVector
Definition: anyreference.hpp:26
qi::TypeKind_Pointer
Definition: fwd.hpp:64
optionaltypeinterface.hxx
qi::TypeKind_Int
Definition: fwd.hpp:58
qi::MapTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:236
qi::TypeKind_List
Definition: fwd.hpp:61
qi::StructTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:262
qi::FloatTypeInterface
Definition: typeinterface.hpp:92
typeimpl.hxx
maptypeinterface.hxx
qi::StringTypeInterface::RawString
std::pair< char *, size_t > RawString
Definition: typeinterface.hpp:107
qi::makeVarArgsType
TypeInterface * makeVarArgsType(TypeInterface *elementType)
qi::PointerTypeInterface::Shared
Definition: typeinterface.hpp:143
qi::makeOptionalType
TypeInterface * makeOptionalType(TypeInterface *valueType)
qi::PointerTypeInterface::PointerKind
PointerKind
Definition: typeinterface.hpp:140
qi::TypeKind_Float
Definition: fwd.hpp:59
qi::VarArgsTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:328
type.hxx
qi::StructTypeInterface::elementsName
virtual std::vector< std::string > elementsName()
Get the names of the fields of the struct.
Definition: typeinterface.hpp:264
stringtypeinterface.hxx
qi::makeIntType
TypeInterface * makeIntType(bool issigned, int bytelen)
qi::RawTypeInterface
Definition: typeinterface.hpp:127
qi::detail::QI_API_DEPRECATED_MSG
struct QI_API_DEPRECATED_MSG(Use 'QI_TYPE_ENUM'instead) QI_TYPE_ENUM_REGISTER_
Definition: typeinterface.hpp:411
qi::makeListType
TypeInterface * makeListType(TypeInterface *elementType)
qi::IntTypeInterface
Definition: typeinterface.hpp:78
qi::PointerTypeInterface
Definition: typeinterface.hpp:137
qi::PointerTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:155
qi::TypeKind_String
Definition: fwd.hpp:60
qi::log::env::QI_DEFAULT_LOGHANDLER::name
char const *const name
qi::TypeKind_Tuple
Definition: fwd.hpp:65
qi::FloatTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:101
qi::DynamicTypeInterface
Definition: typeinterface.hpp:310
qi::TypeKind
TypeKind
Definition: fwd.hpp:54
log.hpp
Convenient log macro.
qi::PointerTypeInterface::Raw
Definition: typeinterface.hpp:142
typeinterface.hpp
qi::StructTypeInterface::convertTo
virtual bool convertTo(std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::tuple< std::string, TypeInterface * >> &missing, const std::map< std::string,::qi::AnyReference > &dropfields)
Fill missing fields caused by conversion to a different struct. Return whether fill succeeded...
Definition: typeinterface.hpp:295
qi::ListTypeInterface
Definition: typeinterface.hpp:188
qi::StringTypeInterface::kind
TypeKind kind() override
Definition: typeinterface.hpp:120
qi::TypeKind_Iterator
Definition: fwd.hpp:68
qi::StructTypeInterface
Definition: typeinterface.hpp:241
qi::TypeKind_Raw
Definition: fwd.hpp:67
QI_NO_TYPE
#define QI_NO_TYPE(T)
Definition: typeinterface.hpp:48
pointertypeinterface.hxx