registry:: non-template storage(id) returns an iterator rather than a naked pointer

This commit is contained in:
Michele Caini
2022-01-19 12:15:22 +01:00
parent 2ad3e0ed4c
commit 2196db562e
3 changed files with 26 additions and 25 deletions

View File

@@ -336,6 +336,26 @@ public:
return iterable_adaptor{internal::storage_proxy_iterator{pools.cbegin()}, internal::storage_proxy_iterator{pools.cend()}};
}
/**
* @brief Finds the storage associated with a given name, if any.
* @param id Name used to map the storage within the registry.
* @return An iterator to the given storage if it's found, past the end
* iterator otherwise.
*/
[[nodiscard]] auto storage(const id_type id) {
return internal::storage_proxy_iterator{pools.find(id)};
}
/**
* @brief Finds the storage associated with a given name, if any.
* @param id Name used to map the storage within the registry.
* @return An iterator to the given storage if it's found, past the end
* iterator otherwise.
*/
[[nodiscard]] auto storage(const id_type id) const {
return internal::storage_proxy_iterator{pools.find(id)};
}
/**
* @brief Returns the storage for a given component type.
* @tparam Component Type of component of which to return the storage.
@@ -363,25 +383,6 @@ public:
return assure<Component>(id);
}
/**
* @brief Returns the storage associated with a given name, if any.
* @param id Name used to map the storage within the registry.
* @return The requested storage if it exists, a null pointer otherwise.
*/
[[nodiscard]] base_type *storage(const id_type id) {
return const_cast<base_type *>(std::as_const(*this).storage(id));
}
/**
* @brief Returns the storage associated with a given name, if any.
* @param id Name used to map the storage within the registry.
* @return The requested storage if it exists, a null pointer otherwise.
*/
[[nodiscard]] const base_type *storage(const id_type id) const {
const auto it = pools.find(id);
return it == pools.end() ? nullptr : it->second.get();
}
/**
* @brief Returns the number of entities created so far.
* @return Number of entities created so far.