- 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
accessor.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_ACCESSOR_HXX_
8 #define _QITYPE_DETAIL_ACCESSOR_HXX_
9
10 #include <boost/type_traits.hpp>
11 #include <boost/utility/enable_if.hpp>
12
13 namespace qi
14 {
18 namespace detail
19 {
20 template<typename T, typename Void = void> struct Accessor
21 {
22 using is_accessor = boost::false_type;
23 };
24 template<typename C, typename T> struct AccessorBase
25 {
26 using is_accessor = boost::true_type;
27 using value_type = typename boost::remove_const<T>::type;
28 using class_type = C;
29 };
30 // we must explicitely check for is_member_object_pointer because T C::*
31 // can match functions also even if it may not make sense
32 template<typename C, typename T> struct Accessor<T C::*, typename boost::enable_if<typename boost::is_member_object_pointer<T C::*> >::type >
33 : public AccessorBase<C, T>
34 {
35 using type = T C::*;
36 static T& access(C* instance, type acc)
37 {
38 return *instance.*acc;
39 }
40 };
41 template<typename C, typename T> struct Accessor<T& (C::*)()>
42 : public AccessorBase<C, T>
43 {
44 using type = T& (C::*)();
45 static T& access(C* instance, type acc)
46 {
47 return (*instance.*acc)();
48 }
49 };
50 template<typename C, typename T> struct Accessor<T& (C::*)() const>
51 : public AccessorBase<C, T>
52 {
53 using type = T& (C::*)() const;
54 static T& access(C* instance, type acc)
55 {
56 return (*instance.*acc)();
57 }
58 };
59 template<typename C, typename T> struct Accessor<T& (*)(C*)>
60 : public AccessorBase<C, T>
61 {
62 using type = T& (*)(C*);
63 static T& access(C* instance, type acc)
64 {
65 return acc(instance);
66 }
67 };
68 }
69 }
70
71 #endif // _QITYPE_DETAIL_ACCESSOR_HXX_
72
73
qi::detail::AccessorBase::value_type
typename boost::remove_const< T >::type value_type
Definition: accessor.hxx:27
qi::detail::AccessorBase
Definition: accessor.hxx:24
qi::detail::AccessorBase::class_type
C class_type
Definition: accessor.hxx:28
qi::detail::AccessorBase::is_accessor
boost::true_type is_accessor
Definition: accessor.hxx:26