Fix function StructureChain::unlink().

This commit is contained in:
asuessenbach 2021-01-21 16:56:14 +01:00
parent a82ea0f9b0
commit 8a21c2e0eb
3 changed files with 48 additions and 61 deletions

View File

@ -10688,31 +10688,29 @@ int main( int argc, char ** argv )
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
void relink() VULKAN_HPP_NOEXCEPT typename std::enable_if<
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value ||
( 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!" );
static_assert(
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || (Which != 0),
"It's not allowed to have the first element unlinked!" );
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 ) );
pNext->pNext = reinterpret_cast<VkBaseInStructure const*>(headElement.pNext); pNext->pNext = reinterpret_cast<VkBaseInStructure const *>( headElement.pNext );
headElement.pNext = pNext; headElement.pNext = pNext;
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
void unlink() VULKAN_HPP_NOEXCEPT typename std::enable_if<
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value ||
( 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!" );
static_assert( unlink( reinterpret_cast<VkBaseOutStructure const *>( &get<ClassType, Which>() ) );
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || (Which != 0),
"It's not allowed to unlink the first element!" );
unlink<sizeof...( ChainElements ) - 1>( reinterpret_cast<VkBaseOutStructure const *>( &get<ClassType, Which>() ) );
} }
private: private:
@ -10774,27 +10772,17 @@ int main( int argc, char ** argv )
typename std::enable_if<Index == 0, void>::type link() VULKAN_HPP_NOEXCEPT typename std::enable_if<Index == 0, void>::type link() VULKAN_HPP_NOEXCEPT
{} {}
template <size_t Index> void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
typename std::enable_if<Index != 0, void>::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
{ {
auto & element = std::get<Index>( static_cast<std::tuple<ChainElements...>&>( *this ) ); VkBaseOutStructure * elementPtr = reinterpret_cast<VkBaseOutStructure *>(
if ( element.pNext == pNext ) &std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) ) );
while ( elementPtr && ( elementPtr->pNext != pNext ) )
{ {
element.pNext = pNext->pNext; elementPtr = elementPtr->pNext;
} }
else if ( elementPtr )
{ {
unlink<Index - 1>( pNext ); elementPtr->pNext = pNext->pNext;
}
}
template <size_t Index>
typename std::enable_if<Index == 0, void>::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
{
auto & element = std::get<0>( static_cast<std::tuple<ChainElements...>&>( *this ) );
if ( element.pNext == pNext )
{
element.pNext = pNext->pNext;
} }
else else
{ {

View File

@ -167,6 +167,18 @@ int main( int /*argc*/, char ** /*argv*/ )
dci2.unlink<vk::DevicePrivateDataCreateInfoEXT, 1>(); dci2.unlink<vk::DevicePrivateDataCreateInfoEXT, 1>();
dci2.relink<vk::DevicePrivateDataCreateInfoEXT, 1>(); dci2.relink<vk::DevicePrivateDataCreateInfoEXT, 1>();
#endif #endif
vk::StructureChain<vk::InstanceCreateInfo,
vk::DebugReportCallbackCreateInfoEXT,
vk::ValidationFlagsEXT,
vk::ValidationFeaturesEXT,
vk::DebugUtilsMessengerCreateInfoEXT>
chain;
chain.unlink<vk::DebugReportCallbackCreateInfoEXT>();
chain.unlink<vk::ValidationFlagsEXT>();
chain.unlink<vk::ValidationFeaturesEXT>();
chain.unlink<vk::DebugUtilsMessengerCreateInfoEXT>();
chain.relink<vk::DebugUtilsMessengerCreateInfoEXT>();
} }
catch ( vk::SystemError const & err ) catch ( vk::SystemError const & err )
{ {

View File

@ -1066,15 +1066,14 @@ namespace VULKAN_HPP_NAMESPACE
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
void relink() VULKAN_HPP_NOEXCEPT typename std::enable_if<
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value ||
( 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!" );
static_assert(
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value ||
( Which != 0 ),
"It's not allowed to have the first element unlinked!" );
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 ) );
@ -1083,17 +1082,15 @@ namespace VULKAN_HPP_NAMESPACE
} }
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
void unlink() VULKAN_HPP_NOEXCEPT typename std::enable_if<
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value ||
( 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!" );
static_assert( unlink( reinterpret_cast<VkBaseOutStructure const *>( &get<ClassType, Which>() ) );
!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value ||
( Which != 0 ),
"It's not allowed to unlink the first element!" );
unlink<sizeof...( ChainElements ) - 1>(
reinterpret_cast<VkBaseOutStructure const *>( &get<ClassType, Which>() ) );
} }
private: private:
@ -1155,27 +1152,17 @@ namespace VULKAN_HPP_NAMESPACE
typename std::enable_if<Index == 0, void>::type link() VULKAN_HPP_NOEXCEPT typename std::enable_if<Index == 0, void>::type link() VULKAN_HPP_NOEXCEPT
{} {}
template <size_t Index> void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
typename std::enable_if<Index != 0, void>::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
{ {
auto & element = std::get<Index>( static_cast<std::tuple<ChainElements...> &>( *this ) ); VkBaseOutStructure * elementPtr =
if ( element.pNext == pNext ) reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) ) );
while ( elementPtr && ( elementPtr->pNext != pNext ) )
{ {
element.pNext = pNext->pNext; elementPtr = elementPtr->pNext;
} }
else if ( elementPtr )
{ {
unlink<Index - 1>( pNext ); elementPtr->pNext = pNext->pNext;
}
}
template <size_t Index>
typename std::enable_if<Index == 0, void>::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
{
auto & element = std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) );
if ( element.pNext == pNext )
{
element.pNext = pNext->pNext;
} }
else else
{ {