EnTT 4.0.0
Loading...
Searching...
No Matches
resolve.hpp
1#ifndef ENTT_META_RESOLVE_HPP
2#define ENTT_META_RESOLVE_HPP
3
4#include "../core/type_info.hpp"
5#include "../locator/locator.hpp"
6#include "../stl/type_traits.hpp"
7#include "context.hpp"
8#include "meta.hpp"
9#include "node.hpp"
10#include "range.hpp"
11
12namespace entt {
13
20template<typename Type>
21[[nodiscard]] meta_type resolve(const meta_ctx &ctx) noexcept {
22 const auto &context = internal::meta_context::from(ctx);
23 return {ctx, internal::resolve<stl::remove_cvref_t<Type>>(context)};
24}
25
31template<typename Type>
32[[nodiscard]] meta_type resolve() noexcept {
34}
35
42 const auto &context = internal::meta_context::from(ctx);
43 return {{ctx, context.bucket.cbegin()}, {ctx, context.bucket.cend()}};
44}
45
53
60[[nodiscard]] inline meta_type resolve(const meta_ctx &ctx, const id_type alias) noexcept {
61 const auto &context = internal::meta_context::from(ctx);
62
63 // fast lookup for unsearchable and overloaded types
64 if(const auto it = context.bucket.find(alias); it != context.bucket.end()) {
65 return meta_type{ctx, *it->second};
66 }
67
68 for(auto &&curr: context.bucket) {
69 if(curr.second->alias == alias) {
70 return meta_type{ctx, *curr.second};
71 }
72 }
73
74 return meta_type{};
75}
76
82[[nodiscard]] inline meta_type resolve(const id_type alias) noexcept {
83 return resolve(locator<meta_ctx>::value_or(), alias);
84}
85
92[[nodiscard]] inline meta_type resolve(const meta_ctx &ctx, const type_info &info) noexcept {
93 const auto &context = internal::meta_context::from(ctx);
94 const auto it = context.bucket.find(info.hash());
95 return (it == context.bucket.cend()) ? meta_type{} : meta_type{ctx, *it->second};
96}
97
103[[nodiscard]] inline meta_type resolve(const type_info &info) noexcept {
104 return resolve(locator<meta_ctx>::value_or(), info);
105}
106
107} // namespace entt
108
109#endif
static Service & value_or(Args &&...args)
Returns a service if available or sets it from a fallback type.
Definition locator.hpp:90
Opaque wrapper for types.
Definition meta.hpp:1026
EnTT default namespace.
Definition dense_map.hpp:25
iterable_adaptor< internal::meta_range_iterator< Type, It > > meta_range
Iterable range to use to iterate all types of meta objects.
Definition range.hpp:115
meta_type resolve() noexcept
Returns the meta type associated with a given type.
Definition resolve.hpp:32
stl::uint32_t id_type
Alias declaration for type identifiers.
Definition fwd.hpp:29
Opaque meta context type.
Definition context.hpp:30
Implementation specific information about a type.