From 8d908208f09d1cfe10766fa123f5d235192d0aee Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sat, 18 Sep 2021 21:35:34 +0300 Subject: [PATCH] Update Other.hpp --- module/Library/DPP/Other.hpp | 62 +++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/module/Library/DPP/Other.hpp b/module/Library/DPP/Other.hpp index d052be5a..84f0dbec 100644 --- a/module/Library/DPP/Other.hpp +++ b/module/Library/DPP/Other.hpp @@ -114,11 +114,7 @@ struct DpActivity /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~DpActivity() noexcept - { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); - } + ~DpActivity() noexcept { Cleanup(); } /* -------------------------------------------------------------------------------------------- * Copy assignment operator (disabled). */ @@ -129,14 +125,24 @@ struct DpActivity DpActivity & operator = (DpActivity && o) noexcept { if (this != &o) { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); + Cleanup(); // Transfer members values mPtr = std::move(o.mPtr); mOwned = o.mOwned; } return *this; } + /* -------------------------------------------------------------------------------------------- + * Release any referenced resources and default to an empty/invalid state. + */ + void Cleanup() + { + // Do we own this to try delete it? + if (!mOwned && mPtr) { + // Not our job, simply forget about it + [[maybe_unused]] auto p = mPtr.release(); + } else mPtr.reset(); // We own this so delete the instance + } /* -------------------------------------------------------------------------------------------- * Validate the managed handle. */ @@ -302,11 +308,7 @@ struct DpPresence /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~DpPresence() noexcept - { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); - } + ~DpPresence() noexcept { Cleanup(); } /* -------------------------------------------------------------------------------------------- * Copy assignment operator (disabled). */ @@ -317,14 +319,24 @@ struct DpPresence DpPresence & operator = (DpPresence && o) noexcept { if (this != &o) { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); + Cleanup(); // Transfer members values mPtr = std::move(o.mPtr); mOwned = o.mOwned; } return *this; } + /* -------------------------------------------------------------------------------------------- + * Release any referenced resources and default to an empty/invalid state. + */ + void Cleanup() + { + // Do we own this to try delete it? + if (!mOwned && mPtr) { + // Not our job, simply forget about it + [[maybe_unused]] auto p = mPtr.release(); + } else mPtr.reset(); // We own this so delete the instance + } /* -------------------------------------------------------------------------------------------- * Validate the managed handle. */ @@ -489,11 +501,7 @@ struct DpVoiceState /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~DpVoiceState() noexcept - { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); - } + ~DpVoiceState() noexcept { Cleanup(); } /* -------------------------------------------------------------------------------------------- * Copy assignment operator (disabled). */ @@ -504,14 +512,24 @@ struct DpVoiceState DpVoiceState & operator = (DpVoiceState && o) noexcept { if (this != &o) { - // Do we own this to try delete it? - if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); + Cleanup(); // Transfer members values mPtr = std::move(o.mPtr); mOwned = o.mOwned; } return *this; } + /* -------------------------------------------------------------------------------------------- + * Release any referenced resources and default to an empty/invalid state. + */ + void Cleanup() + { + // Do we own this to try delete it? + if (!mOwned && mPtr) { + // Not our job, simply forget about it + [[maybe_unused]] auto p = mPtr.release(); + } else mPtr.reset(); // We own this so delete the instance + } /* -------------------------------------------------------------------------------------------- * Validate the managed handle. */ @@ -579,7 +597,7 @@ struct DpVoiceState /* -------------------------------------------------------------------------------------------- * Check if user is surpressed. */ - SQMOD_NODISCARD bool IsSupressed() const { return Valid().is_supressed(); } + SQMOD_NODISCARD bool IsSuppressed() const { return Valid().is_suppressed(); } }; /* ------------------------------------------------------------------------------------------------