1#ifndef ENTT_CORE_TYPE_INFO_HPP
2#define ENTT_CORE_TYPE_INFO_HPP
7#include "../config/config.h"
9#include "hashed_string.hpp"
16struct ENTT_API type_index final {
17 [[nodiscard]]
static id_type next() noexcept {
18 static ENTT_MAYBE_ATOMIC(id_type) value{};
23template<
typename Type>
24[[nodiscard]]
constexpr const char *pretty_function() noexcept {
25#if defined ENTT_PRETTY_FUNCTION
26 return static_cast<const char *
>(ENTT_PRETTY_FUNCTION);
32template<
typename Type>
33[[nodiscard]]
constexpr auto stripped_type_name() noexcept {
34#if defined ENTT_PRETTY_FUNCTION
35 const std::string_view full_name{pretty_function<Type>()};
36 auto first = full_name.find_first_not_of(
' ', full_name.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX) + 1);
37 auto value = full_name.substr(first, full_name.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
40 return std::string_view{};
44template<typename Type, auto = stripped_type_name<Type>().find_first_of(
'.')>
45[[nodiscard]]
constexpr std::string_view type_name(
int)
noexcept {
46 constexpr auto value = stripped_type_name<Type>();
50template<
typename Type>
51[[nodiscard]] std::string_view type_name(
char)
noexcept {
52 static const auto value = stripped_type_name<Type>();
56template<typename Type, auto = stripped_type_name<Type>().find_first_of(
'.')>
57[[nodiscard]]
constexpr id_type type_hash(
int)
noexcept {
58 constexpr auto stripped = stripped_type_name<Type>();
59 constexpr auto value = hashed_string::value(stripped.data(), stripped.size());
63template<
typename Type>
64[[nodiscard]]
id_type type_hash(
char)
noexcept {
65 static const auto value = [](
const auto stripped) {
66 return hashed_string::value(stripped.data(), stripped.size());
67 }(stripped_type_name<Type>());
78template<
typename Type,
typename =
void>
85 static const id_type value = internal::type_index::next();
90 [[nodiscard]]
constexpr operator id_type() const noexcept {
99template<
typename Type,
typename =
void>
105#if defined ENTT_PRETTY_FUNCTION
106 [[nodiscard]]
static constexpr id_type value()
noexcept {
107 return internal::type_hash<Type>(0);
115 [[nodiscard]]
constexpr operator id_type() const noexcept {
124template<
typename Type,
typename =
void>
130 [[nodiscard]]
static constexpr std::string_view
value() noexcept {
131 return internal::type_name<Type>(0);
135 [[nodiscard]]
constexpr operator std::string_view() const noexcept {
146 template<
typename Type>
148 constexpr type_info(std::in_place_type_t<Type>) noexcept
151 alias{type_name<std::remove_const_t<std::remove_reference_t<Type>>>::value()} {}
174 [[nodiscard]]
constexpr std::string_view
name() const noexcept {
181 std::string_view alias;
191 return lhs.hash() == rhs.hash();
201 return !(lhs == rhs);
211 return lhs.index() < rhs.index();
258template<
typename Type>
260 if constexpr(std::is_same_v<Type, std::remove_const_t<std::remove_reference_t<Type>>>) {
261 static const type_info instance{std::in_place_type<Type>};
269template<
typename Type>
std::uint32_t id_type
Alias declaration for type identifiers.
constexpr bool operator<=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator<(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator>=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
const type_info & type_id() noexcept
Returns the type info object associated to a given type.
constexpr bool operator>(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
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 id_type index() const noexcept
Type index.
constexpr std::string_view name() const noexcept
Type name.
constexpr id_type hash() const noexcept
Type hash.
constexpr type_info(std::in_place_type_t< Type >) noexcept
Constructs a type info object for a given type.
static constexpr std::string_view value() noexcept
Returns the name of a given type.