Skip to content

Commit

Permalink
storage:
Browse files Browse the repository at this point in the history
* move storage_type[_t] and storage_for[_t] to fwd.hpp
* no need to include storage.hpp when forward defining views
  • Loading branch information
skypjack committed Nov 30, 2022
1 parent 255b8be commit cd541f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 44 deletions.
44 changes: 38 additions & 6 deletions src/entt/entity/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,47 @@ class basic_sparse_set;
template<typename Type, typename = entity, typename = std::allocator<Type>, typename = void>
class basic_storage;

template<typename Type, typename = entity, typename = std::allocator<Type>, typename = void>
struct storage_type;

template<typename Type, typename = entity, typename = std::allocator<std::remove_const_t<Type>>>
struct storage_for;

template<typename Type>
class sigh_storage_mixin;

/**
* @brief Provides a common way to define storage types.
* @tparam Type Storage value type.
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Type, typename Entity = entity, typename Allocator = std::allocator<Type>, typename = void>
struct storage_type {
/*! @brief Type-to-storage conversion result. */
using type = sigh_storage_mixin<basic_storage<Type, Entity, Allocator>>;
};

/**
* @brief Helper type.
* @tparam Args Arguments to forward.
*/
template<typename... Args>
using storage_type_t = typename storage_type<Args...>::type;

/**
* Type-to-storage conversion utility that preserves constness.
* @tparam Type Storage value type, eventually const.
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Type, typename Entity = entity, typename Allocator = std::allocator<std::remove_const_t<Type>>>
struct storage_for {
/*! @brief Type-to-storage conversion result. */
using type = constness_as_t<storage_type_t<std::remove_const_t<Type>, Entity, Allocator>, Type>;
};

/**
* @brief Helper type.
* @tparam Args Arguments to forward.
*/
template<typename... Args>
using storage_for_t = typename storage_for<Args...>::type;

template<typename Entity = entity, typename = std::allocator<Entity>>
class basic_registry;

Expand Down
38 changes: 0 additions & 38 deletions src/entt/entity/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,44 +898,6 @@ class basic_storage<Type, Entity, Allocator, std::enable_if_t<ignore_as_empty_v<
}
};

/**
* @brief Provides a common way to define storage types.
* @tparam Type Storage value type.
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Type, typename Entity, typename Allocator, typename>
struct storage_type {
/*! @brief Type-to-storage conversion result. */
using type = sigh_storage_mixin<basic_storage<Type, Entity, Allocator>>;
};

/**
* @brief Helper type.
* @tparam Args Arguments to forward.
*/
template<typename... Args>
using storage_type_t = typename storage_type<Args...>::type;

/**
* Type-to-storage conversion utility that preserves constness.
* @tparam Type Storage value type, eventually const.
* @tparam Entity A valid entity type (see entt_traits for more details).
* @tparam Allocator Type of allocator used to manage memory and elements.
*/
template<typename Type, typename Entity, typename Allocator>
struct storage_for {
/*! @brief Type-to-storage conversion result. */
using type = constness_as_t<storage_type_t<std::remove_const_t<Type>, Entity, Allocator>, Type>;
};

/**
* @brief Helper type.
* @tparam Args Arguments to forward.
*/
template<typename... Args>
using storage_for_t = typename storage_for<Args...>::type;

} // namespace entt

#endif

0 comments on commit cd541f3

Please sign in to comment.