forked from OpenRCT2/OpenRCT2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OpenRCT2#22723 from Gymnasiast/refactor/flag-holder
Create FlagHolder
- Loading branch information
Showing
3 changed files
with
67 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/***************************************************************************** | ||
* Copyright (c) 2014-2024 OpenRCT2 developers | ||
* | ||
* For a complete list of all authors, please refer to contributors.md | ||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 | ||
* | ||
* OpenRCT2 is licensed under the GNU General Public License version 3. | ||
*****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
template<typename THolderType, typename TEnumType> struct FlagHolder | ||
{ | ||
THolderType holder{}; | ||
|
||
constexpr void clearAll() | ||
{ | ||
holder = 0; | ||
} | ||
|
||
[[nodiscard]] constexpr bool isEmpty() const | ||
{ | ||
return holder == 0; | ||
} | ||
|
||
[[nodiscard]] constexpr bool has(TEnumType flag) const | ||
{ | ||
return (holder & EnumToFlag(flag)) != 0; | ||
} | ||
|
||
constexpr void set(TEnumType flag) | ||
{ | ||
holder |= EnumToFlag(flag); | ||
} | ||
|
||
constexpr void unset(TEnumType flag) | ||
{ | ||
holder &= ~EnumToFlag(flag); | ||
} | ||
|
||
constexpr void flip(TEnumType flag) | ||
{ | ||
holder ^= EnumToFlag(flag); | ||
} | ||
}; |
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