mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
Create FlagHolder
This commit is contained in:
45
src/openrct2/core/FlagHolder.hpp
Normal file
45
src/openrct2/core/FlagHolder.hpp
Normal file
@@ -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);
|
||||
}
|
||||
};
|
||||
@@ -222,6 +222,7 @@
|
||||
<ClInclude Include="core\Range.hpp" />
|
||||
<ClInclude Include="core\RTL.h" />
|
||||
<ClInclude Include="core\FixedVector.h" />
|
||||
<ClInclude Include="core\FlagHolder.hpp" />
|
||||
<ClInclude Include="core\Speed.hpp" />
|
||||
<ClInclude Include="core\String.hpp" />
|
||||
<ClInclude Include="core\StringBuilder.h" />
|
||||
|
||||
Reference in New Issue
Block a user