2023-07-10 13:54:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QSGNode>
|
|
|
|
|
2023-07-17 08:03:33 +00:00
|
|
|
namespace QskSGNode
|
2023-07-25 10:36:13 +00:00
|
|
|
{
|
|
|
|
enum AppendMode
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
2023-07-25 10:36:13 +00:00
|
|
|
Sequential,
|
|
|
|
Recursive
|
|
|
|
};
|
2023-07-10 13:54:53 +00:00
|
|
|
|
2023-07-25 08:59:03 +00:00
|
|
|
template< AppendMode mode, typename Root, typename... Children >
|
|
|
|
inline Q_REQUIRED_RESULT Root* ensureNodes( QSGNode* root = nullptr )
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
2023-07-20 14:12:54 +00:00
|
|
|
if ( root == nullptr )
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
2023-07-25 10:36:13 +00:00
|
|
|
root = new Root;
|
2023-07-10 13:54:53 +00:00
|
|
|
}
|
2023-07-25 10:36:13 +00:00
|
|
|
|
|
|
|
if constexpr ( mode == Recursive )
|
|
|
|
{
|
|
|
|
QSGNode* current = root;
|
|
|
|
(
|
|
|
|
[ & ]( QSGNode* const child ) {
|
|
|
|
current->appendChildNode( child );
|
|
|
|
current = child;
|
|
|
|
}( new Children ),
|
|
|
|
... );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
( root->appendChildNode( new Children ), ... );
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast< Root* >( root );
|
2023-07-20 14:12:54 +00:00
|
|
|
}
|
2023-07-10 13:54:53 +00:00
|
|
|
}
|