2023-07-10 13:54:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QSGNode>
|
|
|
|
|
2023-07-17 08:03:33 +00:00
|
|
|
namespace QskSGNode
|
2023-07-20 14:12:54 +00:00
|
|
|
{
|
2023-07-25 08:59:03 +00:00
|
|
|
enum AppendMode : bool {
|
|
|
|
Sequential = false,
|
|
|
|
Recursive = true
|
|
|
|
};
|
|
|
|
|
2023-07-20 14:12:54 +00:00
|
|
|
namespace detail
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
2023-07-25 08:59:03 +00:00
|
|
|
template< AppendMode Mode, typename... Ts >
|
2023-07-20 14:12:54 +00:00
|
|
|
struct append;
|
2023-07-10 13:54:53 +00:00
|
|
|
|
2023-07-20 14:12:54 +00:00
|
|
|
template<>
|
2023-07-25 08:59:03 +00:00
|
|
|
struct append<AppendMode::Recursive>
|
|
|
|
{
|
|
|
|
static void nodes( QSGNode* root )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct append<AppendMode::Sequential>
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
2023-07-20 14:12:54 +00:00
|
|
|
static void nodes( QSGNode* root )
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
}
|
2023-07-20 14:12:54 +00:00
|
|
|
};
|
2023-07-10 13:54:53 +00:00
|
|
|
|
2023-07-20 14:12:54 +00:00
|
|
|
template< typename Child, typename... Children >
|
2023-07-25 08:59:03 +00:00
|
|
|
struct append< AppendMode::Recursive, Child, Children... >
|
|
|
|
{
|
|
|
|
static void nodes( QSGNode* root )
|
|
|
|
{
|
|
|
|
auto* const child = new Child;
|
|
|
|
root->appendChildNode( child );
|
|
|
|
append< AppendMode::Recursive, Children... >::nodes( child );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template< typename Child, typename... Children >
|
|
|
|
struct append< AppendMode::Sequential, Child, Children... >
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
2023-07-20 14:12:54 +00:00
|
|
|
static void nodes( QSGNode* root )
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
2023-07-20 14:12:54 +00:00
|
|
|
auto* const child = new Child;
|
|
|
|
root->appendChildNode( child );
|
2023-07-25 08:59:03 +00:00
|
|
|
append< AppendMode::Sequential, Children... >::nodes( root );
|
2023-07-10 13:54:53 +00:00
|
|
|
}
|
2023-07-20 14:12:54 +00:00
|
|
|
};
|
|
|
|
}
|
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 08:59:03 +00:00
|
|
|
root = new std::remove_const_t<Root>();
|
|
|
|
detail::append< mode, Children... >::nodes( root );
|
2023-07-10 13:54:53 +00:00
|
|
|
}
|
2023-07-25 08:59:03 +00:00
|
|
|
return static_cast<Root*>(root);
|
2023-07-20 14:12:54 +00:00
|
|
|
}
|
2023-07-10 13:54:53 +00:00
|
|
|
}
|