[libcalamares] Extend the Deleter-helper with "preserve"
Sometimes you want to keep the thing around after all.
This commit is contained in:
parent
7659dfdb9d
commit
b72eba8157
@ -16,21 +16,29 @@
|
|||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
/// @brief Convenience to zero out and deleteLater of any QObject-derived-class
|
/** @brief Convenience to zero out and deleteLater of any QObject-derived-class
|
||||||
|
*
|
||||||
|
* If, before destruction, preserve is set to @c true, then
|
||||||
|
* the object is "preserved", and not deleted at all.
|
||||||
|
*/
|
||||||
template < typename T >
|
template < typename T >
|
||||||
struct cqDeleter
|
struct cqDeleter
|
||||||
{
|
{
|
||||||
T*& p;
|
T*& p;
|
||||||
|
bool preserve = false;
|
||||||
|
|
||||||
~cqDeleter()
|
~cqDeleter()
|
||||||
{
|
{
|
||||||
static_assert( std::is_base_of< QObject, T >::value, "Not a QObject-class" );
|
static_assert( std::is_base_of< QObject, T >::value, "Not a QObject-class" );
|
||||||
|
if ( !preserve )
|
||||||
|
{
|
||||||
if ( p )
|
if ( p )
|
||||||
{
|
{
|
||||||
p->deleteLater();
|
p->deleteLater();
|
||||||
}
|
}
|
||||||
p = nullptr;
|
p = nullptr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Sets a bool to @p value and resets to !value on destruction
|
/// @brief Sets a bool to @p value and resets to !value on destruction
|
||||||
|
Loading…
Reference in New Issue
Block a user