userdata.h 877 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef ENTT_LIB_META_PLUGIN_STD_USERDATA_H
  2. #define ENTT_LIB_META_PLUGIN_STD_USERDATA_H
  3. #include <type_traits>
  4. #include <entt/core/hashed_string.hpp>
  5. #include <entt/core/type_info.hpp>
  6. #include <entt/meta/context.hpp>
  7. #include <entt/meta/meta.hpp>
  8. #include "../../../common/boxed_type.h"
  9. #include "../../../common/value_type.h"
  10. #define ASSIGN_TYPE_ID(clazz) \
  11. template<> \
  12. struct entt::type_hash<clazz> { \
  13. static ENTT_CONSTEVAL entt::id_type value() noexcept { \
  14. return entt::basic_hashed_string<std::remove_const_t<std::remove_pointer_t<std::decay_t<decltype(#clazz)>>>>{#clazz}; \
  15. } \
  16. }
  17. struct userdata {
  18. entt::locator<entt::meta_ctx>::node_type ctx{};
  19. entt::meta_any any{};
  20. };
  21. ASSIGN_TYPE_ID(std::size_t);
  22. ASSIGN_TYPE_ID(test::boxed_int);
  23. ASSIGN_TYPE_ID(test::empty);
  24. ASSIGN_TYPE_ID(double);
  25. ASSIGN_TYPE_ID(int);
  26. #endif