Browse Source

meta: review meta containers' begin/end functions

Michele Caini 2 years ago
parent
commit
1a6565d5f9
2 changed files with 30 additions and 32 deletions
  1. 20 20
      src/entt/meta/container.hpp
  2. 10 12
      src/entt/meta/meta.hpp

+ 20 - 20
src/entt/meta/container.hpp

@@ -133,24 +133,24 @@ struct basic_meta_sequence_container_traits {
      * @brief Returns a possibly const iterator to the beginning.
      * @brief Returns a possibly const iterator to the beginning.
      * @param area The context to pass to the newly created iterator.
      * @param area The context to pass to the newly created iterator.
      * @param container Opaque pointer to a container of the given type.
      * @param container Opaque pointer to a container of the given type.
-     * @param as_const True for const-only containers, false otherwise.
+     * @param as_const Const opaque pointer fallback.
      * @return An iterator to the first element of the container.
      * @return An iterator to the first element of the container.
      */
      */
-    static iterator begin(const meta_ctx &area, const void *container, const bool as_const) {
-        return as_const ? iterator{area, static_cast<const Type *>(container)->begin()}
-                        : iterator{area, static_cast<Type *>(const_cast<void *>(container))->begin()};
+    static iterator begin(const meta_ctx &area, void *container, const void *as_const) {
+        return container ? iterator{area, static_cast<Type *>(container)->begin()}
+                         : iterator{area, static_cast<const Type *>(as_const)->begin()};
     }
     }
 
 
     /**
     /**
      * @brief Returns a possibly const iterator to the end.
      * @brief Returns a possibly const iterator to the end.
      * @param area The context to pass to the newly created iterator.
      * @param area The context to pass to the newly created iterator.
      * @param container Opaque pointer to a container of the given type.
      * @param container Opaque pointer to a container of the given type.
-     * @param as_const True for const-only containers, false otherwise.
+     * @param as_const Const opaque pointer fallback.
      * @return An iterator that is past the last element of the container.
      * @return An iterator that is past the last element of the container.
      */
      */
-    static iterator end(const meta_ctx &area, const void *container, const bool as_const) {
-        return as_const ? iterator{area, static_cast<const Type *>(container)->end()}
-                        : iterator{area, static_cast<Type *>(const_cast<void *>(container))->end()};
+    static iterator end(const meta_ctx &area, void *container, const void *as_const) {
+        return container ? iterator{area, static_cast<Type *>(container)->end()}
+                         : iterator{area, static_cast<const Type *>(as_const)->end()};
     }
     }
 
 
     /**
     /**
@@ -247,24 +247,24 @@ struct basic_meta_associative_container_traits {
      * @brief Returns a possibly const iterator to the beginning.
      * @brief Returns a possibly const iterator to the beginning.
      * @param area The context to pass to the newly created iterator.
      * @param area The context to pass to the newly created iterator.
      * @param container Opaque pointer to a container of the given type.
      * @param container Opaque pointer to a container of the given type.
-     * @param as_const True for const-only containers, false otherwise.
+     * @param as_const Const opaque pointer fallback.
      * @return An iterator to the first element of the container.
      * @return An iterator to the first element of the container.
      */
      */
-    static iterator begin(const meta_ctx &area, const void *container, const bool as_const) {
-        return as_const ? iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(container)->begin()}
-                        : iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(const_cast<void *>(container))->begin()};
+    static iterator begin(const meta_ctx &area, void *container, const void *as_const) {
+        return container ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->begin()}
+                         : iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->begin()};
     }
     }
 
 
     /**
     /**
      * @brief Returns a possibly const iterator to the end.
      * @brief Returns a possibly const iterator to the end.
      * @param area The context to pass to the newly created iterator.
      * @param area The context to pass to the newly created iterator.
      * @param container Opaque pointer to a container of the given type.
      * @param container Opaque pointer to a container of the given type.
-     * @param as_const True for const-only containers, false otherwise.
+     * @param as_const Const opaque pointer fallback.
      * @return An iterator that is past the last element of the container.
      * @return An iterator that is past the last element of the container.
      */
      */
-    static iterator end(const meta_ctx &area, const void *container, const bool as_const) {
-        return as_const ? iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(container)->end()}
-                        : iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(const_cast<void *>(container))->end()};
+    static iterator end(const meta_ctx &area, void *container, const void *as_const) {
+        return container ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->end()}
+                         : iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->end()};
     }
     }
 
 
     /**
     /**
@@ -296,13 +296,13 @@ struct basic_meta_associative_container_traits {
      * @brief Finds an element with a given key.
      * @brief Finds an element with a given key.
      * @param area The context to pass to the newly created iterator.
      * @param area The context to pass to the newly created iterator.
      * @param container Opaque pointer to a container of the given type.
      * @param container Opaque pointer to a container of the given type.
-     * @param as_const True for const-only containers, false otherwise.
+     * @param as_const Const opaque pointer fallback.
      * @param key Opaque key value of an element to search for.
      * @param key Opaque key value of an element to search for.
      * @return An iterator to the element with the given key, if any.
      * @return An iterator to the element with the given key, if any.
      */
      */
