Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Id.ipp
Go to the documentation of this file.
1#include "Id.hpp"
2
3namespace Engine {
4template <typename TDerived, typename TValue>
5constexpr BasicId<TDerived, TValue>::BasicId(TValue value_) : value{value_}
6{
7}
8template <typename TDerived, typename TValue> constexpr TDerived BasicId<TDerived, TValue>::Null(void)
9{
10 return TDerived::Null();
11}
12template <typename TDerived, typename TValue> constexpr bool BasicId<TDerived, TValue>::IsNull(void) const
13{
14 return value == TDerived::NullValue();
15}
16
17constexpr Id::Id(ValueType value_) : BasicId<Id, ValueType>{value_} {}
18
19constexpr Id::operator Id::ValueType() const { return value; }
20
21constexpr Id::ValueType Id::NullValue() { return entt::null; }
22
23constexpr Id Id::Null() { return Id{NullValue()}; }
24
25constexpr StringId::StringId(ValueType v) : BasicId<StringId, ValueType>{v} {}
26
27constexpr StringId::ValueType StringId::NullValue() { return entt::hashed_string{}; }
28
29constexpr StringId StringId::Null() { return StringId{NullValue()}; }
30} // namespace Engine
31
32template <typename FormatContext>
33auto fmt::formatter<Engine::Id>::format(const Engine::Id &id, FormatContext &context) const
34{
35 return fmt::formatter<entt::id_type>::format(id.value, context);
36}
37
38template <typename FormatContext>
39auto fmt::formatter<Engine::StringId>::format(const Engine::StringId &id, FormatContext &context) const
40{
41 return fmt::formatter<std::string_view>::format(std::string_view(id.value.data(), id.value.size()), context);
42}
Definition Core.hpp:17
An Id class for creating strongly-typed ID wrappers. This template provides a common interface for ID...
Definition Id.hpp:18
static constexpr TDerived Null(void)
Get the null value for this ID type. This should be defined by the derived class to specify what cons...
Definition Id.ipp:8
constexpr bool IsNull(void) const
Checks if the ID is null/invalid by comparing its value to the null value defined by the derived clas...
Definition Id.ipp:12
TValue value
The underlying value of the ID.
Definition Id.hpp:20
friend TDerived
Definition Id.hpp:37
A strongly-typed identifier wrapper based on entt::id_type. This structure provides a type-safe wrapp...
Definition Id.hpp:47
constexpr Id(ValueType value_=NullValue())
Constructor for Id.
Definition Id.ipp:17
static constexpr Id Null(void)
Get a null instance of Id, which has its value set to the null value defined by NullValue().
Definition Id.ipp:23
entt::id_type ValueType
Definition Id.hpp:48
static constexpr ValueType NullValue(void)
Get the null value for this ID type. This returns the null value defined by EnTT's id_type,...
Definition Id.ipp:21
A strongly-typed string identifier wrapper based on entt::hashed_string. This structure provides a ty...
Definition Id.hpp:79
static constexpr StringId Null()
Get a null instance of StringId, which has its value set to the null value defined by NullValue().
Definition Id.ipp:29
static constexpr ValueType NullValue()
Get the null value for this StringId type. This returns a default-constructed entt::hashed_string.
Definition Id.ipp:27
constexpr StringId(ValueType v=NullValue())
Constructor for StringId.
Definition Id.ipp:25
entt::hashed_string ValueType
The underlying value type for StringId, which is entt::hashed_string. This type encapsulates the stri...
Definition Id.hpp:83