1#ifndef ENTT_CORE_TYPE_INFO_HPP
2#define ENTT_CORE_TYPE_INFO_HPP
7#include "../config/config.h"
8#include "../core/attribute.h"
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 auto stripped_type_name() noexcept {
26#if defined ENTT_PRETTY_FUNCTION
27 std::string_view pretty_function{
static_cast<const char *
>(ENTT_PRETTY_FUNCTION)};
28 auto first = pretty_function.find_first_not_of(
' ', pretty_function.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX) + 1);
29 auto value = pretty_function.substr(first, pretty_function.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
32 return std::string_view{
""};
36template<typename Type, auto = stripped_type_name<Type>().find_first_of(
'.')>
37[[nodiscard]]
constexpr std::string_view type_name(
int)
noexcept {
38 constexpr auto value = stripped_type_name<Type>();
42template<
typename Type>
43[[nodiscard]] std::string_view type_name(
char)
noexcept {
44 static const auto value = stripped_type_name<Type>();
48template<typename Type, auto = stripped_type_name<Type>().find_first_of(
'.')>
49[[nodiscard]]
constexpr id_type type_hash(
int)
noexcept {
50 constexpr auto stripped = stripped_type_name<Type>();
51 constexpr auto value = hashed_string::value(stripped.data(), stripped.size());
55template<
typename Type>
56[[nodiscard]]
id_type type_hash(
char)
noexcept {
57 static const auto value = [](
const auto stripped) {
58 return hashed_string::value(stripped.data(), stripped.size());
59 }(stripped_type_name<Type>());
70template<
typename Type,
typename =
void>
77 static const id_type value = internal::type_index::next();
82 [[nodiscard]]
constexpr operator id_type() const noexcept {
91template<
typename Type,
typename =
void>
97#if defined ENTT_PRETTY_FUNCTION
99 return internal::type_hash<Type>(0);
116template<
typename Type,
typename =
void>
122 [[nodiscard]]
static constexpr std::string_view
value() noexcept {
123 return internal::type_name<Type>(0);
127 [[nodiscard]]
constexpr operator std::string_view() const noexcept {
138 template<
typename Type>
140 constexpr type_info(std::in_place_type_t<Type>) noexcept
143 alias{type_name<std::remove_cv_t<std::remove_reference_t<Type>>>::value()} {}
166 [[nodiscard]]
constexpr std::string_view
name() const noexcept {
173 std::string_view alias;
183 return lhs.hash() ==
rhs.hash();
203 return lhs.index() <
rhs.index();
250template<
typename Type>
252 if constexpr(std::is_same_v<Type, std::remove_cv_t<std::remove_reference_t<Type>>>) {
253 static type_info instance{std::in_place_type<Type>};
261template<
typename Type>
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
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.