2022-07-28 15:09:08 +00:00
|
|
|
template <typename X, typename Y>
|
|
|
|
struct StructExtends
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
value = false
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Type, class...>
|
|
|
|
struct IsPartOfStructureChain
|
|
|
|
{
|
|
|
|
static const bool valid = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Type, typename Head, typename... Tail>
|
|
|
|
struct IsPartOfStructureChain<Type, Head, Tail...>
|
|
|
|
{
|
|
|
|
static const bool valid = std::is_same<Type, Head>::value || IsPartOfStructureChain<Type, Tail...>::valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t Index, typename T, typename... ChainElements>
|
|
|
|
struct StructureChainContains
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static const bool value = std::is_same<T, typename std::tuple_element<Index, std::tuple<ChainElements...>>::type>::value ||
|
|
|
|
StructureChainContains<Index - 1, T, ChainElements...>::value;
|
2022-07-28 15:09:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, typename... ChainElements>
|
|
|
|
struct StructureChainContains<0, T, ChainElements...>
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static const bool value = std::is_same<T, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value;
|
2022-07-28 15:09:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t Index, typename... ChainElements>
|
|
|
|
struct StructureChainValidation
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
using TestType = typename std::tuple_element<Index, std::tuple<ChainElements...>>::type;
|
|
|
|
static const bool valid = StructExtends<TestType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value &&
|
|
|
|
( TestType::allowDuplicate || !StructureChainContains<Index - 1, TestType, ChainElements...>::value ) &&
|
|
|
|
StructureChainValidation<Index - 1, ChainElements...>::valid;
|
2022-07-28 15:09:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename... ChainElements>
|
|
|
|
struct StructureChainValidation<0, ChainElements...>
|
|
|
|
{
|
|
|
|
static const bool valid = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename... ChainElements>
|
|
|
|
class StructureChain : public std::tuple<ChainElements...>
|
|
|
|
{
|
2024-08-26 07:45:57 +00:00
|
|
|
// Note: StructureChain has no move constructor or move assignment operator, as it is not supposed to contain movable containers.
|
|
|
|
// In order to get a copy-operation on a move-operations, those functions are neither deleted nor defaulted.
|
2022-07-28 15:09:08 +00:00
|
|
|
public:
|
|
|
|
StructureChain() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, "The structure chain is not valid!" );
|
2022-07-28 15:09:08 +00:00
|
|
|
link<sizeof...( ChainElements ) - 1>();
|
|
|
|
}
|
|
|
|
|
|
|
|
StructureChain( StructureChain const & rhs ) VULKAN_HPP_NOEXCEPT : std::tuple<ChainElements...>( rhs )
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, "The structure chain is not valid!" );
|
2022-07-28 15:09:08 +00:00
|
|
|
link( &std::get<0>( *this ),
|
|
|
|
&std::get<0>( rhs ),
|
|
|
|
reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( *this ) ),
|
|
|
|
reinterpret_cast<VkBaseInStructure const *>( &std::get<0>( rhs ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
StructureChain( ChainElements const &... elems ) VULKAN_HPP_NOEXCEPT : std::tuple<ChainElements...>( elems... )
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static_assert( StructureChainValidation<sizeof...( ChainElements ) - 1, ChainElements...>::valid, "The structure chain is not valid!" );
|
2022-07-28 15:09:08 +00:00
|
|
|
link<sizeof...( ChainElements ) - 1>();
|
|
|
|
}
|
|
|
|
|
|
|
|
StructureChain & operator=( StructureChain const & rhs ) VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
std::tuple<ChainElements...>::operator=( rhs );
|
|
|
|
link( &std::get<0>( *this ),
|
|
|
|
&std::get<0>( rhs ),
|
|
|
|
reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( *this ) ),
|
|
|
|
reinterpret_cast<VkBaseInStructure const *>( &std::get<0>( rhs ) ) );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T = typename std::tuple_element<0, std::tuple<ChainElements...>>::type, size_t Which = 0>
|
|
|
|
T & get() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
return std::get<ChainElementIndex<0, T, Which, void, ChainElements...>::value>( static_cast<std::tuple<ChainElements...> &>( *this ) );
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T = typename std::tuple_element<0, std::tuple<ChainElements...>>::type, size_t Which = 0>
|
|
|
|
T const & get() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
return std::get<ChainElementIndex<0, T, Which, void, ChainElements...>::value>( static_cast<std::tuple<ChainElements...> const &>( *this ) );
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T0, typename T1, typename... Ts>
|
|
|
|
std::tuple<T0 &, T1 &, Ts &...> get() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return std::tie( get<T0>(), get<T1>(), get<Ts>()... );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T0, typename T1, typename... Ts>
|
|
|
|
std::tuple<T0 const &, T1 const &, Ts const &...> get() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return std::tie( get<T0>(), get<T1>(), get<Ts>()... );
|
|
|
|
}
|
|
|
|
|
2023-06-21 07:17:06 +00:00
|
|
|
// 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
|
|
|
|
{
|
2024-02-08 11:32:57 +00:00
|
|
|
T & lhs = get<T, Which>();
|
|
|
|
auto pNext = lhs.pNext;
|
|
|
|
lhs = rhs;
|
|
|
|
lhs.pNext = pNext;
|
2023-06-21 11:33:29 +00:00
|
|
|
return *this;
|
2023-06-21 07:17:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 15:09:08 +00:00
|
|
|
template <typename ClassType, size_t Which = 0>
|
2023-06-21 11:33:29 +00:00
|
|
|
typename std::enable_if<std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value && ( Which == 0 ), bool>::type
|
2022-07-28 15:09:08 +00:00
|
|
|
isLinked() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ClassType, size_t Which = 0>
|
2023-06-21 11:33:29 +00:00
|
|
|
typename std::enable_if<!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<ChainElements...>>::type>::value || ( Which != 0 ), bool>::type
|
2022-07-28 15:09:08 +00:00
|
|
|
isLinked() const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, "Can't unlink Structure that's not part of this StructureChain!" );
|
2022-07-28 15:09:08 +00:00
|
|
|
return isLinked( reinterpret_cast<VkBaseInStructure const *>( &get<ClassType, Which>() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ClassType, size_t Which = 0>
|
2023-06-21 11:33:29 +00:00
|
|
|
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
|
2022-07-28 15:09:08 +00:00
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, "Can't relink Structure that's not part of this StructureChain!" );
|
2022-07-28 15:09:08 +00:00
|
|
|
auto pNext = reinterpret_cast<VkBaseInStructure *>( &get<ClassType, Which>() );
|
|
|
|
VULKAN_HPP_ASSERT( !isLinked( pNext ) );
|
|
|
|
auto & headElement = std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) );
|
|
|
|
pNext->pNext = reinterpret_cast<VkBaseInStructure const *>( headElement.pNext );
|
|
|
|
headElement.pNext = pNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ClassType, size_t Which = 0>
|
2023-06-21 11:33:29 +00:00
|
|
|
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
|
2022-07-28 15:09:08 +00:00
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
static_assert( IsPartOfStructureChain<ClassType, ChainElements...>::valid, "Can't unlink Structure that's not part of this StructureChain!" );
|
2022-07-28 15:09:08 +00:00
|
|
|
unlink( reinterpret_cast<VkBaseOutStructure const *>( &get<ClassType, Which>() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <int Index, typename T, int Which, typename, class First, class... Types>
|
|
|
|
struct ChainElementIndex : ChainElementIndex<Index + 1, T, Which, void, Types...>
|
2023-06-21 11:33:29 +00:00
|
|
|
{
|
|
|
|
};
|
2022-07-28 15:09:08 +00:00
|
|
|
|
|
|
|
template <int Index, typename T, int Which, class First, class... Types>
|
2023-06-21 11:33:29 +00:00
|
|
|
struct ChainElementIndex<Index, T, Which, typename std::enable_if<!std::is_same<T, First>::value, void>::type, First, Types...>
|
|
|
|
: ChainElementIndex<Index + 1, T, Which, void, Types...>
|
|
|
|
{
|
|
|
|
};
|
2022-07-28 15:09:08 +00:00
|
|
|
|
|
|
|
template <int Index, typename T, int Which, class First, class... Types>
|
2023-06-21 11:33:29 +00:00
|
|
|
struct ChainElementIndex<Index, T, Which, typename std::enable_if<std::is_same<T, First>::value, void>::type, First, Types...>
|
|
|
|
: ChainElementIndex<Index + 1, T, Which - 1, void, Types...>
|
|
|
|
{
|
|
|
|
};
|
2022-07-28 15:09:08 +00:00
|
|
|
|
|
|
|
template <int Index, typename T, class First, class... Types>
|
2023-06-21 11:33:29 +00:00
|
|
|
struct ChainElementIndex<Index, T, 0, typename std::enable_if<std::is_same<T, First>::value, void>::type, First, Types...>
|
|
|
|
: std::integral_constant<int, Index>
|
|
|
|
{
|
|
|
|
};
|
2022-07-28 15:09:08 +00:00
|
|
|
|
|
|
|
bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
VkBaseInStructure const * elementPtr =
|
|
|
|
reinterpret_cast<VkBaseInStructure const *>( &std::get<0>( static_cast<std::tuple<ChainElements...> const &>( *this ) ) );
|
2022-07-28 15:09:08 +00:00
|
|
|
while ( elementPtr )
|
|
|
|
{
|
|
|
|
if ( elementPtr->pNext == pNext )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elementPtr = elementPtr->pNext;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t Index>
|
|
|
|
typename std::enable_if<Index != 0, void>::type link() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
auto & x = std::get<Index - 1>( static_cast<std::tuple<ChainElements...> &>( *this ) );
|
|
|
|
x.pNext = &std::get<Index>( static_cast<std::tuple<ChainElements...> &>( *this ) );
|
|
|
|
link<Index - 1>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t Index>
|
|
|
|
typename std::enable_if<Index == 0, void>::type link() VULKAN_HPP_NOEXCEPT
|
2023-06-21 11:33:29 +00:00
|
|
|
{
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
|
|
|
|
void link( void * dstBase, void const * srcBase, VkBaseOutStructure * dst, VkBaseInStructure const * src )
|
|
|
|
{
|
|
|
|
while ( src->pNext )
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
std::ptrdiff_t offset = reinterpret_cast<char const *>( src->pNext ) - reinterpret_cast<char const *>( srcBase );
|
|
|
|
dst->pNext = reinterpret_cast<VkBaseOutStructure *>( reinterpret_cast<char *>( dstBase ) + offset );
|
|
|
|
dst = dst->pNext;
|
|
|
|
src = src->pNext;
|
2022-07-28 15:09:08 +00:00
|
|
|
}
|
|
|
|
dst->pNext = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
2023-06-21 11:33:29 +00:00
|
|
|
VkBaseOutStructure * elementPtr = reinterpret_cast<VkBaseOutStructure *>( &std::get<0>( static_cast<std::tuple<ChainElements...> &>( *this ) ) );
|
2022-07-28 15:09:08 +00:00
|
|
|
while ( elementPtr && ( elementPtr->pNext != pNext ) )
|
|
|
|
{
|
|
|
|
elementPtr = elementPtr->pNext;
|
|
|
|
}
|
|
|
|
if ( elementPtr )
|
|
|
|
{
|
|
|
|
elementPtr->pNext = pNext->pNext;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VULKAN_HPP_ASSERT( false ); // fires, if the ClassType member has already been unlinked !
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-06-22 12:02:39 +00:00
|
|
|
// interupt the VULKAN_HPP_NAMESPACE for a moment to add specializations of std::tuple_size and std::tuple_element for the StructureChain!
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template <typename... Elements>
|
|
|
|
struct tuple_size<VULKAN_HPP_NAMESPACE::StructureChain<Elements...>>
|
|
|
|
{
|
|
|
|
static constexpr size_t value = std::tuple_size<std::tuple<Elements...>>::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <std::size_t Index, typename... Elements>
|
|
|
|
struct tuple_element<Index, VULKAN_HPP_NAMESPACE::StructureChain<Elements...>>
|
|
|
|
{
|
|
|
|
using type = typename std::tuple_element<Index, std::tuple<Elements...>>::type;
|
|
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace VULKAN_HPP_NAMESPACE
|
|
|
|
{
|