-    static iterator find(const meta_ctx &area, const void *container, const bool as_const, const void *key) {
-        return as_const ? iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(container)->find(*static_cast<const typename Type::key_type *>(key))}
-                        : iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(const_cast<void *>(container))->find(*static_cast<const typename Type::key_type *>(key))};
+    static iterator find(const meta_ctx &area, void *container, const void *as_const, const void *key) {
+        return container ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->find(*static_cast<const typename Type::key_type *>(key))}
+                         : iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->find(*static_cast<const typename Type::key_type *>(key))};
     }
     }
 };
 };
 
 

+ 10 - 12
src/entt/meta/meta.hpp

@@ -91,8 +91,8 @@ private:
     bool (*clear_fn)(void *){};
     bool (*clear_fn)(void *){};
     bool (*reserve_fn)(void *, const size_type){};
     bool (*reserve_fn)(void *, const size_type){};
     bool (*resize_fn)(void *, const size_type){};
     bool (*resize_fn)(void *, const size_type){};
-    iterator (*begin_fn)(const meta_ctx &, const void *, const bool){};
-    iterator (*end_fn)(const meta_ctx &, const void *, const bool){};
+    iterator (*begin_fn)(const meta_ctx &, void *, const void *){};
+    iterator (*end_fn)(const meta_ctx &, void *, const void *){};
     iterator (*insert_fn)(const meta_ctx &, void *, const void *, const void *, const iterator &){};
     iterator (*insert_fn)(const meta_ctx &, void *, const void *, const void *, const iterator &){};
     iterator (*erase_fn)(const meta_ctx &, void *, const iterator &){};
     iterator (*erase_fn)(const meta_ctx &, void *, const iterator &){};
     const void *cdata{};
     const void *cdata{};
@@ -171,11 +171,11 @@ private:
     size_type (*size_fn)(const void *){};
     size_type (*size_fn)(const void *){};
     bool (*clear_fn)(void *){};
     bool (*clear_fn)(void *){};
     bool (*reserve_fn)(void *, const size_type){};
     bool (*reserve_fn)(void *, const size_type){};
-    iterator (*begin_fn)(const meta_ctx &, const void *, const bool){};
-    iterator (*end_fn)(const meta_ctx &, const void *, const bool){};
+    iterator (*begin_fn)(const meta_ctx &, void *, const void *){};
+    iterator (*end_fn)(const meta_ctx &, void *, const void *){};
     bool (*insert_fn)(void *, const void *, const void *){};
     bool (*insert_fn)(void *, const void *, const void *){};
     size_type (*erase_fn)(void *, const void *){};
     size_type (*erase_fn)(void *, const void *){};
-    iterator (*find_fn)(const meta_ctx &, const void *, const bool, const void *){};
+    iterator (*find_fn)(const meta_ctx &, void *, const void *, const void *){};
     const void *cdata{};
     const void *cdata{};
     void *data{};
     void *data{};
 };
 };
@@ -1848,7 +1848,7 @@ inline bool meta_sequence_container::reserve(const size_type sz) {
  * @return An iterator to the first element of the container.
  * @return An iterator to the first element of the container.
  */
  */
 [[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::begin() {
 [[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::begin() {
-    return begin_fn(*ctx, cdata, data == nullptr);
+    return begin_fn(*ctx, data, cdata);
 }
 }
 
 
 /**
 /**
@@ -1856,7 +1856,7 @@ inline bool meta_sequence_container::reserve(const size_type sz) {
  * @return An iterator that is past the last element of the container.
  * @return An iterator that is past the last element of the container.
  */
  */
 [[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::end() {
 [[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::end() {
-    return end_fn(*ctx, cdata, data == nullptr);
+    return end_fn(*ctx, data, cdata);
 }
 }
 
 
 /**
 /**
@@ -1950,12 +1950,12 @@ inline bool meta_associative_container::reserve(const size_type sz) {
 
 
 /*! @copydoc meta_sequence_container::begin */
 /*! @copydoc meta_sequence_container::begin */
 [[nodiscard]] inline meta_associative_container::iterator meta_associative_container::begin() {
 [[nodiscard]] inline meta_associative_container::iterator meta_associative_container::begin() {
-    return begin_fn(*ctx, cdata, data == nullptr);
+    return begin_fn(*ctx, data, cdata);
 }
 }
 
 
 /*! @copydoc meta_sequence_container::end */
 /*! @copydoc meta_sequence_container::end */
 [[nodiscard]] inline meta_associative_container::iterator meta_associative_container::end() {
 [[nodiscard]] inline meta_associative_container::iterator meta_associative_container::end() {
-    return end_fn(*ctx, cdata, data == nullptr);
+    return end_fn(*ctx, data, cdata);
 }
 }
 
 
 /**
 /**
@@ -1985,9 +1985,7 @@ inline meta_associative_container::size_type meta_associative_container::erase(m
  * @return An iterator to the element with the given key, if any.
  * @return An iterator to the element with the given key, if any.
  */
  */
 [[nodiscard]] inline meta_associative_container::iterator meta_associative_container::find(meta_any key) {
 [[nodiscard]] inline meta_associative_container::iterator meta_associative_container::find(meta_any key) {
-    return key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))})
-               ? find_fn(*ctx, cdata, data == nullptr, std::as_const(key).data())
-               : iterator{*ctx};
+    return key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))}) ? find_fn(*ctx, data, cdata, std::as_const(key).data()) : iterator{*ctx};
 }
 }
 
 
 /**
 /**