fennec
Loading...
Searching...
No Matches
type.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31#ifndef FENNEC_RTTI_TYPE_H
32#define FENNEC_RTTI_TYPE_H
33
34#include <fennec/lang/types.h>
36
37namespace fennec
38{
39
40struct type {
41
44 const string& name() const {
45 static const string nullname = string("[none]");
46 return _data ? _data->name : nullname;
47 }
48
51 uint64_t id() const {
52 return _data ? _data->uuid : 0;
53 }
54
57 dynarray<type> supertypes() const {
58 return _data ? _data->supers : dynarray<type_data*>{};
59 }
60
63 dynarray<type> subtypes() const {
64 return _data ? _data->subs : dynarray<type_data*>{};
65 }
66
69 bool is_complete() const {
70 return _data ? _data->properties.test(type_data::property_complete) : false;
71 }
72
75 bool is_iterable() const {
76 return _data ? _data->properties.test(type_data::property_iterable) : false;
77 }
78
81 bool is_indexable() const {
82 return _data ? _data->properties.test(type_data::property_indexable) : false;
83 }
84
87 bool is_mappable() const {
88 return _data ? _data->properties.test(type_data::property_mappable) : false;
89 }
90
93 type key_type() const {
94 return _data ? _data->key_type : nullptr;
95 }
96
101 bool operator==(const type& c) const {
102 return _data == c._data;
103 }
104
109 template<typename TypeT>
110 static type get() { return type(static_cast<TypeT*>(nullptr)); }
111
117 template<typename TypeT>
118 static type get_from_instance(TypeT* t) { return type(t); }
119
125 template<typename TypeT>
126 static type get_from_instance(const TypeT*) { return type(static_cast<TypeT*>(nullptr)); }
127
128private:
129 const type_data* _data;
130
131 template<typename TypeT>
132 type(TypeT*) : _data(type_storage::get_data<TypeT>()) {
133 }
134
135public:
136 type(type_data* d) : _data(d) { }
137
138 type(const type& t) = default;
139 type(type&& t) noexcept = default;
140
141 type& operator=(const type&) = default;
142 type& operator=(type&&) noexcept = default;
143};
144
145
146}
147
148#endif // FENNEC_RTTI_TYPE_H
Types
::uint64_t uint64_t
Unsigned 64-bit integer.
Definition types.h:275