2022-07-28 15:09:08 +00:00
|
|
|
#if !defined( VULKAN_HPP_NO_SMART_HANDLE )
|
2024-01-16 12:48:53 +00:00
|
|
|
template <typename Type, typename Dispatch>
|
|
|
|
class UniqueHandleTraits;
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
template <typename Type, typename Dispatch>
|
|
|
|
class UniqueHandle : public UniqueHandleTraits<Type, Dispatch>::deleter
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
using Deleter = typename UniqueHandleTraits<Type, Dispatch>::deleter;
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
public:
|
|
|
|
using element_type = Type;
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
UniqueHandle() : Deleter(), m_value() {}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
explicit UniqueHandle( Type const & value, Deleter const & deleter = Deleter() ) VULKAN_HPP_NOEXCEPT
|
|
|
|
: Deleter( deleter )
|
|
|
|
, m_value( value )
|
|
|
|
{
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
UniqueHandle( UniqueHandle const & ) = delete;
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
UniqueHandle( UniqueHandle && other ) VULKAN_HPP_NOEXCEPT
|
|
|
|
: Deleter( std::move( static_cast<Deleter &>( other ) ) )
|
|
|
|
, m_value( other.release() )
|
|
|
|
{
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
~UniqueHandle() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
if ( m_value )
|
2022-07-28 15:09:08 +00:00
|
|
|
{
|
2024-01-16 12:48:53 +00:00
|
|
|
this->destroy( m_value );
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
2024-01-16 12:48:53 +00:00
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
UniqueHandle & operator=( UniqueHandle const & ) = delete;
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
UniqueHandle & operator=( UniqueHandle && other ) VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
reset( other.release() );
|
|
|
|
*static_cast<Deleter *>( this ) = std::move( static_cast<Deleter &>( other ) );
|
|
|
|
return *this;
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
explicit operator bool() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return m_value.operator bool();
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
# if defined( VULKAN_HPP_SMART_HANDLE_IMPLICIT_CAST )
|
|
|
|
operator Type() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
# endif
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
Type const * operator->() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return &m_value;
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
Type * operator->() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return &m_value;
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
Type const & operator*() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
Type & operator*() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
const Type & get() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
Type & get() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset( Type const & value = Type() ) VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
if ( m_value != value )
|
2022-07-28 15:09:08 +00:00
|
|
|
{
|
2024-01-16 12:48:53 +00:00
|
|
|
if ( m_value )
|
2022-07-28 15:09:08 +00:00
|
|
|
{
|
2024-01-16 12:48:53 +00:00
|
|
|
this->destroy( m_value );
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
2024-01-16 12:48:53 +00:00
|
|
|
m_value = value;
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
2024-01-16 12:48:53 +00:00
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
Type release() VULKAN_HPP_NOEXCEPT
|
2022-07-28 15:09:08 +00:00
|
|
|
{
|
2024-01-16 12:48:53 +00:00
|
|
|
Type value = m_value;
|
|
|
|
m_value = nullptr;
|
|
|
|
return value;
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-16 12:48:53 +00:00
|
|
|
void swap( UniqueHandle<Type, Dispatch> & rhs ) VULKAN_HPP_NOEXCEPT
|
2022-07-28 15:09:08 +00:00
|
|
|
{
|
2024-01-16 12:48:53 +00:00
|
|
|
std::swap( m_value, rhs.m_value );
|
|
|
|
std::swap( static_cast<Deleter &>( *this ), static_cast<Deleter &>( rhs ) );
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
2024-01-16 12:48:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Type m_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename UniqueType>
|
|
|
|
VULKAN_HPP_INLINE std::vector<typename UniqueType::element_type> uniqueToRaw( std::vector<UniqueType> const & handles )
|
|
|
|
{
|
|
|
|
std::vector<typename UniqueType::element_type> newBuffer( handles.size() );
|
|
|
|
std::transform( handles.begin(), handles.end(), newBuffer.begin(), []( UniqueType const & handle ) { return handle.get(); } );
|
|
|
|
return newBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Type, typename Dispatch>
|
|
|
|
VULKAN_HPP_INLINE void swap( UniqueHandle<Type, Dispatch> & lhs, UniqueHandle<Type, Dispatch> & rhs ) VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
lhs.swap( rhs );
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
#endif
|