Move get_ptr to stdex
This was migrated to stdex being platform independent. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
8cca09a567
commit
5b023215f5
@ -855,160 +855,6 @@ namespace winstd
|
|||||||
T* m_data; ///< memory pointer
|
T* m_data; ///< memory pointer
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
|
||||||
/// Helper class for returning pointers to std::unique_ptr
|
|
||||||
///
|
|
||||||
template<class _Ty, class _Dx>
|
|
||||||
class ref_unique_ptr
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Takes ownership of the pointer
|
|
||||||
///
|
|
||||||
/// \param[inout] owner Object to attach helper to
|
|
||||||
///
|
|
||||||
ref_unique_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner) :
|
|
||||||
m_own(owner),
|
|
||||||
m_ptr(owner.release())
|
|
||||||
{}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Moves object
|
|
||||||
///
|
|
||||||
/// \param[inout] other Source object
|
|
||||||
///
|
|
||||||
ref_unique_ptr(_Inout_ ref_unique_ptr<_Ty, _Dx> &&other) :
|
|
||||||
m_own(other.m_own),
|
|
||||||
m_ptr(other.m_ptr)
|
|
||||||
{
|
|
||||||
other.m_ptr = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Returns ownership of the pointer
|
|
||||||
///
|
|
||||||
~ref_unique_ptr()
|
|
||||||
{
|
|
||||||
if (m_ptr != nullptr)
|
|
||||||
m_own.reset(m_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Operator for pointer-to-pointer parameters by value use-cases.
|
|
||||||
///
|
|
||||||
/// \return Pointer to the pointer
|
|
||||||
///
|
|
||||||
operator typename _Ty**()
|
|
||||||
{
|
|
||||||
return &m_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Operator for reverence-to-pointer parameters by value use-cases.
|
|
||||||
///
|
|
||||||
/// \return Reference to the pointer
|
|
||||||
///
|
|
||||||
operator typename _Ty*&()
|
|
||||||
{
|
|
||||||
return m_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<_Ty, _Dx> &m_own; ///< Original owner of the pointer
|
|
||||||
_Ty *m_ptr; ///< Pointer
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Helper function template for returning pointers to std::unique_ptr
|
|
||||||
///
|
|
||||||
/// \param[inout] owner Original owner of the pointer
|
|
||||||
///
|
|
||||||
/// \returns A helper wrapper class to handle returning a reference to the pointer
|
|
||||||
///
|
|
||||||
template<class _Ty, class _Dx>
|
|
||||||
ref_unique_ptr<_Ty, _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner) noexcept
|
|
||||||
{
|
|
||||||
return ref_unique_ptr<_Ty, _Dx>(owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Helper class for returning pointers to std::unique_ptr
|
|
||||||
/// (specialization for arrays)
|
|
||||||
///
|
|
||||||
template<class _Ty, class _Dx>
|
|
||||||
class ref_unique_ptr<_Ty[], _Dx>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
/// Takes ownership of the pointer
|
|
||||||
///
|
|
||||||
/// \param[inout] owner Object to attach helper to
|
|
||||||
///
|
|
||||||
ref_unique_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) noexcept :
|
|
||||||
m_own(owner),
|
|
||||||
m_ptr(owner.release())
|
|
||||||
{}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Moves object
|
|
||||||
///
|
|
||||||
/// \param[inout] other Source object
|
|
||||||
///
|
|
||||||
ref_unique_ptr(_Inout_ ref_unique_ptr<_Ty[], _Dx> &&other) :
|
|
||||||
m_own(other.m_own),
|
|
||||||
m_ptr(other.m_ptr)
|
|
||||||
{
|
|
||||||
other.m_ptr = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Returns ownership of the pointer
|
|
||||||
///
|
|
||||||
virtual ~ref_unique_ptr()
|
|
||||||
{
|
|
||||||
if (m_ptr != nullptr)
|
|
||||||
m_own.reset(m_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Operator for pointer-to-pointer parameters by value use-cases.
|
|
||||||
///
|
|
||||||
/// \return Pointer to the pointer
|
|
||||||
///
|
|
||||||
operator typename _Ty**() noexcept
|
|
||||||
{
|
|
||||||
return &m_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Operator for reverence-to-pointer parameters by value use-cases.
|
|
||||||
///
|
|
||||||
/// \return Reference to the pointer
|
|
||||||
///
|
|
||||||
operator typename _Ty*&()
|
|
||||||
{
|
|
||||||
return m_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<_Ty[], _Dx> &m_own; ///< Original owner of the pointer
|
|
||||||
_Ty *m_ptr; ///< Pointer
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Helper function template for returning pointers to std::unique_ptr
|
|
||||||
/// (specialization for arrays)
|
|
||||||
///
|
|
||||||
/// \param[inout] owner Original owner of the pointer
|
|
||||||
///
|
|
||||||
/// \returns A helper wrapper class to handle returning a reference to the pointer
|
|
||||||
///
|
|
||||||
template<class _Ty, class _Dx>
|
|
||||||
ref_unique_ptr<_Ty[], _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx>& owner) noexcept
|
|
||||||
{
|
|
||||||
return ref_unique_ptr<_Ty[], _Dx>(owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// \addtogroup WinStdSysHandles
|
/// \addtogroup WinStdSysHandles
|
||||||
|
Loading…
x
Reference in New Issue
Block a user