1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Update Guild.hpp

This commit is contained in:
Sandu Liviu Catalin 2021-09-18 21:35:42 +03:00
parent 57321af0c7
commit 83f2ab79e0

View File

@ -59,11 +59,7 @@ struct DpGuildMember
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Destructor. * Destructor.
*/ */
~DpGuildMember() noexcept ~DpGuildMember() noexcept { Cleanup(); }
{
// Do we own this to try delete it?
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled). * Copy assignment operator (disabled).
*/ */
@ -75,13 +71,24 @@ struct DpGuildMember
{ {
if (this != &o) { if (this != &o) {
// Do we own this to try delete it? // Do we own this to try delete it?
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); Cleanup();
// Transfer members values // Transfer members values
mPtr = std::move(o.mPtr); mPtr = std::move(o.mPtr);
mOwned = o.mOwned; mOwned = o.mOwned;
} }
return *this; 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. * Validate the managed handle.
*/ */
@ -201,11 +208,7 @@ struct DpGuild
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Destructor. * Destructor.
*/ */
~DpGuild() noexcept ~DpGuild() noexcept { Cleanup(); }
{
// Do we own this to try delete it?
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled). * Copy assignment operator (disabled).
*/ */
@ -217,13 +220,24 @@ struct DpGuild
{ {
if (this != &o) { if (this != &o) {
// Do we own this to try delete it? // Do we own this to try delete it?
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release(); Cleanup();
// Transfer members values // Transfer members values
mPtr = std::move(o.mPtr); mPtr = std::move(o.mPtr);
mOwned = o.mOwned; mOwned = o.mOwned;
} }
return *this; 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. * Validate the managed handle.
*/ */