Introduce TIdentifier

This commit is contained in:
ζeh Matt 2021-11-07 16:14:25 +02:00
parent 41e17a0c5b
commit f703c3e805
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,61 @@
/*****************************************************************************
* Copyright (c) 2014-2021 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
#include <cstdint>
#include <cstdio>
#include <limits>
template<typename T, T TNullValue, typename TTag> class TIdentifier
{
enum class ValueType : T
{
Null = TNullValue,
} _handle;
private:
explicit TIdentifier(const T index)
: _handle{ static_cast<ValueType>(index) }
{
}
public:
static constexpr auto Null = ValueType::Null;
TIdentifier(const ValueType other)
: _handle{ other }
{
}
static constexpr TIdentifier FromUnderlying(const T val) noexcept
{
return TIdentifier{ val };
}
constexpr T ToUnderlying() const noexcept
{
return static_cast<T>(_handle);
}
constexpr bool IsNull() const noexcept
{
return _handle == ValueType::Null;
}
constexpr bool operator==(const ValueType other) const noexcept
{
return _handle == other;
}
constexpr bool operator!=(const ValueType other) const noexcept
{
return _handle != other;
}
};

View File

@ -169,6 +169,7 @@
<ClInclude Include="core\GroupVector.hpp" />
<ClInclude Include="core\Guard.hpp" />
<ClInclude Include="core\Http.h" />
<ClInclude Include="core\Identifier.hpp" />
<ClInclude Include="core\Imaging.h" />
<ClInclude Include="core\IStream.hpp" />
<ClInclude Include="core\JobPool.h" />