@@ -148,6 +148,28 @@ export namespace CppUtils::Container
148148 node2Accessor.operator->()->detachChild(node1.get(), node1NetworkPtr);
149149 }
150150
151+ [[nodiscard]] auto operator[](std::size_t index) const -> std::expected<MeshNodePtr, std::string_view>
152+ {
153+ using namespace std::literals;
154+
155+ if (not m_self)
156+ return std::unexpected{"Invalid MeshNodePtr"sv};
157+ auto sharedLocker = m_self->sharedAccess();
158+ const auto& branches = sharedLocker->value.branches;
159+ if (auto it = branches.find(m_key); it != std::cend(branches))
160+ {
161+ const auto& children = it->second;
162+ if (index < std::size(children))
163+ if (auto sharedChild = children[index].lock())
164+ return MeshNodePtr{sharedChild};
165+ else
166+ return std::unexpected{"Failed to lock weak pointer for branch. Node might have been deleted"sv};
167+ else
168+ return std::unexpected{"Branch index out of bounds"sv};
169+ }
170+ return std::unexpected{"Branch key not found"sv};
171+ }
172+
151173 private:
152174 SharedPtr& m_self;
153175 const Key& m_key;
@@ -202,28 +224,6 @@ export namespace CppUtils::Container
202224 return sharedLocker->value.value;
203225 }
204226
205- [[nodiscard]] auto getNode(const Key& key, std::size_t index = 0) const -> std::expected<MeshNodePtr, std::string_view>
206- {
207- using namespace std::literals;
208-
209- if (not m_node)
210- return std::unexpected{"Invalid MeshNodePtr"sv};
211- auto sharedLocker = m_node->sharedAccess();
212- const auto& branches = sharedLocker->value.branches;
213- if (auto it = branches.find(key); it != std::cend(branches))
214- {
215- const auto& children = it->second;
216- if (index < std::size(children))
217- if (auto sharedChild = children[index].lock())
218- return MeshNodePtr{sharedChild};
219- else
220- return std::unexpected{"Failed to lock weak pointer for branch. Node might have been deleted"sv};
221- else
222- return std::unexpected{"Branch index out of bounds"sv};
223- }
224- return std::unexpected{"Branch key not found"sv};
225- }
226-
227227 [[nodiscard]] auto getNodes(const Key& key) const -> std::expected<std::vector<MeshNodePtr>, std::string_view>
228228 {
229229 using namespace std::literals;
0 commit comments