mirror of https://github.com/OpenRCT2/OpenRCT2.git
Introduce TIdentifier
This commit is contained in:
parent
41e17a0c5b
commit
f703c3e805
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -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" />
|
||||
|
|
Loading…
Reference in New Issue