-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into multiple_sections
- Loading branch information
Showing
38 changed files
with
1,068 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* LegacyClonk | ||
* | ||
* Copyright (c) 2023, The LegacyClonk Team and contributors | ||
* | ||
* Distributed under the terms of the ISC license; see accompanying file | ||
* "COPYING" for details. | ||
* | ||
* "Clonk" is a registered trademark of Matthes Bender, used with permission. | ||
* See accompanying file "TRADEMARK" for details. | ||
* | ||
* To redistribute this file separately, substitute the full license texts | ||
* for the above references. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cassert> | ||
#include <utility> | ||
|
||
class C4DeletionTrackable | ||
{ | ||
class Tracker | ||
{ | ||
public: | ||
constexpr Tracker(C4DeletionTrackable *const tracked) noexcept : tracked{tracked} | ||
{ | ||
assert(!tracked->tracker); | ||
tracked->tracker = this; | ||
} | ||
|
||
Tracker(const Tracker &) = delete; | ||
|
||
constexpr Tracker(Tracker &&other) noexcept : tracked{std::exchange(other.tracked, nullptr)}, isDeleted{other.isDeleted} | ||
{ | ||
if (!tracked) | ||
{ | ||
return; | ||
} | ||
|
||
assert(tracked->tracker == &other); | ||
tracked->tracker = this; | ||
} | ||
|
||
Tracker &operator=(const Tracker &) = delete; | ||
|
||
constexpr Tracker &operator=(Tracker &&other) noexcept | ||
{ | ||
Clear(); | ||
tracked = std::exchange(other.tracked, nullptr); | ||
isDeleted = other.isDeleted; | ||
|
||
if (tracked) | ||
{ | ||
assert(tracked->tracker == &other); | ||
tracked->tracker = this; | ||
} | ||
|
||
return *this; | ||
} | ||
|
||
constexpr ~Tracker() noexcept | ||
{ | ||
Clear(); | ||
} | ||
|
||
constexpr bool IsDeleted() const noexcept | ||
{ | ||
return isDeleted; | ||
} | ||
|
||
private: | ||
constexpr void Clear() noexcept | ||
{ | ||
if (tracked && !isDeleted) | ||
{ | ||
assert(tracked->tracker == this); | ||
tracked->tracker = nullptr; | ||
} | ||
} | ||
|
||
C4DeletionTrackable *tracked{nullptr}; | ||
bool isDeleted{false}; | ||
|
||
friend C4DeletionTrackable; | ||
}; | ||
|
||
public: | ||
constexpr ~C4DeletionTrackable() noexcept | ||
{ | ||
if (tracker) | ||
{ | ||
tracker->isDeleted = true; | ||
} | ||
} | ||
|
||
[[nodiscard]] constexpr Tracker TrackDeletion() noexcept | ||
{ | ||
return {this}; | ||
} | ||
|
||
private: | ||
Tracker *tracker{nullptr}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.