ADTF  3.14.2
object_ptr.h
Go to the documentation of this file.
1 
7 #ifndef _ADTF_UCOM_ANT_OBJECT_PTR_IMPLEMENTATION_HEADER_
8 #define _ADTF_UCOM_ANT_OBJECT_PTR_IMPLEMENTATION_HEADER_
9 
10 namespace adtf
11 {
12 namespace ucom
13 {
14 namespace ant
15 {
16 
18 template<typename T>
20 {
21 protected:
26 public:
27 
32 #ifndef _MSC_VER
33  // see ACORE-9344, workaround for gcc de-virtualization behaviour
34  __attribute__((noinline))
35 #endif
36  virtual operator const iobject_ptr<const T>& () const
37  {
38  return *reinterpret_cast<const object_ptr_const_conversion<const T>*>(this);
39  }
40 };//template<typename T> class object_ptr_const_conversion
41 
43 template<typename T>
44 class object_ptr_const_conversion<const T> : public iobject_ptr<const T>
45 {
46 protected:
51 };//template<typename T> class object_ptr_const_conversion<const T>
52 
59 template<typename T,
60  bool = std::is_class<T>::value &&
61  detail::has_interface_info_type<typename std::remove_cv<T>::type>::value,
62  typename = object_ptr<T>
63  >
65 
75 template<typename T, typename TChild>
76 class object_ptr_base<T, false, TChild> : public object_ptr_const_conversion<T>
77 {
79 
80 public:
87  operator const iobject_ptr<object_type>& () const
88  { //use CRTP to access the private area of the object_ptr (which is the child of this)
89  return static_cast<const TChild* const>(this)->m_oDelegateObject;
90  }
91 };//template<typename T, typename TChild> class object_ptr_base<T, false, TChild>
92 
97 template<typename T, typename TChild>
98 class object_ptr_base<T, true, TChild> : public object_ptr_const_conversion<T>
99 
100 {
102 
103 public: //implement implicit cast with CRTP
111  { //use CRTP to access the private area of the object_ptr (which is the child of this)
112  return static_cast<TChild* const>(this)->m_oDelegateObject;
113  }
114 
121  operator const iobject_ptr<object_type>& () const
122  { //use CRTP to access the private area of the object_ptr (which is the child of this)
123  return static_cast<const TChild* const>(this)->m_oDelegateObject;
124  }
125 
126 protected:
128  constexpr object_ptr_base()
129  {
130  static_assert(!std::is_same<TChild, object_ptr<object_type>>::value,
131  "object_ptr<IObject> already implicitly convertible to iobject_ptr<IObject>");
132  }
133 };//template<typename T, typename TChild> class object_ptr_base<T, true, TChild>
134 
136 template<> class object_ptr_base<IObject> : public object_ptr_const_conversion<IObject> {};
137 
139 template<> class object_ptr_base<const IObject> : public iobject_ptr<const IObject> {};
140 
156 template<typename T>
157 class object_ptr : public object_ptr_base<T>
158 {
160  template<typename> friend class detail::delegate_object_ptr;
161 
162  template<typename Implementation, typename ...Args> friend
163  typename std::enable_if
164  <
165  !std::is_base_of
166  <
168  typename std::remove_cv<Implementation>::type
169  >::value,
171  >::type
172  make_object_ptr(Args&&... args);
173 
174  template<typename Implementation, typename ...Args> friend
175  typename std::enable_if
176  <
177  std::is_base_of
178  <
180  typename std::remove_cv<Implementation>::type
181  >::value,
183  >::type
184  make_object_ptr(Args&&... args);
185 
186  friend class object_ptr_base<T, true, object_ptr<T>>;
187  friend class object_ptr_base<T, false, object_ptr<T>>;
188  friend class weak_object_ptr<T>;
189 
190 private: //member section
199  template<typename U>
200  object_ptr(U* pSharedObject) :
201  m_oDelegateObject(nullptr != pSharedObject
202  ? new (std::nothrow) detail::object_reference_counter(pSharedObject)
203  : nullptr,
204  ucom_cast<T*>(pSharedObject))
205  {
206  }
207 
209  typedef detail::object_reference_counter::size_type size_type;
210 
215  virtual detail::iobject_ptr_ref<size_type>* GetObjPtrRef() const
216  {
217  return m_oDelegateObject.m_pRefer;
218  }
219 
220 private: //data section
222  typedef detail::delegate_object_ptr<T> storage_type;
224  storage_type m_oDelegateObject;
227 public:
229  object_ptr() : m_oDelegateObject()
230  {
231  }
232 
234  virtual ~object_ptr() = default;
235 
237  object_ptr(std::nullptr_t) : object_ptr()
238  {
239  }
240 
245  object_ptr(const object_ptr& i_oOther) :
246  object_ptr(static_cast<const iobject_ptr<T>&>(i_oOther))
247  {
248  }
249 
254  object_ptr(const iobject_ptr<T>& i_oOther) :
255  m_oDelegateObject(i_oOther.GetObjPtrRef(), i_oOther.Get())
256  {
257  }
258 
264  template<typename U>
265  object_ptr(const iobject_ptr<U>& i_oOther) :
266  object_ptr(ucom_object_ptr_cast<T, U>(i_oOther))
267  {
268  }
269 
276  template<typename U>
277  object_ptr(const iobject_ptr<U>& i_oOther, T* pSharedObject)
278  : m_oDelegateObject(i_oOther.GetObjPtrRef(), pSharedObject)
279  {
280  }
281 
287  {
288  Swap(i_oOther); //leave move-from object in valid but unspecified state
289  }
290 
299  template<typename U>
300  object_ptr(const weak_object_ptr<U>& i_pWeak) :
301  m_oDelegateObject(i_pWeak)
302  {
303  }
304 
314  {
315  Swap(i_oOther);
316  return *this;
317  }
318 
325  template<typename U>
327  {
328  *this = ucom_object_ptr_cast<T, U>(i_oOther);
329  return *this;
330  }
331 
336  T& operator*() const
337  {
338  return *Get();
339  }
340 
345  explicit operator bool() const
346  {
347  return (Get() != nullptr);
348  }
349 
356  void Reset()
357  {
358  *this = object_ptr();
359  }
360 
366  void Swap(object_ptr& o_oOther)
367  {
368  m_oDelegateObject.Swap(o_oOther.m_oDelegateObject);
369  }
370 
371 public: //implement iobject_ptr
376  virtual T* Get() const
377  {
378  return m_oDelegateObject.m_pSharedObject;
379  }
380 
385  virtual T* operator->() const
386  {
387  return Get();
388  }
389 
397  virtual tResult Reset(const iobject_ptr<T>& i_oOther)
398  {
399  *this = i_oOther;
400  return ERR_NOERROR;
401  }
402 };//class object_ptr<>
403 
404 }//ns ant
405 
407 template<class T>
409 
410 }//ns ucom
411 }//ns adtf
412 
413 //specializing the swap function to enable best match for compiler
415 namespace std
416 {
417  template<typename T>
418  inline void swap(adtf::ucom::ant::object_ptr<T>& i_oLHS,
420  {
421  i_oLHS.Swap(i_oRHS);
422  }
423 }//ns std
425 
426 #endif //_ADTF_UCOM_ANT_OBJECT_PTR_IMPLEMENTATION_HEADER_
Base class for every interface type within the uCOM.
Definition: object_intf.h:31
Safely retrieve a valid object_ptr<> instance to *this when all we have is *this.
Base object pointer to realize binary compatible reference counting in interface methods.
Base object pointer to realize binary compatible reference counting in interface methods.
iobject_ptr< T >::object_type object_type
const correct IObject type
Definition: object_ptr.h:78
constexpr object_ptr_base()
Used to test whether object_ptr<IObject> is not inherited from this base.
Definition: object_ptr.h:128
iobject_ptr< T >::object_type object_type
const correct IObject type
Definition: object_ptr.h:101
Base class for object_ptr<>
Definition: object_ptr.h:64
Disables implicit conversion operators to iobject_ptr<const T> (implemented through inheritance)
Definition: object_ptr.h:45
Enables implicit conversion operators to iobject_ptr<const T>
Definition: object_ptr.h:20
__attribute__((noinline)) virtual operator const iobject_ptr< const T > &() const
Enable implicit conversion to const value type for pointer-like behavior.
Definition: object_ptr.h:34
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:158
virtual tResult Reset(const iobject_ptr< T > &i_oOther)
Reset this object_ptr<> with the content of another iobject_ptr<>
Definition: object_ptr.h:397
void Reset()
Reset this object_ptr.
Definition: object_ptr.h:356
object_ptr & operator=(object_ptr i_oOther)
Assignment operator.
Definition: object_ptr.h:313
object_ptr(std::nullptr_t)
nullptr_t construction - the object_ptr<T> is created empty
Definition: object_ptr.h:237
object_ptr(object_ptr &&i_oOther)
Move constructor.
Definition: object_ptr.h:286
object_ptr()
Default constructor - the object_ptr<T> is created empty.
Definition: object_ptr.h:229
object_ptr(const weak_object_ptr< U > &i_pWeak)
Construct from weak_object_ptr<>
Definition: object_ptr.h:300
T & operator*() const
Operator* overload to treat object_ptr<> types like real pointers.
Definition: object_ptr.h:336
object_ptr(const iobject_ptr< U > &i_oOther, T *pSharedObject)
Aliasing constructor for iobject_ptr containing a different type.
Definition: object_ptr.h:277
virtual T * operator->() const
Operator-> overload to treat object_ptr<> types like real pointers.
Definition: object_ptr.h:385
virtual T * Get() const
Get pointer to shared object.
Definition: object_ptr.h:376
void Swap(object_ptr &o_oOther)
Swap content of *this with o_oOther (only shallow copies are performed!)
Definition: object_ptr.h:366
object_ptr(const object_ptr &i_oOther)
Copy constructor.
Definition: object_ptr.h:245
object_ptr & operator=(const object_ptr< U > &i_oOther)
Assignment operator for object_ptr containing a different type.
Definition: object_ptr.h:326
object_ptr(const iobject_ptr< T > &i_oOther)
Copy constructor for base type.
Definition: object_ptr.h:254
virtual ~object_ptr()=default
default destruction
object_ptr(const iobject_ptr< U > &i_oOther)
Copy constructor for iobject_ptr containing a different type.
Definition: object_ptr.h:265
Implementation of a weak pointer for usage with iobject_ptr and object_ptr.
void swap(StackPtr< T, StackSize, Alignment > &lhs, StackPtr< T, StackSize, Alignment > &rhs)
Swap storages of two objects of type StackPtr.
std::enable_if< !std::is_base_of< enable_object_ptr_from_this< typename std::remove_cv< Implementation >::type >, typename std::remove_cv< Implementation >::type >::value, object_ptr< Implementation > >::type make_object_ptr(Args &&... args)
Create an instance of type object_ptr with Implementation as the shared resource.
object_ptr< T > ucom_object_ptr_cast(const iobject_ptr< U > &i_oOther)
Create an object_ptr with a already shared resource of implicitly convertible type.
Namespace for entire ADTF SDK.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Tue May 10 2022 by doxygen 1.9.1)