Merge pull request #859 from asuessenbach/StructureChain

Introduce new function StructureChain::isLinked<>()
This commit is contained in:
Andreas Süßenbach 2021-01-20 16:38:20 +01:00 committed by GitHub
commit 85fb79c2c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 4 deletions

View File

@ -10665,6 +10665,28 @@ int main( int argc, char ** argv )
return std::tie( get<T0>(), get<T1>(), get<Ts>()... ); return std::tie( get<T0>(), get<T1>(), get<Ts>()... );
} }
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
isLinked() const VULKAN_HPP_NOEXCEPT
{
return true;
}
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
isLinked() const VULKAN_HPP_NOEXCEPT
{
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid,
"Can't unlink Structure that's not part of this StructureChain!" );
return isLinked( reinterpret_cast<VkBaseInStructure const *>( &get<ClassType, Which>() ) );
}
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
void relink() VULKAN_HPP_NOEXCEPT void relink() VULKAN_HPP_NOEXCEPT
{ {
@ -10725,9 +10747,10 @@ int main( int argc, char ** argv )
Types...> : std::integral_constant<int, Index> Types...> : std::integral_constant<int, Index>
{}; {};
bool isLinked( VkBaseInStructure const * pNext ) bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT
{ {
VkBaseInStructure const * elementPtr = reinterpret_cast<VkBaseInStructure const*>(&std::get<0>( static_cast<std::tuple<ChainElements...>&>( *this ) ) ); VkBaseInStructure const * elementPtr = 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 )

View File

@ -74,6 +74,10 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDevicePushDescriptorPropertiesKHR> vk::PhysicalDevicePushDescriptorPropertiesKHR>
sc7; sc7;
// some checks on unmodified chains
assert( sc7.isLinked<vk::PhysicalDeviceProperties2>() );
assert( sc7.isLinked<vk::PhysicalDeviceMaintenance3Properties>() );
// some invalid StructureChains // some invalid StructureChains
// clang-format off // clang-format off
//vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties> x; //vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties> x;
@ -91,6 +95,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// unlink a struct from a StructureChain // unlink a struct from a StructureChain
sc7.unlink<vk::PhysicalDeviceMaintenance3Properties>(); sc7.unlink<vk::PhysicalDeviceMaintenance3Properties>();
assert( !sc7.isLinked<vk::PhysicalDeviceMaintenance3Properties>() );
// some invalid unlink calls // some invalid unlink calls
// clang-format off // clang-format off
@ -102,6 +107,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// re-link a struct // re-link a struct
sc7.relink<vk::PhysicalDeviceMaintenance3Properties>(); sc7.relink<vk::PhysicalDeviceMaintenance3Properties>();
assert( sc7.isLinked<vk::PhysicalDeviceMaintenance3Properties>() );
// invalid re-linking // invalid re-linking
// clang-format off // clang-format off

View File

@ -1043,6 +1043,28 @@ namespace VULKAN_HPP_NAMESPACE
return std::tie( get<T0>(), get<T1>(), get<Ts>()... ); return std::tie( get<T0>(), get<T1>(), get<Ts>()... );
} }
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
isLinked() const VULKAN_HPP_NOEXCEPT
{
return true;
}
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
isLinked() const VULKAN_HPP_NOEXCEPT
{
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid,
"Can't unlink Structure that's not part of this StructureChain!" );
return isLinked( reinterpret_cast<VkBaseInStructure const *>( &get<ClassType, Which>() ) );
}
template <typename ClassType, size_t Which = 0> template <typename ClassType, size_t Which = 0>
void relink() VULKAN_HPP_NOEXCEPT void relink() VULKAN_HPP_NOEXCEPT
{ {
@ -1106,10 +1128,10 @@ namespace VULKAN_HPP_NAMESPACE
Types...> : std::integral_constant<int, Index> Types...> : std::integral_constant<int, Index>
{}; {};
bool isLinked( VkBaseInStructure const * pNext ) bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT
{ {
VkBaseInStructure const * elementPtr = reinterpret_cast<VkBaseInStructure const *>( VkBaseInStructure const * elementPtr = reinterpret_cast<VkBaseInStructure const *>(
&std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) ) ); &std::get<0>( static_cast<std::tuple<ChainElements...> const &>( *this ) ) );
while ( elementPtr ) while ( elementPtr )
{ {
if ( elementPtr->pNext == pNext ) if ( elementPtr->pNext == pNext )