23template<
typename StorageType>
24class object_ptr_storage
27 constexpr object_ptr_storage()
noexcept: m_pObject(
nullptr), m_pRefer(
nullptr)
31 constexpr object_ptr_storage(::std::nullptr_t)
noexcept: object_ptr_storage()
35 object_ptr_storage(iobject_ptr_ref<size_t>* pControlBlock,
36 StorageType* pSharedObject,
37 bool bFromWeak =
false)
noexcept:
38 m_pObject(pSharedObject), m_pRefer(pSharedObject ? pControlBlock :
nullptr)
44 if (!m_pRefer->IncreaseUseCountNonZero())
52 m_pRefer->IncreaseUseCount();
57 object_ptr_storage(
const object_ptr_storage& oOther)
noexcept:
58 object_ptr_storage(oOther.GetObjPtrRef(), oOther.GetStorageObject())
63 typename ConstCompatible = ::std::enable_if_t<::std::is_const_v<StorageType> || !::std::is_const_v<U>>>
70 typename ConstCompatible = ::std::enable_if_t<std::is_const_v<StorageType> || !::std::is_const_v<U>>>
72 object_ptr_storage(oWeak.m_pRefer, oWeak.m_pObject,
true)
77 object_ptr_storage(oOther.GetObjPtrRef(), oOther.Get())
84 object_ptr_storage(i_oOther.GetObjPtrRef(), pSharedObject)
93 constexpr detail::iobject_ptr_ref<size_t>* GetObjPtrRef() const noexcept
98 constexpr StorageType* GetStorageObject() const noexcept
103 object_ptr_storage& operator=(
const object_ptr_storage& oOther)
105 object_ptr_storage oHelper(oOther);
110 object_ptr_storage& operator=(object_ptr_storage&& oOther)
123 auto pOrphanedBlock = m_pRefer;
127 pOrphanedBlock->DecreaseUseCount();
131 void Swap(object_ptr_storage& oOther)
noexcept
134 swap(m_pObject, oOther.m_pObject);
135 swap(m_pRefer, oOther.m_pRefer);
139 StorageType* m_pObject;
140 detail::iobject_ptr_ref<size_t>* m_pRefer;
143template<
typename StorageType>
145template<
typename StorageType>
147template<
typename T,
typename StorageType>
149template<
typename T,
typename StorageType>
152template<
typename T,
typename StorageType>
153using object_ptr_base =
154 typename ::std::conditional_t<::std::is_same_v<std::remove_const_t<T>,
IObject>,
155 ::std::conditional_t<::std::is_const_v<T>,
158 ::std::conditional_t<::std::is_const_v<T>,
162template<
typename T,
typename StorageType>
165 static_assert(!::std::is_volatile_v<T> && !::std::is_reference_v<T>);
166 static_assert(!::std::is_volatile_v<StorageType> && !::std::is_reference_v<StorageType>);
167 static_assert(::std::is_const_v<T> || !::std::is_const_v<StorageType>,
168 "Can't enable non-const interface for a const storage type");
171 template<
typename... Args>
172 object_ptr_delegate_base(Args&&... args)
noexcept: m_oDelegate(::std::forward<Args>(args)...)
176 object_ptr_delegate_base(
const object_ptr_delegate_base& oOther)
noexcept:
177 object_ptr_delegate_base(oOther, oOther.GetStorageObject())
181 object_ptr_delegate_base(object_ptr_delegate_base&& oOther)
noexcept: object_ptr_delegate_base()
186 ~object_ptr_delegate_base() =
default;
188 constexpr detail::iobject_ptr_ref<size_t>* GetObjPtrRef()
const noexcept final override
190 return m_oDelegate.GetObjPtrRef();
193 constexpr StorageType* GetStorageObject()
const noexcept
195 return m_oDelegate.GetStorageObject();
198 T*
Get() const final
override
200 if constexpr (::std::is_same_v<T, StorageType>)
202 return GetStorageObject();
215 T& operator*() const noexcept
220 void Swap(object_ptr_delegate_base& oOther)
noexcept
222 m_oDelegate.Swap(oOther.m_oDelegate);
238 else if constexpr (::std::is_same_v<T, StorageType>)
240 object_ptr_base<T, StorageType> oHelper(oOther);
246#pragma warning(disable : 6326)
248 else if constexpr (::std::is_same_v<std::remove_const_t<T>,
IObject> &&
249 ::std::is_const_v<StorageType> == ::std::is_const_v<T> &&
250 has_interface_info_type<::std::remove_const_t<StorageType>>::value)
262 object_ptr_base<T, StorageType> oHelper(oOther, pObject);
274 m_oDelegate = oOther.m_oDelegate;
278 object_ptr_delegate_base& operator=(object_ptr_delegate_base&& oOther)
280 m_oDelegate = ::std::move(oOther.m_oDelegate);
284 constexpr explicit operator bool() const noexcept
286 return (GetStorageObject() !=
nullptr);
290 ::std::conditional_t<::std::is_same_v<std::remove_const_t<T>,
IObject>,
291 std::conditional_t<!::std::is_const_v<T> && !::std::is_const_v<StorageType>,
292 object_ptr_const_iobject_delegate<StorageType>,
293 object_ptr_storage<StorageType>>,
294 std::conditional_t<::std::is_const_v<T> || ::std::is_const_v<StorageType>,
295 ::std::conditional_t<::std::is_const_v<StorageType>,
296 object_ptr_const_iobject_delegate<StorageType>,
297 object_ptr_iobject_delegate<StorageType>>,
298 object_ptr_const_delegate<const T, StorageType>>>
302template<
typename StorageType>
306 using object_ptr_delegate_base<
const IObject, StorageType>::object_ptr_delegate_base;
309template<
typename StorageType>
312 using base = object_ptr_delegate_base<IObject, StorageType>;
318 return base::m_oDelegate;
322template<
typename T,
typename StorageType>
325 static_assert(::std::is_const_v<T> && !::std::is_same_v<T, const IObject>);
327 using base = object_ptr_delegate_base<T, StorageType>;
333 return base::m_oDelegate;
336 template<
typename U,
typename = ::std::enable_if_t<::std::is_same_v<U, IObject> && !::std::is_const_v<StorageType>>>
339 return base::m_oDelegate;
343 typename = std::enable_if_t<(::std::is_same_v<U, const IObject> && ::std::is_const_v<StorageType>) ||
344 (::std::is_same_v<U, IObject> && !::std::is_const_v<StorageType>)>>
347 return base::m_oDelegate;
351template<
typename T,
typename StorageType>
354 static_assert(!::std::is_const_v<T> && !::std::is_same_v<T, IObject>);
355 using base = object_ptr_delegate_base<T, StorageType>;
361 return base::m_oDelegate;
366 return base::m_oDelegate;
371 return base::m_oDelegate;
376 return base::m_oDelegate;
385 using base = detail::object_ptr_base<T, T>;
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
Definition result.h:44
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define RETURN_IF_THROWS(s)
if the expression throws an exception, returns a tResult containing the exception information.
Definition result.h:123
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Definition result.h:42
Definition object_intf.h:33
Definition object_ptr.h:324
Definition object_ptr.h:304
Definition object_ptr.h:164
tResult Reset(const iobject_ptr< T > &oOther) noexcept final override
Reset this object_ptr<> with the content of another iobject_ptr<>
Definition object_ptr.h:230
T * operator->() const noexcept final override
Operator-> overload to treat object_ptr<> types like real pointers.
Definition object_ptr.h:210
T * Get() const final override
Get raw pointer to shared object.
Definition object_ptr.h:198
Definition object_ptr.h:353
Definition object_ptr.h:311
Definition object_ptr.h:25
object_ptr_storage(const iobject_ptr< U > &i_oOther, StorageType *pSharedObject) noexcept
Aliasing constructor.
Definition object_ptr.h:83
Base object pointer to realize binary compatible reference counting in interface methods.
Definition object_ptr_intf.h:112
Definition object_ptr.h:384
Implementation of a weak pointer for usage with iobject_ptr and object_ptr.
Definition weak_object_ptr.h:34
void swap(cResult &i_oLHS, cResult &i_oRHS) noexcept
Definition result.h:505
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
InterfacePointerType ucom_cast(ObjectPointerType i_pObject) noexcept
Definition ucom_cast.h:157
constexpr const char * get_iid() noexcept
Definition adtf_iid.h:429
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
ant::IObject IObject
Alias always bringing the latest version of ant::IObject into scope.
Definition object_intf.h:109
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