ECSTASY
All in the name
Loading...
Searching...
No Matches
TypeRegistry.cpp
Go to the documentation of this file.
1
11
12#include "TypeRegistry.hpp"
13
14namespace ecstasy::rtti
15{
16
18 {
19 static TypeRegistry instance;
20
21 return instance;
22 }
23
25 bool TypeRegistry::has(std::size_t name_hash) const noexcept
26 {
27 return _types.contains(name_hash);
28 }
30
32 {
33 auto result = std::find_if(_types.begin(), _types.end(), p);
34
35 if (result == _types.end())
36 return std::nullopt;
37 return std::ref(*result->second);
38 }
39
41 {
42 auto result = findIf(p);
43
44 if (result.has_value())
45 return result.value();
46 throw std::out_of_range("Type not found.");
47 }
48
50 {
51 if (_types.contains(name_hash))
52 return std::ref(*(_types.at(name_hash)));
53 return std::nullopt;
54 }
55
57 {
58 return *(_types.at(name_hash));
59 }
60
61} // namespace ecstasy::rtti
Type erased interface for cross-platform type information.
Definition AType.hpp:46
Type registry class to store types in cross-platform way.
static TypeRegistry & getInstance() noexcept
Get the Instance object.
std::unordered_map< std::size_t, std::unique_ptr< AType > > _types
Map of types indexed by their (cross-platform) hash code.
OptionalATypeReference find() const noexcept
Search for a registered type.
bool has() const noexcept
Check if a type is registered.
AType & getIf(const Predicate &p) const
Get a reference to the AType instance matching the predicate.
OptionalATypeReference findIf(const Predicate &p) const noexcept
Calls std::find_if on the types map using the given predicate.
AType & get() const
Get a reference to the AType instance matching the target.
T find_if(T... args)
Namespace regrouping the cross platform rtti symbols.
Definition AType.cpp:15
T ref(T... args)