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 // GCC before 15 reports this as hidden by the unrelated conversion operators of derived
125 // classes. Suppress it at the declaration, which is where the diagnostic is emitted.
126#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 15
127 #pragma GCC diagnostic push
128 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
129#endif
130 virtual operator const iobject_ptr<const T>&() const = 0;
131#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 15
132 #pragma GCC diagnostic pop
133#endif
134}; // class iobject_ptr<T>
135
142template<typename T>
143class DOEXPORT iobject_ptr<const T> : public iobject_ptr_base<const T>
144{
145protected: // construction/destruction
147 ~iobject_ptr() = default;
148
149public:
150 typedef const IObject object_type;
151}; // class iobject_ptr<const T>
152
153// #################################################################################################
154// ############################### Comparison Operators ############################################
155// #################################################################################################
156
165template<typename T, typename U>
166bool operator==(const iobject_ptr<T>& i_oLHS, const U* i_pRHS)
167{
168 return i_oLHS.Get() == i_pRHS;
169}
170
179template<typename T, typename U>
180bool operator==(const T* i_pLHS, const iobject_ptr<U>& i_oRHS)
181{ // call previous defined operator
182 return operator==(i_oRHS, i_pLHS);
183}
184
193template<typename T, typename U>
194bool operator!=(const iobject_ptr<T>& i_oLHS, const U* i_pRHS)
195{
196 return !operator==(i_oLHS, i_pRHS);
197}
198
207template<typename T, typename U>
208bool operator!=(const T* i_pLHS, const iobject_ptr<U>& i_oRHS)
209{
210 return !operator==(i_pLHS, i_oRHS);
211}
212
221template<typename T, typename U>
222bool operator==(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
223{
224 return i_oLHS.Get() == i_oRHS.Get();
225}
226
235template<typename T, typename U>
236bool operator!=(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
237{
238 return !operator==(i_oLHS, i_oRHS);
239}
240
249template<typename T, typename U>
250bool operator<(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
251{
252 typedef typename std::common_type<T*, U*>::type common_pointer_type;
253 return std::less<common_pointer_type>()(i_oLHS.Get(), i_oRHS.Get());
254}
255
264template<typename T, typename U>
265bool operator>(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
266{
267 return operator<(i_oRHS, i_oLHS);
268}
269
278template<typename T, typename U>
279bool operator<=(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
280{
281 return !operator>(i_oLHS, i_oRHS);
282}
283
292template<typename T, typename U>
293bool operator>=(const iobject_ptr<T>& i_oLHS, const iobject_ptr<U>& i_oRHS)
294{
295 return !operator<(i_oLHS, i_oRHS);
296}
297
304template<typename T>
305bool operator==(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
306{
307 return !i_oLHS.Get();
308}
309
316template<typename T>
317bool operator==(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
318{
319 return i_oRHS == nullptr;
320}
321
328template<typename T>
329bool operator!=(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
330{
331 return nullptr != i_oLHS.Get();
332}
333
340template<typename T>
341bool operator!=(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
342{
343 return i_oRHS != nullptr;
344}
345
352template<typename T>
353bool operator<(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
354{
355 return std::less<T*>()(i_oLHS.Get(), nullptr);
356}
357
364template<typename T>
365bool operator<(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
366{
367 return std::less<T*>()(nullptr, i_oRHS.Get());
368}
369
376template<typename T>
377bool operator<=(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
378{
379 return !operator<(nullptr, i_oLHS);
380}
381
388template<typename T>
389bool operator<=(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
390{
391 return !operator<(i_oRHS, nullptr);
392}
393
400template<typename T>
401bool operator>(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
402{
403 return operator<(nullptr, i_oLHS);
404}
405
412template<typename T>
413bool operator>(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
414{
415 return operator<(i_oRHS, nullptr);
416}
417
424template<typename T>
425bool operator>=(const iobject_ptr<T>& i_oLHS, std::nullptr_t)
426{
427 return !operator<(i_oLHS, nullptr);
428}
429
436template<typename T>
437bool operator>=(std::nullptr_t, const iobject_ptr<T>& i_oRHS)
438{
439 return !operator<(nullptr, i_oRHS);
440}
441
442} // namespace ant
443
445template<class T>
447
448} // namespace ucom
449} // namespace adtf
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:775
Definition object_intf.h:33
const IObject object_type
Provided for single point of const correct type access.
Definition object_ptr_intf.h:150
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:446
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14