23 #include "ocilibcpp/core.hpp"
32 HandleHolder<T>::HandleHolder() : _smartHandle(nullptr)
37 HandleHolder<T>::HandleHolder(
const HandleHolder& other) : _smartHandle(nullptr)
39 AcquireTransient(other, other._smartHandle ? other._smartHandle->GetParent() :
nullptr);
43 HandleHolder<T>::~HandleHolder() noexcept
45 SILENT_CATCH(Release())
49 HandleHolder<T>& HandleHolder<T>::operator= (
const HandleHolder<T>& other) noexcept
53 Handle* parent = other._smartHandle ? other._smartHandle->GetParent() :
nullptr;
54 SILENT_CATCH(AcquireTransient(other, parent))
60 bool HandleHolder<T>::IsNull()
const
62 return (
static_cast<T
>(*
this) == 0);
66 HandleHolder<T>::operator T()
68 return _smartHandle ? _smartHandle->GetHandle() :
nullptr;
72 HandleHolder<T>::operator T()
const
74 return _smartHandle ? _smartHandle->GetHandle() :
nullptr;
78 HandleHolder<T>::operator bool()
84 HandleHolder<T>::operator bool()
const
90 Handle* HandleHolder<T>::GetHandle()
const
92 return static_cast<Handle*
>(_smartHandle);
96 void HandleHolder<T>::AcquireAllocated(T handle, Handle* parent)
98 Acquire(handle,
true,
nullptr, parent);
102 void HandleHolder<T>::AcquireTransient(T handle, Handle* parent)
104 Acquire(handle,
false,
nullptr, parent);
108 void HandleHolder<T>::AcquireAllocatedWithNotification(T handle, Handle* parent, SmartHandleFreeNotifyFunc freeNotifyFunc)
110 Acquire(handle,
true, freeNotifyFunc, parent);
114 void HandleHolder<T>::Acquire(T handle,
bool allocated, SmartHandleFreeNotifyFunc freeNotifyFunc, Handle* parent)
116 if (_smartHandle && _smartHandle->GetHandle() == handle)
125 _smartHandle = HandleStore::GetStoreForHandle(parent).Get<SmartHandle*>(handle);
129 _smartHandle = OnAllocate(
new SmartHandle(
this, handle, allocated, freeNotifyFunc, parent));
133 _smartHandle->Acquire(
this);
139 void HandleHolder<T>::Acquire(HandleHolder<T>& other)
141 if (&other !=
this && _smartHandle != other._smartHandle)
145 if (other._smartHandle)
147 other._smartHandle->Acquire(
this);
148 _smartHandle = other._smartHandle;
154 void HandleHolder<T>::Release()
158 _smartHandle->Release(
this);
161 _smartHandle =
nullptr;