libqi-api  2.4.3.28
 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_DETAILS_TYPEPOINTER_HXX_
8 #define _QITYPE_DETAILS_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:
18  {
19  // Caching the result here is dangerous if T uses runtime factory.
20  return typeOf<T>();
21  }
22  PointerKind pointerKind() { return Raw; }
23  AnyReference dereference(void* storage)
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 setPointee(void** storage, void* pointer)
31  {
32  *storage = pointer;
33  }
34 
35  typedef DefaultTypeImplMethods<T*,
39  };
40 
41  template<typename T> class TypeImpl<T*>: public PointerTypeInterfaceImpl<T>{};
42 
43  template<typename T> class TypeSharedPointerImpl: public PointerTypeInterface
44  {
45  public:
47  {
48  return typeOf<typename T::element_type>();
49  }
51  AnyReference dereference(void* storage)
52  {
53  T* ptr = (T*)ptrFromStorage(&storage);
54  void *value = pointedType()->initializeStorage(ptr->get());
55  return AnyReference(pointedType(), value);
56  }
57  void setPointee(void** storage, void* pointer)
58  {
59  T* ptr = (T*)ptrFromStorage(storage);
60  *ptr = T((typename T::element_type*)pointer);
61  }
64  };
65 
66  template<typename T> class TypeImpl<boost::shared_ptr<T> >: public TypeSharedPointerImpl<boost::shared_ptr<T> >{};
67 }
68 
69 #endif // _QITYPE_DETAILS_TYPEPOINTER_HXX_
virtual void * ptrFromStorage(void **)=0
_QI_BOUNCE_TYPE_METHODS(TypeMethodsImpl)
void setPointee(void **storage, void *pointer)
Set new pointee value. pointer must be a pointer to type pointedType()
DefaultTypeImplMethods< T, TypeByPointerPOD< T > > Impl
TypeInterface * pointedType()
Get the type of the pointed element.
PointerKind pointerKind()
Return whether the pointer has raw or shared semantics.
DefaultTypeImplMethods< T *, TypeByValue< T * > > TypeMethodsImpl
PointerKind pointerKind()
Return whether the pointer has raw or shared semantics.
TypeInterface * pointedType()
Get the type of the pointed element.
AnyReference dereference(void *storage)
Get the pointed element (must not be destroyed)
AnyReference dereference(void *storage)
Get the pointed element (must not be destroyed)
void setPointee(void **storage, void *pointer)
Set new pointee value. pointer must be a pointer to type pointedType()
Access api that stores a T in storage.
Definition: typeimpl.hxx:184
virtual void * initializeStorage(void *ptr=0)=0