mixin.hpp 970 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef ENTT_COMMON_MIXIN_HPP
  2. #define ENTT_COMMON_MIXIN_HPP
  3. #include <entt/core/any.hpp>
  4. #include <entt/entity/fwd.hpp>
  5. namespace test {
  6. struct assure_loop {};
  7. template<typename Type>
  8. class assure_loop_mixin: public Type {
  9. using underlying_type = Type;
  10. using registry_type = entt::basic_registry<typename underlying_type::entity_type, typename underlying_type::base_type::allocator_type>;
  11. void bind_any(entt::any value) noexcept override {
  12. if(auto *owner = entt::any_cast<registry_type>(&value); owner) {
  13. owner->template storage<int>();
  14. }
  15. }
  16. public:
  17. using allocator_type = typename underlying_type::allocator_type;
  18. using entity_type = typename underlying_type::entity_type;
  19. using Type::Type;
  20. };
  21. } // namespace test
  22. template<entt::entity_like Entity>
  23. struct entt::storage_type<test::assure_loop, Entity> {
  24. using type = test::assure_loop_mixin<entt::basic_storage<test::assure_loop, Entity>>;
  25. };
  26. #endif