- 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
type.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 #ifndef _QITYPE_DETAIL_TYPE_HXX_
8 #define _QITYPE_DETAIL_TYPE_HXX_
9
10 #include <qi/atomic.hpp>
11 #include <qi/types.hpp>
12 #include <cstring>
13 #include <map>
14 #include <vector>
15 #include <list>
16 #include <qi/type/detail/bindtype.hxx>
17 #include <boost/thread/mutex.hpp>
18 #include <boost/mpl/for_each.hpp>
19 #include <boost/mpl/transform_view.hpp>
20 #include <boost/type_traits/remove_reference.hpp>
21 #include <boost/type_traits/add_pointer.hpp>
22 #include <boost/function_types/parameter_types.hpp>
23 #include <boost/function_types/result_type.hpp>
24 #include <boost/function_types/function_type.hpp>
25 #include <boost/function_types/is_member_pointer.hpp>
26
27 /* This file contains the default-provided Type specialisations
28 *
29 */
30
31
32 namespace qi {
33
34 namespace detail {
35
36 // Try to get a nice error message for QI_NO_TYPE
37 class ForbiddenInTypeSystem: public TypeImpl<int>
38 {
39 private:
40 ForbiddenInTypeSystem();
41 };
42
43 template<typename T>
44 inline void initializeType(TypeInterface* &tgt)
45 {
46 qiLogDebug("qitype.typeof") << "first typeOf request for unregistered type " << qi::typeId<T>().name();
47 tgt = new TypeImpl<T>();
48 }
49
50 template<typename T>
51 inline TypeInterface* typeOfBackend()
52 {
53 TypeInterface* result = getType(qi::typeId<T>());
54 if (!result)
55 {
56
57 static TypeInterface* defaultResult = 0;
58 QI_ONCE(initializeType<T>(defaultResult));
59 result = defaultResult;
60 }
61 return result;
62 }
63
64 template<typename T>
65 struct TypeOfAdapter
66 {
67 using type = T;
68 };
69
70 template <typename T>
71 using TypeOfAdapter_t = typename TypeOfAdapter<T>::type;
72
73 template<typename T>
74 struct TypeOfAdapter<T&>
75 {
76 using type = TypeOfAdapter_t<T>;
77 };
78
79 template<typename T>
80 struct TypeOfAdapter<const T>
81 {
82 using type = TypeOfAdapter_t<T>;
83 };
84
85 template<typename T>
86 struct TypeOfAdapter<T*>
87 {
88 using type = typename std::add_pointer<typename std::remove_const<TypeOfAdapter_t<T>>::type>::type;
89 };
90
91 }
92
93 template<typename T>
94 TypeInterface* typeOf()
95 {
96 return detail::typeOfBackend<detail::TypeOfAdapter_t<T>>();
97 }
98
99 inline TypeKind TypeInterface::kind()
100 {
101 return TypeKind_Unknown;
102 }
103
104 namespace detail {
105
106 // Bouncer to DefaultAccess or DirectAccess based on type size
107 template<typename T>
108 class TypeImplMethodsBySize
109 {
110 public:
111 /* DISABLE. Inplace modification does not work with TypeByValue.
112 * TODO: be able to switch between ByVal and ByPointer on the
113 * same type.
114 */
115 using type = DefaultTypeImplMethods<T>;
116 /*
117 typedef typename boost::mpl::if_c<
118 sizeof(T) <= sizeof(void*),
119 DefaultTypeImplMethods<T,
120 TypeByValue<T>
121 >,
122 DefaultTypeImplMethods<T,
123 TypeByPointer<T>
124 >
125 >::type type;
126 */
127 };
128
129 template <typename T>
130 using TypeImplMethodsBySize_t = typename TypeImplMethodsBySize<T>::type;
131 }
132
133 // To detect a templated type, make all the Type of its instanciations
134 // inherit fro a single class
135 template<template<typename> class T>
136 class QITYPE_TEMPLATE_API TypeOfTemplate;
137
138 template<template<typename> class T, typename I>
139 class TypeOfTemplateImpl;
140 }
141
142 #endif // _QITYPE_DETAIL_TYPE_HXX_
qi::TypeImpl
Definition: typeimpl.hxx:300
bindtype.hxx
qi::detail::TypeOfAdapter< T & >::type
TypeOfAdapter_t< T > type
Definition: type.hxx:76
qi::getType
TypeInterface * getType(const TypeIndex &typeId)
Runtime Type factory getter. Used by typeOf<T>()
qiLogDebug
#define qiLogDebug(...)
Definition: log.hpp:76
qi::TypeInterface::kind
virtual TypeKind kind()
Definition: type.hxx:99
qi::TypeOfTemplate
class QITYPE_TEMPLATE_API TypeOfTemplate
Definition: type.hxx:136
types.hpp
qi::TypeKind_Unknown
Definition: fwd.hpp:56
qi::detail::ForbiddenInTypeSystem
Definition: type.hxx:37
qi::detail::TypeOfAdapter::type
T type
Definition: type.hxx:67
qi::TypeInterface
Definition: typeinterface.hpp:129
QITYPE_TEMPLATE_API
#define QITYPE_TEMPLATE_API
Definition: api.hpp:66
qi::detail::TypeImplMethodsBySize
Definition: type.hxx:108
qi::detail::TypeImplMethodsBySize_t
typename TypeImplMethodsBySize< T >::type TypeImplMethodsBySize_t
Definition: type.hxx:130
qi::detail::typeOfBackend
TypeInterface * typeOfBackend()
Definition: type.hxx:51
qi::DefaultTypeImplMethods
Definition: typeimpl.hxx:228
QI_ONCE
#define QI_ONCE(code)
Execute code once, parallel calls are blocked until code finishes.
Definition: atomic.hpp:420
qi::TypeOfTemplateImpl
Definition: type.hxx:139
atomic.hpp
qi::typeOf
TypeInterface * typeOf()
Definition: type.hxx:94
qi::log::env::QI_DEFAULT_LOGHANDLER::name
char const *const name
qi::TypeKind
TypeKind
Definition: fwd.hpp:54
qi::detail::TypeOfAdapter_t
typename TypeOfAdapter< T >::type TypeOfAdapter_t
Definition: type.hxx:71
qi::detail::TypeOfAdapter< const T >::type
TypeOfAdapter_t< T > type
Definition: type.hxx:82
qi::detail::TypeOfAdapter
Definition: type.hxx:65
qi::detail::TypeOfAdapter< T * >::type
typename std::add_pointer< typename std::remove_const< TypeOfAdapter_t< T >>::type >::type type
Definition: type.hxx:88
qi::detail::initializeType
void initializeType(TypeInterface *&tgt)
Definition: type.hxx:44