libqi-api  2.8.7.4
 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>
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:
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>
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>
66  {
67  using type = T;
68  };
69 
70  template <typename T>
72 
73  template<typename T>
74  struct TypeOfAdapter<T&>
75  {
77  };
78 
79  template<typename T>
80  struct TypeOfAdapter<const T>
81  {
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>
95  {
96  return detail::typeOfBackend<detail::TypeOfAdapter_t<T>>();
97  }
98 
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>
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  */
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>
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>
137 
138  template<template<typename> class T, typename I>
140 }
141 
142 #endif // _QITYPE_DETAIL_TYPE_HXX_
TypeOfAdapter_t< T > type
Definition: type.hxx:76
TypeInterface * getType(const TypeIndex &typeId)
Runtime Type factory getter. Used by typeOf<T>()
#define qiLogDebug(...)
Definition: log.hpp:76
virtual TypeKind kind()
Definition: type.hxx:99
class QITYPE_TEMPLATE_API TypeOfTemplate
Definition: type.hxx:136
#define QITYPE_TEMPLATE_API
Definition: api.hpp:66
typename TypeImplMethodsBySize< T >::type TypeImplMethodsBySize_t
Definition: type.hxx:130
TypeInterface * typeOfBackend()
Definition: type.hxx:51
#define QI_ONCE(code)
Execute code once, parallel calls are blocked until code finishes.
Definition: atomic.hpp:420
TypeInterface * typeOf()
Definition: type.hxx:94
TypeKind
Definition: fwd.hpp:54
typename TypeOfAdapter< T >::type TypeOfAdapter_t
Definition: type.hxx:71
TypeOfAdapter_t< T > type
Definition: type.hxx:82
typename std::add_pointer< typename std::remove_const< TypeOfAdapter_t< T >>::type >::type type
Definition: type.hxx:88
void initializeType(TypeInterface *&tgt)
Definition: type.hxx:44