File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ class Container : virtual public Attributable
114114 template <typename >
115115 friend class internal ::EraseStaleEntries;
116116 friend class StatefulIterator ;
117+ friend class StatefulSnapshotsContainer ;
117118
118119protected:
119120 using ContainerData = internal::ContainerData<T, T_key, T_container>;
Original file line number Diff line number Diff line change @@ -395,6 +395,11 @@ class StatefulIterator
395395 -> std::optional<value_type const *>;
396396 auto peekCurrentlyOpenIteration () -> std::optional<value_type *>;
397397
398+ // Only checks the index state from the Iterator, peekCurrentlyOpenIteration
399+ // actually retrieves the Iteration and checks if it is open
400+ [[nodiscard]] auto currentIterationIndex () const
401+ -> std::optional<iteration_index_t>;
402+
398403 auto reparse_possibly_deleted_iteration (iteration_index_t ) -> void;
399404};
400405} // namespace openPMD
Original file line number Diff line number Diff line change @@ -266,6 +266,12 @@ auto StatefulSnapshotsContainer::operator[](key_type const &key)
266266 }
267267 }
268268
269+ if (auto currentIteration = base_iterator->currentIterationIndex ();
270+ currentIteration.has_value () && *currentIteration != key)
271+ {
272+ s.series .iterations .container ().erase (*currentIteration);
273+ }
274+
269275 // create new
270276 auto &res = s.series .iterations [key];
271277 Iteration::BeginStepStatus status = [&]() {
Original file line number Diff line number Diff line change @@ -360,7 +360,7 @@ auto StatefulIterator::peekCurrentlyOpenIteration() const
360360 return std::nullopt ;
361361 }
362362 auto &s = optional.value ();
363- auto const &maybeCurrentIteration = s. currentIteration ();
363+ auto const &maybeCurrentIteration = currentIterationIndex ();
364364 if (!maybeCurrentIteration.has_value ())
365365 {
366366 return std::nullopt ;
@@ -391,6 +391,21 @@ auto StatefulIterator::peekCurrentlyOpenIteration()
391391 }
392392}
393393
394+ auto StatefulIterator::currentIterationIndex () const
395+ -> std::optional<iteration_index_t>
396+ {
397+ if (!m_data)
398+ {
399+ return std::nullopt ;
400+ }
401+ auto &optional = *m_data;
402+ if (!optional.has_value ())
403+ {
404+ return std::nullopt ;
405+ }
406+ auto &s = optional.value ();
407+ return s.currentIteration ();
408+ }
394409auto StatefulIterator::reparse_possibly_deleted_iteration (iteration_index_t idx)
395410 -> void
396411{
You can’t perform that action at this time.
0 commit comments