Extend checking of StructureChains to allow transitive extension. (#254)

This commit is contained in:
Andreas Süßenbach
2018-09-20 15:20:00 +02:00
committed by Markus Tavenrath
parent 1ddafc1c56
commit 295d5c755f
3 changed files with 106 additions and 34 deletions

View File

@@ -479,8 +479,34 @@ namespace VULKAN_HPP_NAMESPACE
#endif
template <typename X, typename Y> struct isStructureChainValid { enum { value = false }; };
template <typename P, typename T>
struct TypeList
{
using list = P;
using last = T;
};
template <typename List, typename X>
struct extendCheck
{
static const bool valid = isStructureChainValid<typename List::last, X>::value || extendCheck<typename List::list,X>::valid;
};
template <typename T, typename X>
struct extendCheck<TypeList<void,T>,X>
{
static const bool valid = isStructureChainValid<T, X>::value;
};
template <typename X>
struct extendCheck<void,X>
{
static const bool valid = true;
};
template <class Element>
class StructureChainElement
{
@@ -497,75 +523,78 @@ namespace VULKAN_HPP_NAMESPACE
public:
StructureChain()
{
link<StructureElements...>();
link<void, StructureElements...>();
}
StructureChain(StructureChain const &rhs)
{
linkAndCopy<StructureElements...>(rhs);
linkAndCopy<void, StructureElements...>(rhs);
}
StructureChain(StructureElements const &... elems)
{
linkAndCopyElements<StructureElements...>(elems...);
linkAndCopyElements<void, StructureElements...>(elems...);
}
StructureChain& operator=(StructureChain const &rhs)
{
linkAndCopy<StructureElements...>(rhs);
linkAndCopy<void, StructureElements...>(rhs);
return *this;
}
template<typename ClassType> ClassType& get() { return static_cast<ClassType&>(*this);}
private:
template<typename X>
template<typename List, typename X>
void link()
{
static_assert(extendCheck<List, X>::valid, "The structure chain is not valid!");
}
template<typename X, typename Y, typename ...Z>
template<typename List, typename X, typename Y, typename ...Z>
void link()
{
static_assert(isStructureChainValid<X,Y>::value, "The structure chain is not valid!");
static_assert(extendCheck<List,X>::valid, "The structure chain is not valid!");
X& x = static_cast<X&>(*this);
Y& y = static_cast<Y&>(*this);
x.pNext = &y;
link<Y, Z...>();
link<TypeList<List, X>, Y, Z...>();
}
template<typename X>
template<typename List, typename X>
void linkAndCopy(StructureChain const &rhs)
{
static_assert(extendCheck<List, X>::valid, "The structure chain is not valid!");
static_cast<X&>(*this) = static_cast<X const &>(rhs);
}
template<typename X, typename Y, typename ...Z>
template<typename List, typename X, typename Y, typename ...Z>
void linkAndCopy(StructureChain const &rhs)
{
static_assert(isStructureChainValid<X,Y>::value, "The structure chain is not valid!");
static_assert(extendCheck<List, X>::valid, "The structure chain is not valid!");
X& x = static_cast<X&>(*this);
Y& y = static_cast<Y&>(*this);
x = static_cast<X const &>(rhs);
x.pNext = &y;
linkAndCopy<Y, Z...>(rhs);
linkAndCopy<TypeList<List, X>, Y, Z...>(rhs);
}
template<typename X>
template<typename List, typename X>
void linkAndCopyElements(X const &xelem)
{
static_assert(extendCheck<List, X>::valid, "The structure chain is not valid!");
static_cast<X&>(*this) = xelem;
}
template<typename X, typename Y, typename ...Z>
template<typename List, typename X, typename Y, typename ...Z>
void linkAndCopyElements(X const &xelem, Y const &yelem, Z const &... zelem)
{
static_assert(isStructureChainValid<X,Y>::value, "The structure chain is not valid!");
static_assert(extendCheck<List, X>::valid, "The structure chain is not valid!");
X& x = static_cast<X&>(*this);
Y& y = static_cast<Y&>(*this);
x = xelem;
x.pNext = &y;
linkAndCopyElements<Y, Z...>(yelem, zelem...);
linkAndCopyElements<TypeList<List, X>, Y, Z...>(yelem, zelem...);
}
};