ADTF
Loading...
Searching...
No Matches
object_ptr_intf.h
Go to the documentation of this file.
1
7#pragma once
8
10#include <a_utils/core/result.h>
11
12#include <cstddef>
13#include <type_traits>
14
15namespace adtf
16{
17namespace ucom
18{
19namespace ant
20{
21
22template<typename T> class iobject_ptr;
23
25namespace detail
26{
27
31template<typename TSize>
32class DOEXPORT iobject_ptr_ref
33{
34protected: // types
35 typedef TSize size_type;
36
37protected: // construction/destruction
39 ~iobject_ptr_ref() = default;
40
41public:
42 virtual void IncreaseUseCount() = 0;
43 virtual void DecreaseUseCount() = 0;
44
45 virtual void IncreaseWeakCount() = 0;
46 virtual void DecreaseWeakCount() = 0;
47
48 virtual bool IncreaseUseCountNonZero() = 0;
49}; // class iobject_ptr_ref
50
51} // namespace detail
53
58template<typename T>
59class DOEXPORT iobject_ptr_base
60{
61public: // types
62 typedef T element_type;
63
64protected: // construction/destruction
66 ~iobject_ptr_base() = default;
67
68public: // observer
73 virtual T* Get() const = 0;
74
85 virtual tResult Reset(const iobject_ptr<T>& i_oOther) = 0;
86
91 virtual T* operator->() const = 0;
92
93 virtual detail::iobject_ptr_ref<size_t>* GetObjPtrRef() const = 0;
94
99 T& operator*() const noexcept
100 {
101 return *Get();
102 }
103
104}; // class iobject_ptr_base<>
105
110template<typename T>
111class DOEXPORT iobject_ptr : public iobject_ptr_base<T>
112{
113protected: // construction/destruction
115 ~iobject_ptr() = default;
116
117public:
119
124 virtual operator const iobject_ptr<const T>&() const = 0;
125}; // class iobject_ptr<T>
126
133template<typename T>
134class DOEXPORT iobject_ptr<const T> : public iobject_ptr_base<const T>
135{
136protected: // construction/destruction
138 ~iobject_ptr() = default;
139
140public:
141 typedef const IObject object_type;
142}; // class iobject_ptr<const T>
143
144// #################################################################################################
145// ############################### Comparison Operators ############################################
146// #################################################################################################
147
156template<typename T, typename U>
157bool operator==(const iobject_ptr<T>& i_oLHS, const U* i_pRHS)
158{
159 return i_oLHS.Get() == i_pRHS;
160}
161
170template<typename T, typename U>
171bool operator==(const T* i_pLHS, const iobject_ptr<U>& i_oRHS)
172{ // call previous defined operator
173 return operator==(i_oRHS, i_pLHS);
174}
175
184template<typename T, typename U>
185bool operator!=(const iobject_ptr<T>& i_oLHS, const U* i_pRHS)
186{
187 return !operator==(i_oLHS, i_pRHS);
188}
189
198template<typename T, typename U>
199bool operator!=(const T* i_pLHS, const iobject_ptr<U>& i_oRHS)
200{
201 return !operator==(i_pLHS, i_oRHS);
202}
203
212template<typename T, typename U>
213bool operator==(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
214{
215 return i_oLHS.Get() == i_oRHS.Get();
216}
217
226template<typename T, typename U>
227bool operator!=(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
228{
229 return !operator==(i_oLHS, i_oRHS);
230}
231
240template<typename T, typename U>
241bool operator<(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
242{
243 typedef typename std::common_type<T*, U*>::type common_pointer_type;
244 return std::less<common_pointer_type>()(i_oLHS.Get(), i_oRHS.Get());
245}
246
255template<typename T, typename U>
256bool operator>(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
257{
258 return operator<(i_oRHS, i_oLHS);
259}
260
269template<typename T, typename U>
270bool operator<=(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
271{
272 return !operator>(i_oLHS, i_oRHS);
273}
274
283template<typename T, typename U>
284bool operator>=(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
285{
286 return !operator<(i_oLHS, i_oRHS);
287}
288
295template<typename T>
296bool operator==(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
297{
298 return !i_oLHS.Get();
299}
300
307template<typename T>
308bool operator==(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
309{
310 return i_oRHS == nullptr;
311}
312
319template<typename T>
320bool operator!=(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
321{
322 return nullptr != i_oLHS.Get();
323}
324
331template<typename T>
332bool operator!=(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
333{
334 return i_oRHS != nullptr;
335}
336
343template<typename T>
344bool operator<(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
345{
346 return std::less<T*>()(i_oLHS.Get(), nullptr);
347}
348
355template<typename T>
356bool operator<(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
357{
358 return std::less<T*>()(nullptr, i_oRHS.Get());
359}
360
367template<typename T>
368bool operator<=(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
369{
370 return !operator<(nullptr, i_oLHS);
371}
372
379template<typename T>
380bool operator<=(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
381{
382 return !operator<(i_oRHS, nullptr);
383}
384
391template<typename T>
392bool operator>(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
393{
394 return operator<(nullptr, i_oLHS);
395}
396
403template<typename T>
404bool operator>(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
405{
406 return operator<(i_oRHS, nullptr);
407}
408
415template<typename T>
416bool operator>=(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
417{
418 return !operator<(i_oLHS, nullptr);
419}
420
427template<typename T>
428bool operator>=(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
429{
430 return !operator<(nullptr, i_oRHS);
431}
432
433} // namespace ant
434
436template<class T>
438
439} // namespace ucom
440} // namespace adtf
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
Definition object_intf.h:33
const IObject object_type
Provided for single point of const correct type access.
Definition object_ptr_intf.h:141
Base class for iobject_ptr<T> defining their commonly used interface methods.
Definition object_ptr_intf.h:60
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Reset this object_ptr<> with the content of another iobject_ptr<>
virtual T * operator->() const =0
Operator-> overload to treat object_ptr<> types like real pointers.
T & operator*() const noexcept
Operator* to dereference the stored pointer.
Definition object_ptr_intf.h:99
virtual T * Get() const =0
Get raw pointer to shared object.
T element_type
Contained type to manage an object of.
Definition object_ptr_intf.h:62
~iobject_ptr_base()=default
Destructor.
Base object pointer to realize binary compatible reference counting in interface methods.
Definition object_ptr_intf.h:112
~iobject_ptr()=default
Destructor.
IObject object_type
Definition object_ptr_intf.h:118
Namespace for all internally used functionality implemented.
Definition class_info.h:17
Namespace for all functionality of the ADTF UCOM SDK provided since v3.0.
Definition test_runtime.h:14
bool operator>(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Greater-than operator for forward_iterator.
Definition iterator_intf.h:122
bool operator<(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Less-than operator for forward_iterator.
Definition iterator_intf.h:108
bool operator>=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Greater-than-or-equal operator for forward_iterator.
Definition iterator_intf.h:150
bool operator<=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Less-than-or-equal operator for forward_iterator.
Definition iterator_intf.h:136
bool operator!=(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Inequality operator for forward_iterator.
Definition iterator_intf.h:178
bool operator==(const forward_iterator< T > &oLHS, const forward_iterator< T > &oRHS) noexcept
Equality operator for forward_iterator.
Definition iterator_intf.h:164
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
ant::iobject_ptr< T > iobject_ptr
Alias always bringing the latest version of ant::iobject_ptr into scope.
Definition object_ptr_intf.h:437
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14