Introduce functions vk::StructureChain::unlink<ClassType>() and vk::StructureChain::relink<ClassType>(). (#441)

Resolves #439.
This commit is contained in:
Andreas Süßenbach
2019-11-28 15:58:15 +01:00
committed by Markus Tavenrath
parent e40eb90980
commit f2058303cb
4 changed files with 122 additions and 0 deletions

View File

@@ -431,6 +431,18 @@ namespace VULKAN_HPP_NAMESPACE
static const bool valid = true;
};
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 <class Element>
class StructureChainElement
{
@@ -477,6 +489,45 @@ namespace VULKAN_HPP_NAMESPACE
);
}
template<typename ClassType>
void unlink() VULKAN_HPP_NOEXCEPT
{
static_assert(isPartOfStructureChain<ClassType, StructureElements...>::valid, "Can't unlink Structure that's not part of this StructureChain!");
static_assert(!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<StructureElements...>>::type>::value, "It's not allowed to unlink the first element!");
VkBaseOutStructure * ptr = reinterpret_cast<VkBaseOutStructure*>(&get<ClassType>());
assert(ptr != nullptr);
VkBaseOutStructure ** ppNext = &(reinterpret_cast<VkBaseOutStructure*>(this)->pNext);
assert(*ppNext != nullptr);
while (*ppNext != ptr)
{
ppNext = &(*ppNext)->pNext;
assert(*ppNext != nullptr); // fires, if the ClassType member has already been unlinked !
}
assert(*ppNext == ptr);
*ppNext = (*ppNext)->pNext;
}
template <typename ClassType>
void relink() VULKAN_HPP_NOEXCEPT
{
static_assert(isPartOfStructureChain<ClassType, StructureElements...>::valid, "Can't relink Structure that's not part of this StructureChain!");
static_assert(!std::is_same<ClassType, typename std::tuple_element<0, std::tuple<StructureElements...>>::type>::value, "It's not allowed to have the first element unlinked!");
VkBaseOutStructure * ptr = reinterpret_cast<VkBaseOutStructure*>(&get<ClassType>());
assert(ptr != nullptr);
VkBaseOutStructure ** ppNext = &(reinterpret_cast<VkBaseOutStructure*>(this)->pNext);
assert(*ppNext != nullptr);
#if !defined(NDEBUG)
while (*ppNext)
{
assert(*ppNext != ptr); // fires, if the ClassType member has not been unlinked before
ppNext = &(*ppNext)->pNext;
}
ppNext = &(reinterpret_cast<VkBaseOutStructure*>(this)->pNext);
#endif
ptr->pNext = *ppNext;
*ppNext = ptr;
}
private:
template<typename List, typename X>
void link() VULKAN_HPP_NOEXCEPT