Introduce helper class vk::StridedArrayProxy; use it on functions with parameters having the 'stride' attribute.
This commit is contained in:
@@ -12,36 +12,18 @@
|
||||
, m_ptr( nullptr )
|
||||
{}
|
||||
|
||||
ArrayProxy( T & value ) VULKAN_HPP_NOEXCEPT
|
||||
ArrayProxy( T const & value ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( 1 )
|
||||
, m_ptr( &value )
|
||||
{}
|
||||
|
||||
template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
|
||||
ArrayProxy( typename std::remove_const<T>::type & value ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( 1 )
|
||||
, m_ptr( &value )
|
||||
{}
|
||||
|
||||
ArrayProxy( uint32_t count, T * ptr ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( count )
|
||||
, m_ptr( ptr )
|
||||
{}
|
||||
|
||||
template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
|
||||
ArrayProxy( uint32_t count, typename std::remove_const<T>::type * ptr ) VULKAN_HPP_NOEXCEPT
|
||||
ArrayProxy( uint32_t count, T const * ptr ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( count )
|
||||
, m_ptr( ptr )
|
||||
{}
|
||||
|
||||
template <std::size_t C>
|
||||
ArrayProxy( T (& ptr)[C] ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( C )
|
||||
, m_ptr( ptr )
|
||||
{}
|
||||
|
||||
template <std::size_t C, typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
|
||||
ArrayProxy( typename std::remove_const<T>::type (& ptr)[C] ) VULKAN_HPP_NOEXCEPT
|
||||
ArrayProxy( T const ( &ptr )[C] ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( C )
|
||||
, m_ptr( ptr )
|
||||
{}
|
||||
@@ -60,20 +42,10 @@
|
||||
ArrayProxy( std::initializer_list<typename std::remove_const<T>::type> const & list ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( static_cast<uint32_t>( list.size() ) )
|
||||
, m_ptr( list.begin() )
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
ArrayProxy( std::initializer_list<T> & list ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( static_cast<uint32_t>( list.size() ) )
|
||||
, m_ptr( list.begin() )
|
||||
{}
|
||||
|
||||
template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
|
||||
ArrayProxy( std::initializer_list<typename std::remove_const<T>::type> & list ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( static_cast<uint32_t>( list.size() ) )
|
||||
, m_ptr( list.begin() )
|
||||
{}
|
||||
|
||||
# if __GNUC__ >= 9
|
||||
#if __GNUC__ >= 9
|
||||
# pragma GCC diagnostic pop
|
||||
# endif
|
||||
|
||||
@@ -88,15 +60,6 @@
|
||||
, m_ptr( v.data() )
|
||||
{}
|
||||
|
||||
template <typename V,
|
||||
typename std::enable_if<
|
||||
std::is_convertible<decltype( std::declval<V>().data() ), T *>::value &&
|
||||
std::is_convertible<decltype( std::declval<V>().size() ), std::size_t>::value>::type * = nullptr>
|
||||
ArrayProxy( V & v ) VULKAN_HPP_NOEXCEPT
|
||||
: m_count( static_cast<uint32_t>( v.size() ) )
|
||||
, m_ptr( v.data() )
|
||||
{}
|
||||
|
||||
const T * begin() const VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return m_ptr;
|
||||
@@ -129,12 +92,12 @@
|
||||
return m_count;
|
||||
}
|
||||
|
||||
T * data() const VULKAN_HPP_NOEXCEPT
|
||||
T const * data() const VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_count;
|
||||
T * m_ptr;
|
||||
uint32_t m_count;
|
||||
T const * m_ptr;
|
||||
};
|
||||
|
||||
40
snippets/StridedArrayProxy.hpp
Normal file
40
snippets/StridedArrayProxy.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
template <typename T>
|
||||
class StridedArrayProxy : protected ArrayProxy<T>
|
||||
{
|
||||
public:
|
||||
using ArrayProxy<T>::ArrayProxy;
|
||||
|
||||
StridedArrayProxy( uint32_t count, T const * ptr, uint32_t stride ) VULKAN_HPP_NOEXCEPT
|
||||
: ArrayProxy<T>( count, ptr )
|
||||
, m_stride( stride )
|
||||
{
|
||||
VULKAN_HPP_ASSERT( sizeof( T ) <= stride );
|
||||
}
|
||||
|
||||
using ArrayProxy<T>::begin;
|
||||
|
||||
const T * end() const VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return reinterpret_cast<T const *>( static_cast<uint8_t const *>( begin() ) + size() * m_stride );
|
||||
}
|
||||
|
||||
using ArrayProxy<T>::front;
|
||||
|
||||
const T & back() const VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
VULKAN_HPP_ASSERT( begin() && size() );
|
||||
return *reinterpret_cast<T const *>( static_cast<uint8_t const *>( begin() ) + ( size() - 1 ) * m_stride );
|
||||
}
|
||||
|
||||
using ArrayProxy<T>::empty;
|
||||
using ArrayProxy<T>::size;
|
||||
using ArrayProxy<T>::data;
|
||||
|
||||
uint32_t stride() const
|
||||
{
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_stride = sizeof( T );
|
||||
};
|
||||
Reference in New Issue
Block a user