CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
TypedID.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include <functional>
11
12namespace CeresEngine {
13
14 template<typename Tag, typename TType> struct TypedID {
15 using Type = TType;
16
17 public:
19
20 public:
21 static constexpr Type Default = TType();
22
23 constexpr TypedID() noexcept : raw(0) {}
24 explicit constexpr TypedID(Type raw) noexcept : raw(raw) {}
25
26 public:
27 [[nodiscard]] explicit constexpr operator Type() const noexcept { return raw; }
28 [[nodiscard]] constexpr Type getValue() const noexcept { return raw; }
29
30 [[nodiscard]] constexpr bool operator==(const TypedID& value) const noexcept { return raw == value.raw; }
31 [[nodiscard]] constexpr bool operator!=(const TypedID& value) const noexcept { return !(*this == value); }
32
33 [[nodiscard]] constexpr bool isValid() const noexcept { return raw != Default; }
34 };
35
36} // namespace CeresEngine
37
38template<typename Tag, typename Type> struct std::hash<CeresEngine::TypedID<Tag, Type>> {
39 using result_type = std::size_t;
40 using argument_type = CeresEngine::TypedID<Tag, Type>;
41
42 result_type operator()(const argument_type& id) const { return std::hash<Type>{}(id.raw); }
43};
Definition Application.hpp:19
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition TypedID.hpp:14
constexpr bool operator==(const TypedID &value) const noexcept
Definition TypedID.hpp:30
TType Type
Definition TypedID.hpp:15
constexpr bool operator!=(const TypedID &value) const noexcept
Definition TypedID.hpp:31
constexpr TypedID(Type raw) noexcept
Definition TypedID.hpp:24
constexpr TypedID() noexcept
Definition TypedID.hpp:23
constexpr bool isValid() const noexcept
Definition TypedID.hpp:33
constexpr Type getValue() const noexcept
Definition TypedID.hpp:28
Type raw
Definition TypedID.hpp:18
static constexpr Type Default
Definition TypedID.hpp:21