[Bf-blender-cvs] [805e2ccb07e] soc-2021-adaptive-cloth: bli: generational_arena: get(), get_no_gen(), get_no_gen_index()
ishbosamiya
noreply at git.blender.org
Fri Jun 18 11:22:44 CEST 2021
Commit: 805e2ccb07ec19cb62d98dc88cfb5532a3356bb2
Author: ishbosamiya
Date: Tue Jun 15 22:18:33 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB805e2ccb07ec19cb62d98dc88cfb5532a3356bb2
bli: generational_arena: get(), get_no_gen(), get_no_gen_index()
===================================================================
M source/blender/blenlib/BLI_generational_arena.hh
===================================================================
diff --git a/source/blender/blenlib/BLI_generational_arena.hh b/source/blender/blenlib/BLI_generational_arena.hh
index 30a147ba157..8cec19ca76e 100644
--- a/source/blender/blenlib/BLI_generational_arena.hh
+++ b/source/blender/blenlib/BLI_generational_arena.hh
@@ -52,6 +52,7 @@
*/
/* TODO(ish): need to complete documentation */
+#include <functional>
#include <limits>
#include <optional>
#include <tuple>
@@ -235,6 +236,70 @@ class Arena {
}
}
+ std::optional<std::reference_wrapper<const T>> get(Index index) const
+ {
+ /* if index exceeds size of the container, return std::nullopt */
+ if (index.index >= this->data.size()) {
+ return std::nullopt;
+ }
+
+ if (index.generation != this->data[index.index]) {
+ return std::nullopt;
+ }
+
+ return std::cref(this->data[index.index]);
+ }
+
+ std::optional<std::reference_wrapper<T>> get(Index index)
+ {
+ /* if index exceeds size of the container, return std::nullopt */
+ if (index.index >= this->data.size()) {
+ return std::nullopt;
+ }
+
+ if (index.generation != this->data[index.index]) {
+ return std::nullopt;
+ }
+
+ return std::ref(this->data[index.index]);
+ }
+
+ std::optional<std::reference_wrapper<const T>> get_no_gen(usize index) const
+ {
+ /* if index exceeds size of the container, return std::nullopt */
+ if (index >= this->data.size()) {
+ return std::nullopt;
+ }
+
+ return std::cref(this->data[index]);
+ }
+
+ std::optional<std::reference_wrapper<T>> get_no_gen(usize index)
+ {
+ /* if index exceeds size of the container, return std::nullopt */
+ if (index >= this->data.size()) {
+ return std::nullopt;
+ }
+
+ return std::ref(this->data[index]);
+ }
+
+ std::optional<Index> get_no_gen_index(usize index) const
+ {
+ /* if index exceeds size of the container, return std::nullopt */
+ if (index >= this->data.size()) {
+ return std::nullopt;
+ }
+
+ std::optional<Index> res;
+ std::visit(extra::overloaded{
+ [&res](EntryNoExist &entry) { res = std::nullopt; },
+ [&res, index](EntryExist &entry) { res = Index(index, entry.generation); }},
+ this->data[index]);
+
+ return res;
+ }
+
protected:
/* all protected static methods */
/* all protected non-static methods */
More information about the Bf-blender-cvs
mailing list