From b72eba81576c925a676971e7246a0a6c99617d6e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 30 Oct 2020 14:47:30 +0100 Subject: [PATCH] [libcalamares] Extend the Deleter-helper with "preserve" Sometimes you want to keep the thing around after all. --- src/libcalamares/utils/RAII.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/utils/RAII.h b/src/libcalamares/utils/RAII.h index d6f8fe94d..1cbead4a2 100644 --- a/src/libcalamares/utils/RAII.h +++ b/src/libcalamares/utils/RAII.h @@ -16,20 +16,28 @@ #include -/// @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 > struct cqDeleter { T*& p; + bool preserve = false; ~cqDeleter() { static_assert( std::is_base_of< QObject, T >::value, "Not a QObject-class" ); - if ( p ) + if ( !preserve ) { - p->deleteLater(); + if ( p ) + { + p->deleteLater(); + } + p = nullptr; } - p = nullptr; } };