use fold expressiong for ensureNodes
This commit is contained in:
parent
4acd03c21b
commit
bfc5dab5b1
|
@ -406,7 +406,7 @@ QSGNode* QskLevelingSensorSkinlet::updateSubNode(
|
|||
const QskSkinnable* const skinnable, const quint8 nodeRole, QSGNode* const node ) const
|
||||
{
|
||||
const auto* const sensor = static_cast< const Q* >( skinnable );
|
||||
|
||||
|
||||
switch ( static_cast< R >( nodeRole ) )
|
||||
{
|
||||
case OuterDisk:
|
||||
|
|
|
@ -3,64 +3,36 @@
|
|||
#include <QSGNode>
|
||||
|
||||
namespace QskSGNode
|
||||
{
|
||||
enum AppendMode : bool {
|
||||
Sequential = false,
|
||||
Recursive = true
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
enum AppendMode
|
||||
{
|
||||
template< AppendMode Mode, typename... Ts >
|
||||
struct append;
|
||||
|
||||
template<>
|
||||
struct append<AppendMode::Recursive>
|
||||
{
|
||||
static void nodes( QSGNode* root )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct append<AppendMode::Sequential>
|
||||
{
|
||||
static void nodes( QSGNode* root )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template< typename Child, typename... Children >
|
||||
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... >
|
||||
{
|
||||
static void nodes( QSGNode* root )
|
||||
{
|
||||
auto* const child = new Child;
|
||||
root->appendChildNode( child );
|
||||
append< AppendMode::Sequential, Children... >::nodes( root );
|
||||
}
|
||||
};
|
||||
}
|
||||
Sequential,
|
||||
Recursive
|
||||
};
|
||||
|
||||
template< AppendMode mode, typename Root, typename... Children >
|
||||
inline Q_REQUIRED_RESULT Root* ensureNodes( QSGNode* root = nullptr )
|
||||
{
|
||||
if ( root == nullptr )
|
||||
{
|
||||
root = new std::remove_const_t<Root>();
|
||||
detail::append< mode, Children... >::nodes( root );
|
||||
root = new Root;
|
||||
}
|
||||
return static_cast<Root*>(root);
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue