From 2e2782448c13eccd0a3c71971df7f3cf9f10b998 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Wed, 20 Jan 2021 10:33:33 +0100 Subject: [PATCH] Introduce new function StructureChain::isLinked<>() --- VulkanHppGenerator.cpp | 27 +++++++++++++++++++++++-- tests/StructureChain/StructureChain.cpp | 6 ++++++ vulkan/vulkan.hpp | 26 ++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 96ac776..548b680 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -10665,6 +10665,28 @@ int main( int argc, char ** argv ) return std::tie( get(), get(), get()... ); } + template + typename std::enable_if< + std::is_same>::type>::value && + ( Which == 0 ), + bool>::type + isLinked() const VULKAN_HPP_NOEXCEPT + { + return true; + } + + template + typename std::enable_if< + !std::is_same>::type>::value || + ( Which != 0 ), + bool>::type + isLinked() const VULKAN_HPP_NOEXCEPT + { + static_assert( IsPartOfStructureChain::valid, + "Can't unlink Structure that's not part of this StructureChain!" ); + return isLinked( reinterpret_cast( &get() ) ); + } + template void relink() VULKAN_HPP_NOEXCEPT { @@ -10725,9 +10747,10 @@ int main( int argc, char ** argv ) Types...> : std::integral_constant {}; - bool isLinked( VkBaseInStructure const * pNext ) + bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT { - VkBaseInStructure const * elementPtr = reinterpret_cast(&std::get<0>( static_cast&>( *this ) ) ); + VkBaseInStructure const * elementPtr = reinterpret_cast( + &std::get<0>( static_cast const &>( *this ) ) ); while ( elementPtr ) { if ( elementPtr->pNext == pNext ) diff --git a/tests/StructureChain/StructureChain.cpp b/tests/StructureChain/StructureChain.cpp index e417122..f541f23 100644 --- a/tests/StructureChain/StructureChain.cpp +++ b/tests/StructureChain/StructureChain.cpp @@ -74,6 +74,10 @@ int main( int /*argc*/, char ** /*argv*/ ) vk::PhysicalDevicePushDescriptorPropertiesKHR> sc7; + // some checks on unmodified chains + assert( sc7.isLinked() ); + assert( sc7.isLinked() ); + // some invalid StructureChains // clang-format off //vk::StructureChain x; @@ -91,6 +95,7 @@ int main( int /*argc*/, char ** /*argv*/ ) // unlink a struct from a StructureChain sc7.unlink(); + assert( !sc7.isLinked() ); // some invalid unlink calls // clang-format off @@ -102,6 +107,7 @@ int main( int /*argc*/, char ** /*argv*/ ) // re-link a struct sc7.relink(); + assert( sc7.isLinked() ); // invalid re-linking // clang-format off diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 579c0b9..adff991 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -1043,6 +1043,28 @@ namespace VULKAN_HPP_NAMESPACE return std::tie( get(), get(), get()... ); } + template + typename std::enable_if< + std::is_same>::type>::value && + ( Which == 0 ), + bool>::type + isLinked() const VULKAN_HPP_NOEXCEPT + { + return true; + } + + template + typename std::enable_if< + !std::is_same>::type>::value || + ( Which != 0 ), + bool>::type + isLinked() const VULKAN_HPP_NOEXCEPT + { + static_assert( IsPartOfStructureChain::valid, + "Can't unlink Structure that's not part of this StructureChain!" ); + return isLinked( reinterpret_cast( &get() ) ); + } + template void relink() VULKAN_HPP_NOEXCEPT { @@ -1106,10 +1128,10 @@ namespace VULKAN_HPP_NAMESPACE Types...> : std::integral_constant {}; - bool isLinked( VkBaseInStructure const * pNext ) + bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT { VkBaseInStructure const * elementPtr = reinterpret_cast( - &std::get<0>( static_cast &>( *this ) ) ); + &std::get<0>( static_cast const &>( *this ) ) ); while ( elementPtr ) { if ( elementPtr->pNext == pNext )