EnTT: src/entt/meta/resolve.hpp Source File

EnTT 3.15.0

Loading...
Searching...
No Matches
resolve.hpp
1#ifndef ENTT_META_RESOLVE_HPP
2#define ENTT_META_RESOLVE_HPP
3
4#include <type_traits>
5#include "../core/type_info.hpp"
6#include "../locator/locator.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 auto &&context = internal::meta_context::from(ctx);
23 return {ctx, internal::resolve<std::remove_cv_t<std::remove_reference_t<Type>>>(context)};
24}
25
31template<typename Type>
32[[nodiscard]] meta_type resolve() noexcept {
33 return resolve<Type>(locator<meta_ctx>::value_or());
34}
35
41[[nodiscard]] inline meta_range<meta_type, typename decltype(internal::meta_context::value)::const_iterator> resolve(const meta_ctx &ctx) noexcept {
42 auto &&context = internal::meta_context::from(ctx);
43 return {{ctx, context.value.cbegin()}, {ctx, context.value.cend()}};
44}
45
50[[nodiscard]] inline meta_range<meta_type, typename decltype(internal::meta_context::value)::const_iterator> resolve() noexcept {
51 return resolve(locator<meta_ctx>::value_or());
52}
53
60[[nodiscard]] inline meta_type resolve(const meta_ctx &ctx, const id_type id) noexcept {
61 for(auto &&curr: resolve(ctx)) {
62 if(curr.second.id() == id) {
63 return curr.second;
64 }
65 }
66
67 return meta_type{};
68}
69
75[[nodiscard]] inline meta_type resolve(const id_type id) noexcept {
76 return resolve(locator<meta_ctx>::value_or(), id);
77}
78
85[[nodiscard]] inline meta_type resolve(const meta_ctx &ctx, const type_info &info) noexcept {
86 auto &&context = internal::meta_context::from(ctx);
87 const auto *elem = internal::try_resolve(context, info);
88 return (elem != nullptr) ? meta_type{ctx, *elem} : meta_type{};
89}
90
96[[nodiscard]] inline meta_type resolve(const type_info &info) noexcept {
97 return resolve(locator<meta_ctx>::value_or(), info);
98}
99
100} // namespace entt
101
102#endif
entt::locator::value_or
static Service & value_or(Args &&...args)
Returns a service if available or sets it from a fallback type.
Definition locator.hpp:88
entt::meta_ctx
Opaque meta context type.
Definition context.hpp:34
entt::meta_type
Opaque wrapper for types.
Definition meta.hpp:1088
entt
EnTT default namespace.
Definition dense_map.hpp:22
entt::id_type
std::uint32_t id_type
Alias declaration for type identifiers.
Definition fwd.hpp:29
entt::meta_range
iterable_adaptor< internal::meta_range_iterator< Type, It > > meta_range
Iterable range to use to iterate all types of meta objects.
Definition range.hpp:147
entt::resolve
meta_type resolve() noexcept
Returns the meta type associated with a given type.
Definition resolve.hpp:32
entt::type_info
Implementation specific information about a type.
Definition type_info.hpp:133