Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/openPMD/backend/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Container : virtual public Attributable
template <typename>
friend class internal::EraseStaleEntries;
friend class StatefulIterator;
friend class StatefulSnapshotsContainer;

protected:
using ContainerData = internal::ContainerData<T, T_key, T_container>;
Expand Down
5 changes: 5 additions & 0 deletions include/openPMD/snapshots/StatefulIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ class StatefulIterator
-> std::optional<value_type const *>;
auto peekCurrentlyOpenIteration() -> std::optional<value_type *>;

// Only checks the index state from the Iterator, peekCurrentlyOpenIteration
// actually retrieves the Iteration and checks if it is open
[[nodiscard]] auto currentIterationIndex() const
-> std::optional<iteration_index_t>;

auto reparse_possibly_deleted_iteration(iteration_index_t) -> void;
};
} // namespace openPMD
Expand Down
6 changes: 6 additions & 0 deletions src/snapshots/ContainerImpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ auto StatefulSnapshotsContainer::operator[](key_type const &key)
}
}

if (auto currentIteration = base_iterator->currentIterationIndex();
currentIteration.has_value() && *currentIteration != key)
{
s.series.iterations.container().erase(*currentIteration);
}

// create new
auto &res = s.series.iterations[key];
Iteration::BeginStepStatus status = [&]() {
Expand Down
17 changes: 16 additions & 1 deletion src/snapshots/StatefulIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ auto StatefulIterator::peekCurrentlyOpenIteration() const
return std::nullopt;
}
auto &s = optional.value();
auto const &maybeCurrentIteration = s.currentIteration();
auto const &maybeCurrentIteration = currentIterationIndex();
if (!maybeCurrentIteration.has_value())
{
return std::nullopt;
Expand Down Expand Up @@ -391,6 +391,21 @@ auto StatefulIterator::peekCurrentlyOpenIteration()
}
}

auto StatefulIterator::currentIterationIndex() const
-> std::optional<iteration_index_t>
{
if (!m_data)
{
return std::nullopt;
}
auto &optional = *m_data;
if (!optional.has_value())
{
return std::nullopt;
}
auto &s = optional.value();
return s.currentIteration();
}
auto StatefulIterator::reparse_possibly_deleted_iteration(iteration_index_t idx)
-> void
{
Expand Down
Loading