23 #include "ocilibcpp/core.hpp" 32 HandleHolder<T>::HandleHolder() : _smartHandle(nullptr)
37 HandleHolder<T>::HandleHolder(
const HandleHolder& other) : _smartHandle(nullptr)
39 Acquire(other,
nullptr,
nullptr, 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(Acquire(other,
nullptr,
nullptr, 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>::Acquire(T handle, HandleFreeFunc handleFreefunc, SmartHandleFreeNotifyFunc freeNotifyFunc, Handle* parent)
98 if (_smartHandle && _smartHandle->GetHandle() == handle)
107 _smartHandle = Environment::GetSmartHandle<SmartHandle*>(handle);
111 _smartHandle = OnAllocate(
new SmartHandle(
this, handle, handleFreefunc, freeNotifyFunc, parent));
115 _smartHandle->Acquire(
this);
121 void HandleHolder<T>::Acquire(HandleHolder<T>& other)
123 if (&other !=
this && _smartHandle != other._smartHandle)
127 if (other._smartHandle)
129 other._smartHandle->Acquire(
this);
130 _smartHandle = other._smartHandle;
136 void HandleHolder<T>::Release()
140 _smartHandle->Release(
this);
143 _smartHandle =
nullptr;