Skip to content

Commit

Permalink
Use an owning copy of Series in ReadIterations
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 19, 2021
1 parent 9e0df7f commit 6f21962
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 6 additions & 8 deletions include/openPMD/Series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class SeriesIterator
{
using iteration_index_t = IndexedIteration::index_t;

using maybe_series_t = auxiliary::Option< Series * >;
using maybe_series_t = auxiliary::Option< Series >;

maybe_series_t m_series;
iteration_index_t m_currentIteration = 0;
Expand All @@ -501,10 +501,9 @@ class SeriesIterator
SeriesIterator();

public:
SeriesIterator( Series * );
SeriesIterator( Series );

SeriesIterator &
operator++();
SeriesIterator & operator++();

IndexedIteration
operator*();
Expand Down Expand Up @@ -543,13 +542,12 @@ class ReadIterations
using iterations_t = decltype( internal::SeriesData::iterations );
using iterator_t = SeriesIterator;

Series * m_series;
Series m_series;

ReadIterations( Series * );
ReadIterations( Series );

public:
iterator_t
begin();
iterator_t begin();

iterator_t
end();
Expand Down
16 changes: 9 additions & 7 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ Series::Series(

ReadIterations Series::readIterations()
{
return { this };
return { *this };
}

WriteIterations
Expand Down Expand Up @@ -1315,10 +1315,11 @@ SeriesIterator::SeriesIterator() : m_series()
{
}

SeriesIterator::SeriesIterator( Series * series ) : m_series( series )
SeriesIterator::SeriesIterator( Series series )
: m_series( std::move( series ) )
{
auto it = series->iterations.begin();
if( it == series->iterations.end() )
auto it = series.get().iterations.begin();
if( it == series.get().iterations.end() )
{
*this = end();
return;
Expand All @@ -1344,7 +1345,7 @@ SeriesIterator::operator++()
*this = end();
return *this;
}
Series & series = *m_series.get();
Series & series = m_series.get();
auto & iterations = series.iterations;
auto & currentIteration = iterations[ m_currentIteration ];
if( !currentIteration.closed() )
Expand Down Expand Up @@ -1409,7 +1410,7 @@ IndexedIteration
SeriesIterator::operator*()
{
return IndexedIteration(
m_series.get()->iterations[ m_currentIteration ], m_currentIteration );
m_series.get().iterations[ m_currentIteration ], m_currentIteration );
}

bool
Expand All @@ -1431,7 +1432,8 @@ SeriesIterator::end()
return {};
}

ReadIterations::ReadIterations( Series * series ) : m_series( series )
ReadIterations::ReadIterations( Series series )
: m_series( std::move( series ) )
{
}

Expand Down

0 comments on commit 6f21962

Please sign in to comment.