From 8a21c2e0eb1ddcf8be99ed02ad990ef2e085ab2d Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Thu, 21 Jan 2021 16:56:14 +0100 Subject: [PATCH] Fix function StructureChain::unlink(). --- VulkanHppGenerator.cpp | 48 +++++++++--------------- tests/StructureChain/StructureChain.cpp | 12 ++++++ vulkan/vulkan.hpp | 49 +++++++++---------------- 3 files changed, 48 insertions(+), 61 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 548b680..db23fd9 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -10688,31 +10688,29 @@ int main( int argc, char ** argv ) } template - void relink() VULKAN_HPP_NOEXCEPT + typename std::enable_if< + !std::is_same>::type>::value || + ( Which != 0 ), + void>::type relink() VULKAN_HPP_NOEXCEPT { static_assert( IsPartOfStructureChain::valid, "Can't relink Structure that's not part of this StructureChain!" ); - static_assert( - !std::is_same>::type>::value || (Which != 0), - "It's not allowed to have the first element unlinked!" ); - auto pNext = reinterpret_cast( &get() ); VULKAN_HPP_ASSERT( !isLinked( pNext ) ); - auto & headElement = std::get<0>( static_cast&>( *this ) ); - pNext->pNext = reinterpret_cast(headElement.pNext); + auto & headElement = std::get<0>( static_cast &>( *this ) ); + pNext->pNext = reinterpret_cast( headElement.pNext ); headElement.pNext = pNext; } template - void unlink() VULKAN_HPP_NOEXCEPT + typename std::enable_if< + !std::is_same>::type>::value || + ( Which != 0 ), + void>::type unlink() VULKAN_HPP_NOEXCEPT { static_assert( IsPartOfStructureChain::valid, "Can't unlink Structure that's not part of this StructureChain!" ); - static_assert( - !std::is_same>::type>::value || (Which != 0), - "It's not allowed to unlink the first element!" ); - - unlink( reinterpret_cast( &get() ) ); + unlink( reinterpret_cast( &get() ) ); } private: @@ -10774,27 +10772,17 @@ int main( int argc, char ** argv ) typename std::enable_if::type link() VULKAN_HPP_NOEXCEPT {} - template - typename std::enable_if::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT + void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT { - auto & element = std::get( static_cast&>( *this ) ); - if ( element.pNext == pNext ) + VkBaseOutStructure * elementPtr = reinterpret_cast( + &std::get<0>( static_cast &>( *this ) ) ); + while ( elementPtr && ( elementPtr->pNext != pNext ) ) { - element.pNext = pNext->pNext; + elementPtr = elementPtr->pNext; } - else + if ( elementPtr ) { - unlink( pNext ); - } - } - - template - typename std::enable_if::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT - { - auto & element = std::get<0>( static_cast&>( *this ) ); - if ( element.pNext == pNext ) - { - element.pNext = pNext->pNext; + elementPtr->pNext = pNext->pNext; } else { diff --git a/tests/StructureChain/StructureChain.cpp b/tests/StructureChain/StructureChain.cpp index f541f23..fdedaca 100644 --- a/tests/StructureChain/StructureChain.cpp +++ b/tests/StructureChain/StructureChain.cpp @@ -167,6 +167,18 @@ int main( int /*argc*/, char ** /*argv*/ ) dci2.unlink(); dci2.relink(); #endif + + vk::StructureChain + chain; + chain.unlink(); + chain.unlink(); + chain.unlink(); + chain.unlink(); + chain.relink(); } catch ( vk::SystemError const & err ) { diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 73a9838..e1062b5 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -1066,15 +1066,14 @@ namespace VULKAN_HPP_NAMESPACE } template - void relink() VULKAN_HPP_NOEXCEPT + typename std::enable_if< + !std::is_same>::type>::value || + ( Which != 0 ), + void>::type + relink() VULKAN_HPP_NOEXCEPT { static_assert( IsPartOfStructureChain::valid, "Can't relink Structure that's not part of this StructureChain!" ); - static_assert( - !std::is_same>::type>::value || - ( Which != 0 ), - "It's not allowed to have the first element unlinked!" ); - auto pNext = reinterpret_cast( &get() ); VULKAN_HPP_ASSERT( !isLinked( pNext ) ); auto & headElement = std::get<0>( static_cast &>( *this ) ); @@ -1083,17 +1082,15 @@ namespace VULKAN_HPP_NAMESPACE } template - void unlink() VULKAN_HPP_NOEXCEPT + typename std::enable_if< + !std::is_same>::type>::value || + ( Which != 0 ), + void>::type + unlink() VULKAN_HPP_NOEXCEPT { static_assert( IsPartOfStructureChain::valid, "Can't unlink Structure that's not part of this StructureChain!" ); - static_assert( - !std::is_same>::type>::value || - ( Which != 0 ), - "It's not allowed to unlink the first element!" ); - - unlink( - reinterpret_cast( &get() ) ); + unlink( reinterpret_cast( &get() ) ); } private: @@ -1155,27 +1152,17 @@ namespace VULKAN_HPP_NAMESPACE typename std::enable_if::type link() VULKAN_HPP_NOEXCEPT {} - template - typename std::enable_if::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT + void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT { - auto & element = std::get( static_cast &>( *this ) ); - if ( element.pNext == pNext ) + VkBaseOutStructure * elementPtr = + reinterpret_cast( &std::get<0>( static_cast &>( *this ) ) ); + while ( elementPtr && ( elementPtr->pNext != pNext ) ) { - element.pNext = pNext->pNext; + elementPtr = elementPtr->pNext; } - else + if ( elementPtr ) { - unlink( pNext ); - } - } - - template - typename std::enable_if::type unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT - { - auto & element = std::get<0>( static_cast &>( *this ) ); - if ( element.pNext == pNext ) - { - element.pNext = pNext->pNext; + elementPtr->pNext = pNext->pNext; } else {