CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
TypeInfo.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-2023 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
11
12#include "TypeName.hpp"
13#include "IReflectable.hpp"
14
16
17namespace CeresEngine {
18
21
25 template<typename T> consteval TypeIdentityHash getIdentityHash() noexcept {
27 }
28
29 enum class TypeAttribute {
30 NONE,
31 LREF,
32 RREF,
34 };
35
36 class TypeInfo {
37 public:
38 virtual ~TypeInfo() = default;
39
40 public:
42
43 [[nodiscard]] TypeID getID() const noexcept { return TypeID(reinterpret_cast<UInt64>(this)); }
44
47
48 public:
50 [[nodiscard]] virtual const TypeInfo& desugar() const { return *this; }
51
54 [[nodiscard]] virtual std::size_t getSize() const noexcept = 0;
55
59
60 template<typename T> [[nodiscard]] bool is() const noexcept { return dynamic_cast<const T*>(this) != nullptr; }
61 template<typename T> [[nodiscard]] const T* as() const noexcept { return dynamic_cast<const T*>(this); }
62 template<typename T> [[nodiscard]] const T* being() const noexcept { return dynamic_cast<const T*>(this); }
63
64 public:
66 [[nodiscard]] const TypeInfo& removePointer() const;
67 [[nodiscard]] const TypeInfo& removeConst() const;
68
69 public: // Construction, copy & move
70 [[nodiscard]] virtual const TypeInfo& getType(TypeAttribute attribute) const = 0;
71
78 [[nodiscard]] virtual const void* access(const void* target) const { return target; }
79 };
80
82 protected:
84
85 public:
93 virtual void construct(void* target) const = 0;
94 };
95
97 protected:
99
100 public:
105 virtual void destroy(void* target) const = 0;
106 };
107
109 protected:
111
112 public:
123 virtual void copy(void* target, const void* source) const = 0;
124 };
125
127 protected:
128 ~MovableTypeTrait() = default;
129
130 public:
141 virtual void move(void* target, void* source) const = 0;
142 };
143
145 protected:
147
148 public:
151 [[nodiscard]] virtual Box dereference(const Box& value) const = 0;
152 };
153
154 // ---------------------------------------------------------------------------------------------
155
158 protected:
160
161 public:
163 [[nodiscard]] virtual size_t hash(const Box& object) const = 0;
164 };
165
166 // ---------------------------------------------------------------------------------------------
167
169 protected:
171
172 public:
174 [[nodiscard]] virtual bool equals(const Box& lhs, const Box& rhs) const = 0;
175
177 [[nodiscard]] virtual bool notEquals(const Box& lhs, const Box& rhs) const {
178 return !equals(lhs, rhs);
179 }
180 };
181
182 // ---------------------------------------------------------------------------------------------
183
185 protected:
187
188 public:
189 [[nodiscard]] virtual bool greaterThan(const Box& lhs, const Box& rhs) const = 0;
190 [[nodiscard]] virtual bool greaterThanOrEquals(const Box& lhs, const Box& rhs) const = 0;
191 [[nodiscard]] virtual bool lessThan(const Box& lhs, const Box& rhs) const = 0;
192 [[nodiscard]] virtual bool lessThanOrEquals(const Box& lhs, const Box& rhs) const = 0;
193 };
194
195 // ---------------------------------------------------------------------------------------------
196
198 protected:
200
201 public:
202 virtual void increment(const Box& value) const = 0;
203 };
204
205 // ---------------------------------------------------------------------------------------------
206
208 protected:
210
211 public:
213 [[nodiscard]] virtual Box begin(const Box& value) const = 0;
214
216 [[nodiscard]] virtual Box end(const Box& value) const = 0;
217 };
218
219 // ---------------------------------------------------------------------------------------------
220
222 protected:
224
225 public:
231 [[nodiscard]] virtual Box get(const Box& target, size_t index) const = 0;
232
237 virtual void set(const Box& target, size_t index, Box&& value) const = 0;
238 };
239
243 protected:
245
246 public:
247 [[nodiscard]] virtual Box insert(const Box& container, const Box& where, Box&& value) const = 0;
248 };
249
253 protected:
255
256 public:
257 [[nodiscard]] virtual Box erase(const Box& container, const Box& where) const = 0;
258 };
259
260 // ---------------------------------------------------------------------------------------------
261
263 protected:
265
266 public:
267 virtual void pushBack(const Box& container, Box&& value) const = 0;
268 };
269
270} // namespace CeresEngine
A value type that can hold any alongside it's type information.
Definition Box.hpp:40
Definition TypeInfo.hpp:81
virtual void construct(void *target) const =0
Constructs a new instance at the given target address.
Definition TypeInfo.hpp:108
virtual void copy(void *target, const void *source) const =0
Copies the object from source to target.
Definition TypeInfo.hpp:144
virtual Box dereference(const Box &value) const =0
Dereferences the value at value.
Definition TypeInfo.hpp:96
virtual void destroy(void *target) const =0
Destroys an existing instance of the type at target address.
Definition TypeInfo.hpp:168
virtual bool notEquals(const Box &lhs, const Box &rhs) const
Definition TypeInfo.hpp:177
virtual bool equals(const Box &lhs, const Box &rhs) const =0
Definition TypeInfo.hpp:197
virtual void increment(const Box &value) const =0
Definition TypeInfo.hpp:221
virtual void set(const Box &target, size_t index, Box &&value) const =0
Sets the element at index position on target by using operator[].
virtual Box get(const Box &target, size_t index) const =0
Gets the element at index position on target by using operator[].
Definition TypeInfo.hpp:207
virtual Box begin(const Box &value) const =0
Gets the begin iterator value by calling valie.begin().
virtual Box end(const Box &value) const =0
Gets the begin iterator value by calling value.end().
Definition TypeInfo.hpp:126
virtual void move(void *target, void *source) const =0
Moves the object from source to target.
Definition TypeInfo.hpp:262
virtual void pushBack(const Box &container, Box &&value) const =0
Definition TypeInfo.hpp:184
virtual bool greaterThan(const Box &lhs, const Box &rhs) const =0
virtual bool greaterThanOrEquals(const Box &lhs, const Box &rhs) const =0
virtual bool lessThan(const Box &lhs, const Box &rhs) const =0
virtual bool lessThanOrEquals(const Box &lhs, const Box &rhs) const =0
Definition TypeInfo.hpp:36
TypeID getID() const noexcept
Definition TypeInfo.hpp:43
const TypeInfo & removeReference() const
bool is() const noexcept
Definition TypeInfo.hpp:60
virtual ~TypeInfo()=default
virtual std::size_t getSize() const noexcept=0
virtual const TypeInfo & desugar() const
Desugar the type into a raw type.
Definition TypeInfo.hpp:50
virtual TypeIdentityHash getIdentityHash() const noexcept=0
virtual const TypeInfo & getType(TypeAttribute attribute) const =0
const TypeInfo & removeConst() const
const T * being() const noexcept
Definition TypeInfo.hpp:62
const T * as() const noexcept
Definition TypeInfo.hpp:61
virtual const void * access(const void *target) const
Provides access to the object.
Definition TypeInfo.hpp:78
virtual StringView getName() const noexcept=0
const TypeInfo & removePointer() const
virtual std::size_t getAlignment() const noexcept=0
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
UInt64 TypeIdentityHash
A type that represents a Type hash value.
Definition Type.hpp:29
TypedID< internal::TypeTag, UInt64 > TypeID
Definition Forward.hpp:45
consteval TypeIdentityHash getIdentityHash() noexcept
Gets the a static constexpr hash of the type.
Definition TypeInfo.hpp:25
constexpr UInt64 staticHash64(BasicStringView< T > string, const UInt64 value=0xcbf29ce484222325) noexcept
Definition Hash.hpp:82
TypeAttribute
Definition TypeInfo.hpp:29
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
A meta interface that can be implemented by types that support erasion.
Definition TypeInfo.hpp:252
virtual Box erase(const Box &container, const Box &where) const =0
A meta interface that can be implemented by types that support hashing.
Definition TypeInfo.hpp:157
virtual size_t hash(const Box &object) const =0
Computes the hash of the object by using CeresEngine::hash.
A meta interface that can be implemented by types that support insertion.
Definition TypeInfo.hpp:242
virtual Box insert(const Box &container, const Box &where, Box &&value) const =0