Browse Source

view: added use<T> to set explicitly the type that should drive all iterations in a multi type view

Michele Caini 5 years ago
parent
commit
52fa690764
2 changed files with 15 additions and 7 deletions
  1. 2 3
      TODO
  2. 13 4
      src/entt/entity/view.hpp

+ 2 - 3
TODO

@@ -17,11 +17,10 @@
   - ...
 
 WIP:
-* remove extended registry::remove, rename it to (basic) erase and document the handle way for extended operations
-* make view pack work also with groups
+* document the handle way for extended operations
+* make view pack work also with groups, add multi-type iterator (not only input iterators)
 * add exclude-only views to combine with packs
 * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views
-* split basic_view and view_t like sfinae-friendly class
 * HP: write documentation for custom storages and views!!
 * view pack: plain function as an alias for operator|, reverse iterators, rbegin and rend
 * pagination doesn't work nicely across boundaries probably, give it a look. RO operations are fine, adding components maybe not.

+ 13 - 4
src/entt/entity/view.hpp

@@ -318,6 +318,15 @@ public:
     /*! @brief Reverse iterator type. */
     using reverse_iterator = view_iterator<typename basic_sparse_set<entity_type>::reverse_iterator>;
 
+    /**
+     * @brief Forces the type to use to drive iterations.
+     * @tparam Comp Type of component to use to drive the iteration.
+     */
+    template<typename Comp>
+    void use() const ENTT_NOEXCEPT {
+        view = std::get<pool_type<Comp> *>(pools);
+    }
+
     /**
      * @brief Estimates the number of entities iterated by the view.
      * @return Estimated number of entities iterated by the view.
@@ -493,13 +502,13 @@ public:
      *
      * @sa each
      *
-     * @tparam Comp Type of component to use to enforce the iteration order.
+     * @tparam Comp Type of component to use to drive the iteration.
      * @tparam Func Type of the function object to invoke.
      * @param func A valid function object.
      */
     template<typename Comp, typename Func>
     void each(Func func) const {
-        view = std::get<pool_type<Comp> *>(pools);
+        use<Comp>();
         traverse<Comp>(std::move(func), return_type{});
     }
 
@@ -531,12 +540,12 @@ public:
      *
      * @sa each
      *
-     * @tparam Comp Type of component to use to enforce the iteration order.
+     * @tparam Comp Type of component to use to drive the iteration.
      * @return An iterable object to use to _visit_ the view.
      */
     template<typename Comp>
     [[nodiscard]] iterable_view each() const ENTT_NOEXCEPT {
-        view = std::get<pool_type<Comp> *>(pools);
+        use<Comp>();
         return iterable_view{*this};
     }