libqi-api  2.4.3.28
 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_DETAILS_TYPE_HXX_
8 #define _QITYPE_DETAILS_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 " << typeid(T).name();
47  tgt = new TypeImpl<T>();
48  }
49 
50  template<typename T>
52  {
53  TypeInterface* result = getType(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  typedef T type;
68  };
69 
70  template<typename T>
71  struct TypeOfAdapter<T&>
72  {
73  typedef typename TypeOfAdapter<T>::type type;
74  };
75 
76  template<typename T>
77  struct TypeOfAdapter<const T>
78  {
79  typedef typename TypeOfAdapter<T>::type type;
80  };
81 
82  template<typename T>
83  struct TypeOfAdapter<T*>
84  {
85  typedef typename boost::add_pointer<typename boost::remove_const<typename TypeOfAdapter<T>::type>::type>::type type;
86  };
87 
88  }
89 
90  template<typename T>
92  {
93  return detail::typeOfBackend<typename detail::TypeOfAdapter<T>::type>();
94  }
95 
97  {
98  return TypeKind_Unknown;
99  }
100 
101  namespace detail {
102 
103  // Bouncer to DefaultAccess or DirectAccess based on type size
104  template<typename T>
106  {
107  public:
108  /* DISABLE. Inplace modification does not work with TypeByValue.
109  * TODO: be able to switch between ByVal and ByPointer on the
110  * same type.
111  */
113  /*
114  typedef typename boost::mpl::if_c<
115  sizeof(T) <= sizeof(void*),
116  DefaultTypeImplMethods<T,
117  TypeByValue<T>
118  >,
119  DefaultTypeImplMethods<T,
120  TypeByPointer<T>
121  >
122  >::type type;
123  */
124  };
125  }
126 
127  // To detect a templated type, make all the Type of its instanciations
128  // inherit fro a single class
129  template<template<typename> class T>
131 
132  template<template<typename> class T, typename I>
134 }
135 
136 #endif // _QITYPE_DETAILS_TYPE_HXX_
#define qiLogDebug(...)
Definition: log.hpp:69
virtual TypeKind kind()
Definition: type.hxx:96
class QITYPE_TEMPLATE_API TypeOfTemplate
Definition: type.hxx:130
DefaultTypeImplMethods< T > type
Definition: type.hxx:112
#define QITYPE_TEMPLATE_API
Definition: api.hpp:47
TypeInterface * getType(const std::type_info &type)
Runtime Type factory getter. Used by typeOf<T>()
TypeOfAdapter< T >::type type
Definition: type.hxx:73
TypeInterface * typeOfBackend()
Definition: type.hxx:51
#define QI_ONCE(code)
Execute code once, parallel calls are blocked until code finishes.
Definition: atomic.hpp:298
TypeInterface * typeOf()
Definition: type.hxx:91
TypeKind
Definition: fwd.hpp:53
boost::add_pointer< typename boost::remove_const< typename TypeOfAdapter< T >::type >::type >::type type
Definition: type.hxx:85
TypeOfAdapter< T >::type type
Definition: type.hxx:79
void initializeType(TypeInterface *&tgt)
Definition: type.hxx:44