Fix some formatting. (#1599)

This commit is contained in:
Andreas Süßenbach 2023-06-21 13:33:29 +02:00 committed by GitHub
parent e8eac44fe1
commit 98d2b53258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 79 deletions

View File

@ -22,26 +22,23 @@
template <size_t Index, typename T, typename... ChainElements> template <size_t Index, typename T, typename... ChainElements>
struct StructureChainContains struct StructureChainContains
{ {
static const bool value = static const bool value = std::is_same<T, typename std::tuple_element<Index, std::tuple<ChainElements...>>::type>::value ||
std::is_same<T, typename std::tuple_element<Index, std::tuple<ChainElements...>>::type>::value || StructureChainContains<Index - 1, T, ChainElements...>::value;
StructureChainContains<Index - 1, T, ChainElements...>::value;
}; };
template <typename T, typename... ChainElements> template <typename T, typename... ChainElements>
struct StructureChainContains<0, T, ChainElements...> struct StructureChainContains<0, T, ChainElements...>
{ {
static const bool value = static const bool value = std::is_same<T, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value;
std::is_same<T, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value;
}; };
template <size_t Index, typename... ChainElements> template <size_t Index, typename... ChainElements>
struct StructureChainValidation struct StructureChainValidation
{ {
using TestType = typename std::tuple_element<Index, std::tuple<ChainElements...>>::type; using TestType = typename std::tuple_element<Index, std::tuple<ChainElements...>>::type;
static const bool valid = static const bool valid = StructExtends<TestType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value &&
StructExtends<TestType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value && ( TestType::allowDuplicate || !StructureChainContains<Index - 1, TestType, ChainElements...>::value ) &&
( TestType::allowDuplicate || !StructureChainContains<Index - 1, TestType, ChainElements...>::value ) && StructureChainValidation<Index - 1, ChainElements...>::valid;
StructureChainValidation<Index - 1, ChainElements...>::valid;
}; };
template <typename... ChainElements> template <typename... ChainElements>
@ -56,26 +53,22 @@
public: public:
StructureChain() VULKAN_HPP_NOEXCEPT StructureChain() VULKAN_HPP_NOEXCEPT
{ {
static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, "The structure chain is not valid!" );
"The structure chain is not valid!" );
link<sizeof...( ChainElements ) - 1>(); link<sizeof...( ChainElements ) - 1>();
} }
StructureChain( StructureChain const & rhs ) VULKAN_HPP_NOEXCEPT : std::tuple<ChainElements...>( rhs ) StructureChain( StructureChain const & rhs ) VULKAN_HPP_NOEXCEPT : std::tuple<ChainElements...>( rhs )
{ {
static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, "The structure chain is not valid!" );
"The structure chain is not valid!" );
link( &std::get<0>( *this ), link( &std::get<0>( *this ),
&std::get<0>( rhs ), &std::get<0>( rhs ),
reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( *this ) ), reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( *this ) ),
reinterpret_cast<VkBaseInStructure const *>( &std::get<0>( rhs ) ) ); reinterpret_cast<VkBaseInStructure const *>( &std::get<0>( rhs ) ) );
} }
StructureChain( StructureChain && rhs ) VULKAN_HPP_NOEXCEPT StructureChain( StructureChain && rhs ) VULKAN_HPP_NOEXCEPT : std::tuple<ChainElements...>( std::forward<std::tuple<ChainElements...>>( rhs ) )
: std::tuple<ChainElements...>( std::forward<std::tuple<ChainElements...>>( rhs ) )
{ {
static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, "The structure chain is not valid!" );
"The structure chain is not valid!" );
link( &std::get<0>( *this ), link( &std::get<0>( *this ),
&std::get<0>( rhs ), &std::get<0>( rhs ),
reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( *this ) ), reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( *this ) ),
@ -84,8 +77,7 @@
StructureChain( ChainElements const &... elems ) VULKAN_HPP_NOEXCEPT : std::tuple<ChainElements...>( elems... ) StructureChain( ChainElements const &... elems ) VULKAN_HPP_NOEXCEPT : std::tuple<ChainElements...>( elems... )
{ {
static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, "The structure chain is not valid!" );
"The structure chain is not valid!" );
link<sizeof...( ChainElements ) - 1>(); link<sizeof...( ChainElements ) - 1>();
} }
@ -104,15 +96,13 @@
template <typename T = typename std::tuple_element<0, std::tuple<ChainElements...>>::type, size_t Which = 0> template <typename T = typename std::tuple_element<0, std::tuple<ChainElements...>>::type, size_t Which = 0>
T & get() VULKAN_HPP_NOEXCEPT T & get() VULKAN_HPP_NOEXCEPT
{ {
return std::get<ChainElementIndex<0, T, Which, void, ChainElements...>::value>( return std::get<ChainElementIndex<0, T, Which, void, ChainElements...>::value>( static_cast<std::tuple<ChainElements...> &>( *this ) );
static_cast<std::tuple<ChainElements...> &>( *this ) );
} }
template <typename T = typename std::tuple_element<0, std::tuple<ChainElements...>>::type, size_t Which = 0> template <typename T = typename std::tuple_element<0, std::tuple<ChainElements...>>::type, size_t Which = 0>
T const & get() const VULKAN_HPP_NOEXCEPT T const & get() const VULKAN_HPP_NOEXCEPT
{ {
return std::get<ChainElementIndex<0, T, Which, void, ChainElements...>::value>( return std::get<ChainElementIndex<0, T, Which, void, ChainElements...>::value>( static_cast<std::tuple<ChainElements...> const &>( *this ) );
static_cast<std::tuple<ChainElements...> const &>( *this ) );
} }
template <typename T0, typename T1, typename... Ts> template <typename T0, typename T1, typename... Ts>
@ -135,39 +125,29 @@
void * pNext = lhs.pNext; void * pNext = lhs.pNext;
lhs = rhs; lhs = rhs;
lhs.pNext = pNext; lhs.pNext = pNext;
return *this; return *this;
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
typename std::enable_if< typename std::enable_if<std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value && ( Which == 0 ), bool>::type
std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value &&
( Which == 0 ),
bool>::type
isLinked() const VULKAN_HPP_NOEXCEPT isLinked() const VULKAN_HPP_NOEXCEPT
{ {
return true; return true;
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
typename std::enable_if< typename std::enable_if<!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || ( Which != 0 ), bool>::type
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value ||
( Which != 0 ),
bool>::type
isLinked() const VULKAN_HPP_NOEXCEPT isLinked() const VULKAN_HPP_NOEXCEPT
{ {
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, "Can't unlink Structure that's not part of this StructureChain!" );
"Can't unlink Structure that's not part of this StructureChain!" );
return isLinked( reinterpret_cast<VkBaseInStructure const *>( &get<ClassType, Which>() ) ); return isLinked( reinterpret_cast<VkBaseInStructure const *>( &get<ClassType, Which>() ) );
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
typename std::enable_if< typename std::enable_if<!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || ( Which != 0 ), void>::type
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || relink() VULKAN_HPP_NOEXCEPT
( Which != 0 ),
void>::type relink() VULKAN_HPP_NOEXCEPT
{ {
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, "Can't relink Structure that's not part of this StructureChain!" );
"Can't relink Structure that's not part of this StructureChain!" );
auto pNext = reinterpret_cast<VkBaseInStructure *>( &get<ClassType, Which>() ); auto pNext = reinterpret_cast<VkBaseInStructure *>( &get<ClassType, Which>() );
VULKAN_HPP_ASSERT( !isLinked( pNext ) ); VULKAN_HPP_ASSERT( !isLinked( pNext ) );
auto & headElement = std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) ); auto & headElement = std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) );
@ -176,52 +156,41 @@
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
typename std::enable_if< typename std::enable_if<!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || ( Which != 0 ), void>::type
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || unlink() VULKAN_HPP_NOEXCEPT
( Which != 0 ),
void>::type unlink() VULKAN_HPP_NOEXCEPT
{ {
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, "Can't unlink Structure that's not part of this StructureChain!" );
"Can't unlink Structure that's not part of this StructureChain!" );
unlink( reinterpret_cast<VkBaseOutStructure const *>( &get<ClassType, Which>() ) ); unlink( reinterpret_cast<VkBaseOutStructure const *>( &get<ClassType, Which>() ) );
} }
private: private:
template <int Index, typename T, int Which, typename, class First, class... Types> template <int Index, typename T, int Which, typename, class First, class... Types>
struct ChainElementIndex : ChainElementIndex<Index + 1, T, Which, void, Types...> struct ChainElementIndex : ChainElementIndex<Index + 1, T, Which, void, Types...>
{}; {
};
template <int Index, typename T, int Which, class First, class... Types> template <int Index, typename T, int Which, class First, class... Types>
struct ChainElementIndex<Index, struct ChainElementIndex<Index, T, Which, typename std::enable_if<!std::is_same<T, First>::value, void>::type, First, Types...>
T, : ChainElementIndex<Index + 1, T, Which, void, Types...>
Which, {
typename std::enable_if<!std::is_same<T, First>::value, void>::type, };
First,
Types...> : ChainElementIndex<Index + 1, T, Which, void, Types...>
{};
template <int Index, typename T, int Which, class First, class... Types> template <int Index, typename T, int Which, class First, class... Types>
struct ChainElementIndex<Index, struct ChainElementIndex<Index, T, Which, typename std::enable_if<std::is_same<T, First>::value, void>::type, First, Types...>
T, : ChainElementIndex<Index + 1, T, Which - 1, void, Types...>
Which, {
typename std::enable_if<std::is_same<T, First>::value, void>::type, };
First,
Types...> : ChainElementIndex<Index + 1, T, Which - 1, void, Types...>
{};
template <int Index, typename T, class First, class... Types> template <int Index, typename T, class First, class... Types>
struct ChainElementIndex<Index, struct ChainElementIndex<Index, T, 0, typename std::enable_if<std::is_same<T, First>::value, void>::type, First, Types...>
T, : std::integral_constant<int, Index>
0, {
typename std::enable_if<std::is_same<T, First>::value, void>::type, };
First,
Types...> : std::integral_constant<int, Index>
{};
bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT
{ {
VkBaseInStructure const * elementPtr = reinterpret_cast<VkBaseInStructure const *>( VkBaseInStructure const * elementPtr =
&std::get<0>( static_cast<std::tuple<ChainElements...> const &>( *this ) ) ); reinterpret_cast<VkBaseInStructure const *>( &std::get<0>( static_cast<std::tuple<ChainElements...> const &>( *this ) ) );
while ( elementPtr ) while ( elementPtr )
{ {
if ( elementPtr->pNext == pNext ) if ( elementPtr->pNext == pNext )
@ -243,25 +212,24 @@
template <size_t Index> template <size_t Index>
typename std::enable_if<Index == 0, void>::type link() VULKAN_HPP_NOEXCEPT typename std::enable_if<Index == 0, void>::type link() VULKAN_HPP_NOEXCEPT
{} {
}
void link( void * dstBase, void const * srcBase, VkBaseOutStructure * dst, VkBaseInStructure const * src ) void link( void * dstBase, void const * srcBase, VkBaseOutStructure * dst, VkBaseInStructure const * src )
{ {
while ( src->pNext ) while ( src->pNext )
{ {
std::ptrdiff_t offset = std::ptrdiff_t offset = reinterpret_cast<char const *>( src->pNext ) - reinterpret_cast<char const *>( srcBase );
reinterpret_cast<char const *>( src->pNext ) - reinterpret_cast<char const *>( srcBase ); dst->pNext = reinterpret_cast<VkBaseOutStructure *>( reinterpret_cast<char *>( dstBase ) + offset );
dst->pNext = reinterpret_cast<VkBaseOutStructure *>( reinterpret_cast<char *>( dstBase ) + offset ); dst = dst->pNext;
dst = dst->pNext; src = src->pNext;
src = src->pNext;
} }
dst->pNext = nullptr; dst->pNext = nullptr;
} }
void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
{ {
VkBaseOutStructure * elementPtr = VkBaseOutStructure * elementPtr = reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) ) );
reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) ) );
while ( elementPtr && ( elementPtr->pNext != pNext ) ) while ( elementPtr && ( elementPtr->pNext != pNext ) )
{ {
elementPtr = elementPtr->pNext; elementPtr = elementPtr->pNext;

View File

@ -1053,6 +1053,17 @@ namespace VULKAN_HPP_NAMESPACE
return std::tie( get<T0>(), get<T1>(), get<Ts>()... ); return std::tie( get<T0>(), get<T1>(), get<Ts>()... );
} }
// assign a complete structure to the StructureChain without modifying the chaining
template <typename T = typename std::tuple_element<0, std::tuple<ChainElements...>>::type, size_t Which = 0>
StructureChain & assign( const T & rhs ) VULKAN_HPP_NOEXCEPT
{
T & lhs = get<T, Which>();
void * pNext = lhs.pNext;
lhs = rhs;
lhs.pNext = pNext;
return *this;
}
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
typename std::enable_if<std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value && ( Which == 0 ), bool>::type typename std::enable_if<std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value && ( Which == 0 ), bool>::type
isLinked() const VULKAN_HPP_NOEXCEPT isLinked() const VULKAN_HPP_NOEXCEPT