- 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
pointertypeinterface.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_TYPEPOINTER_HXX_
8 #define _QITYPE_DETAIL_TYPEPOINTER_HXX_
9
10 #include <boost/shared_ptr.hpp>
11
12 namespace qi
13 {
14 template<typename T> class PointerTypeInterfaceImpl: public PointerTypeInterface
15 {
16 public:
17 TypeInterface* pointedType() override
18 {
19 // Caching the result here is dangerous if T uses runtime factory.
20 return typeOf<T>();
21 }
22 PointerKind pointerKind() override { return Raw; }
23 AnyReference dereference(void* storage) override
24 {
25 // We are in DirectAccess mode, so storage is a T*.
26 void* value = pointedType()->initializeStorage(storage);
27 return AnyReference(pointedType(), value);
28 }
29
30 void set(void** storage, AnyReference pointer) override
31 {
32 AnyReference obj = *pointer;
33 *storage = obj.rawValue();
34 }
35
36 void setPointee(void** storage, void* pointer) override
37 {
38 *storage = pointer;
39 }
40
41 using TypeMethodsImpl = DefaultTypeImplMethods<T*, TypeByValue<T*>>;
42 _QI_BOUNCE_TYPE_METHODS(TypeMethodsImpl);
43 };
44
45 template<typename T> class TypeImpl<T*>: public PointerTypeInterfaceImpl<T>{};
46
47 template<typename T> class TypeSharedPointerImpl: public PointerTypeInterface
48 {
49 public:
50 TypeInterface* pointedType() override
51 {
52 return typeOf<typename T::element_type>();
53 }
54 PointerKind pointerKind() override { return Shared; }
55 AnyReference dereference(void* storage) override
56 {
57 T* ptr = (T*)ptrFromStorage(&storage);
58 void *value = pointedType()->initializeStorage(ptr->get());
59 return AnyReference(pointedType(), value);
60 }
61 void set(void** storage, AnyReference pointer) override
62 {
63 T* ptr = (T*)ptrFromStorage(storage);
64 T* otherPtr = (T*)pointer.rawValue();
65 *ptr = *otherPtr;
66 }
67 void setPointee(void** storage, void* pointer) override
68 {
69 // we can't do that as it means that we would take ownership of pointer
70 throw std::runtime_error("cannot convert to shared_ptr");
71 }
72 using Impl = DefaultTypeImplMethods<T, TypeByPointerPOD<T>>;
73 _QI_BOUNCE_TYPE_METHODS(Impl);
74 };
75
76 template<typename T> class TypeImpl<boost::shared_ptr<T> >: public TypeSharedPointerImpl<boost::shared_ptr<T> >{};
77 }
78
79 #endif // _QITYPE_DETAIL_TYPEPOINTER_HXX_
qi::TypeInterface::ptrFromStorage
virtual void * ptrFromStorage(void **)=0
qi::TypeImpl
Definition: typeimpl.hxx:300
qi::PointerTypeInterfaceImpl::set
void set(void **storage, AnyReference pointer) override
Set new pointee value. pointer must be a pointer to type pointedType()
Definition: pointertypeinterface.hxx:30
qi::PointerTypeInterfaceImpl::_QI_BOUNCE_TYPE_METHODS
_QI_BOUNCE_TYPE_METHODS(TypeMethodsImpl)
qi::TypeSharedPointerImpl::_QI_BOUNCE_TYPE_METHODS
_QI_BOUNCE_TYPE_METHODS(Impl)
qi::TypeSharedPointerImpl::pointedType
TypeInterface * pointedType() override
Get the type of the pointed element.
Definition: pointertypeinterface.hxx:50
qi::AnyReference
Definition: anyreference.hpp:360
qi::PointerTypeInterfaceImpl::dereference
AnyReference dereference(void *storage) override
Get the pointed element (must not be destroyed)
Definition: pointertypeinterface.hxx:23
qi::TypeInterface::initializeStorage
virtual void * initializeStorage(void *ptr=nullptr)=0
qi::PointerTypeInterfaceImpl::setPointee
void setPointee(void **storage, void *pointer) override
Set new pointee value. pointer must be a pointer to type pointedType()
Definition: pointertypeinterface.hxx:36
qi::TypeSharedPointerImpl::setPointee
void setPointee(void **storage, void *pointer) override
Set new pointee value. pointer must be a pointer to type pointedType()
Definition: pointertypeinterface.hxx:67
qi::TypeInterface
Definition: typeinterface.hpp:129
qi::TypeSharedPointerImpl::dereference
AnyReference dereference(void *storage) override
Get the pointed element (must not be destroyed)
Definition: pointertypeinterface.hxx:55
qi::DefaultTypeImplMethods
Definition: typeimpl.hxx:228
qi::detail::AnyReferenceBase::rawValue
void * rawValue() const
Definition: anyreference.hpp:351
qi::PointerTypeInterface::Shared
Definition: typeinterface.hpp:143
qi::PointerTypeInterface::PointerKind
PointerKind
Definition: typeinterface.hpp:140
qi::TypeSharedPointerImpl::pointerKind
PointerKind pointerKind() override
Return whether the pointer has raw or shared semantics.
Definition: pointertypeinterface.hxx:54
qi::PointerTypeInterface
Definition: typeinterface.hpp:137
qi::TypeSharedPointerImpl::set
void set(void **storage, AnyReference pointer) override
Set new pointee value. pointer must be a pointer to type pointedType()
Definition: pointertypeinterface.hxx:61
qi::PointerTypeInterface::Raw
Definition: typeinterface.hpp:142
qi::PointerTypeInterfaceImpl::pointerKind
PointerKind pointerKind() override
Return whether the pointer has raw or shared semantics.
Definition: pointertypeinterface.hxx:22
qi::PointerTypeInterfaceImpl
Definition: pointertypeinterface.hxx:14
qi::TypeSharedPointerImpl
Definition: pointertypeinterface.hxx:47
qi::PointerTypeInterfaceImpl::pointedType
TypeInterface * pointedType() override
Get the type of the pointed element.
Definition: pointertypeinterface.hxx:17