1#ifndef ENTT_CORE_TYPE_INFO_HPP
2#define ENTT_CORE_TYPE_INFO_HPP
5#include "../config/config.h"
6#include "../stl/string_view.hpp"
7#include "../stl/type_traits.hpp"
8#include "../stl/utility.hpp"
10#include "hashed_string.hpp"
17struct ENTT_API type_index final {
18 [[nodiscard]]
static id_type next() noexcept {
19 static ENTT_MAYBE_ATOMIC(id_type) value{};
24template<
typename Type>
25[[nodiscard]]
constexpr const char *pretty_function() noexcept {
26#if defined ENTT_PRETTY_FUNCTION
27 return static_cast<const char *
>(ENTT_PRETTY_FUNCTION);
33template<
typename Type>
34[[nodiscard]]
constexpr auto stripped_type_name() noexcept {
35#if defined ENTT_PRETTY_FUNCTION
36 const stl::string_view full_name{pretty_function<Type>()};
37 auto first = full_name.find_first_not_of(
' ', full_name.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX) + 1);
38 auto value = full_name.substr(first, full_name.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
41 return stl::string_view{};
45template<typename Type, auto = stripped_type_name<Type>().find_first_of(
'.')>
46[[nodiscard]] ENTT_CONSTEVAL stl::string_view type_name(
int)
noexcept {
47 constexpr auto value = stripped_type_name<Type>();
51template<
typename Type>
52[[nodiscard]] stl::string_view type_name(
char)
noexcept {
53 static const auto value = stripped_type_name<Type>();
57template<typename Type, auto = stripped_type_name<Type>().find_first_of(
'.')>
58[[nodiscard]] ENTT_CONSTEVAL
id_type type_hash(
int)
noexcept {
59 constexpr auto stripped = stripped_type_name<Type>();
60 constexpr auto value = hashed_string::value(stripped.data(), stripped.size());
64template<
typename Type>
65[[nodiscard]]
id_type type_hash(
char)
noexcept {
66 static const auto value = [](
const auto stripped) {
67 return hashed_string::value(stripped.data(), stripped.size());
68 }(stripped_type_name<Type>());
79template<
typename Type>
86 static const id_type value = internal::type_index::next();
91 [[nodiscard]]
constexpr operator id_type() const noexcept {
100template<
typename Type>
106#if defined ENTT_PRETTY_FUNCTION
107 [[nodiscard]]
static constexpr id_type value()
noexcept {
108 return internal::type_hash<Type>(0);
116 [[nodiscard]]
constexpr operator id_type() const noexcept {
125template<
typename Type>
131 [[nodiscard]]
static constexpr stl::string_view
value() noexcept {
132 return internal::type_name<Type>(0);
136 [[nodiscard]]
constexpr operator stl::string_view() const noexcept {
147 template<
typename Type>
149 constexpr type_info(stl::in_place_type_t<Type>) noexcept
152 alias{type_name<stl::remove_cvref_t<Type>>::value()} {}
175 [[nodiscard]]
constexpr stl::string_view
name() const noexcept {
185 return identifier == other.identifier;
194 return seq <=> other.seq;
200 stl::string_view alias;
214template<
typename Type>
216 if constexpr(stl::is_same_v<Type, stl::remove_cvref_t<Type>>) {
217 static const type_info instance{stl::in_place_type<Type>};
225template<
typename Type>
const type_info & type_id() noexcept
Returns the type info object associated to a given type.
stl::uint32_t id_type
Alias declaration for type identifiers.
static constexpr id_type value() noexcept
Returns the numeric representation of a given type.
Type sequential identifier.
static id_type value() noexcept
Returns the sequential identifier of a given type.
Implementation specific information about a type.
constexpr auto operator<=>(const type_info &other) const noexcept
Lexicographically compares two type info objects.
constexpr type_info(stl::in_place_type_t< Type >) noexcept
Constructs a type info object for a given type.
constexpr stl::string_view name() const noexcept
Type name.
constexpr id_type index() const noexcept
Type index.
constexpr id_type hash() const noexcept
Type hash.
constexpr bool operator==(const type_info &other) const noexcept
Compares two type info objects.
static constexpr stl::string_view value() noexcept
Returns the name of a given type.