Introduce helper class vk::StridedArrayProxy; use it on functions with parameters having the 'stride' attribute.
This commit is contained in:
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