Skip to content

Commit 885d1ba

Browse files
Follow-up of frontend redesign: Remove unnecessary pointer members (#936)
* Make members of SeriesData plain members, not pointers * Dito for AttributableData * Fix invasive tests * Reorder SeriesData members This makes the class a little bit smaller (352 -> 344 bytes on my machine) * Remove leftover debug message * Move (Read|Write)Iterations to their own header files * Cleanup
1 parent 937de1a commit 885d1ba

21 files changed

Lines changed: 555 additions & 439 deletions

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,12 @@ set(CORE_SOURCE
344344
src/Mesh.cpp
345345
src/ParticlePatches.cpp
346346
src/ParticleSpecies.cpp
347+
src/ReadIterations.cpp
347348
src/Record.cpp
348349
src/RecordComponent.cpp
349350
src/Series.cpp
350351
src/version.cpp
352+
src/WriteIterations.cpp
351353
src/auxiliary/Date.cpp
352354
src/auxiliary/Filesystem.cpp
353355
src/auxiliary/JSON.cpp

include/openPMD/Iteration.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ class Iteration : public LegacyAttributable
246246
bool
247247
dirtyRecursive() const;
248248

249-
virtual void linkHierarchy(std::shared_ptr< Writable > const& w);
249+
/**
250+
* @brief Link with parent.
251+
*
252+
* @param w The Writable representing the parent.
253+
*/
254+
virtual void linkHierarchy(Writable& w);
250255
}; // Iteration
251256

252257
extern template

include/openPMD/ParticleSpecies.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace traits
6666
template< typename T >
6767
void operator()(T & ret)
6868
{
69-
ret.particlePatches.linkHierarchy(ret.writableShared());
69+
ret.particlePatches.linkHierarchy(ret.writable());
7070

7171
auto& np = ret.particlePatches["numParticles"];
7272
auto& npc = np[RecordComponent::SCALAR];

include/openPMD/ReadIterations.hpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* Copyright 2021 Franz Poeschel
2+
*
3+
* This file is part of openPMD-api.
4+
*
5+
* openPMD-api is free software: you can redistribute it and/or modify
6+
* it under the terms of of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* openPMD-api is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with openPMD-api.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
#pragma once
22+
23+
#include "openPMD/Iteration.hpp"
24+
#include "openPMD/Series.hpp"
25+
26+
namespace openPMD
27+
{
28+
/**
29+
* @brief Subclass of Iteration that knows its own index withing the containing
30+
* Series.
31+
*/
32+
class IndexedIteration : public Iteration
33+
{
34+
friend class SeriesIterator;
35+
36+
public:
37+
using iterations_t = decltype( internal::SeriesData::iterations );
38+
using index_t = iterations_t::key_type;
39+
index_t const iterationIndex;
40+
41+
private:
42+
template< typename Iteration_t >
43+
IndexedIteration( Iteration_t && it, index_t index )
44+
: Iteration( std::forward< Iteration_t >( it ) )
45+
, iterationIndex( index )
46+
{
47+
}
48+
};
49+
50+
class SeriesIterator
51+
{
52+
using iteration_index_t = IndexedIteration::index_t;
53+
54+
using maybe_series_t = auxiliary::Option< Series >;
55+
56+
maybe_series_t m_series;
57+
iteration_index_t m_currentIteration = 0;
58+
59+
//! construct the end() iterator
60+
SeriesIterator();
61+
62+
public:
63+
SeriesIterator( Series );
64+
65+
SeriesIterator & operator++();
66+
67+
IndexedIteration operator*();
68+
69+
bool operator==( SeriesIterator const & other ) const;
70+
71+
bool operator!=( SeriesIterator const & other ) const;
72+
73+
static SeriesIterator end();
74+
};
75+
76+
/**
77+
* @brief Reading side of the streaming API.
78+
*
79+
* Create instance via Series::readIterations().
80+
* For use in a C++11-style foreach loop over iterations.
81+
* Designed to allow reading any kind of Series, streaming and non-
82+
* streaming alike.
83+
* Calling Iteration::close() manually before opening the next iteration is
84+
* encouraged and will implicitly flush all deferred IO actions.
85+
* Otherwise, Iteration::close() will be implicitly called upon
86+
* SeriesIterator::operator++(), i.e. upon going to the next iteration in
87+
* the foreach loop.
88+
* Since this is designed for streaming mode, reopening an iteration is
89+
* not possible once it has been closed.
90+
*
91+
*/
92+
class ReadIterations
93+
{
94+
friend class Series;
95+
96+
private:
97+
using iterations_t = decltype( internal::SeriesData::iterations );
98+
using iterator_t = SeriesIterator;
99+
100+
Series m_series;
101+
102+
ReadIterations( Series );
103+
104+
public:
105+
iterator_t begin();
106+
107+
iterator_t end();
108+
};
109+
} // namespace openPMD

include/openPMD/Series.hpp

Lines changed: 13 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "openPMD/Iteration.hpp"
3030
#include "openPMD/IterationEncoding.hpp"
3131
#include "openPMD/Streaming.hpp"
32+
#include "openPMD/WriteIterations.hpp"
3233
#include "openPMD/auxiliary/Option.hpp"
3334
#include "openPMD/auxiliary/Variant.hpp"
3435
#include "openPMD/backend/Attributable.hpp"
@@ -52,7 +53,6 @@
5253
namespace openPMD
5354
{
5455
class ReadIterations;
55-
class WriteIterations;
5656
class Series;
5757
class SeriesImpl;
5858

@@ -84,27 +84,21 @@ class SeriesData : public AttributableData
8484
Container< Iteration, uint64_t > iterations{};
8585

8686
OPENPMD_private :
87+
auxiliary::Option< WriteIterations > m_writeIterations;
88+
std::string m_name;
89+
std::string m_filenamePrefix;
90+
std::string m_filenamePostfix;
91+
int m_filenamePadding;
92+
IterationEncoding m_iterationEncoding{};
93+
Format m_format;
8794
/**
8895
* Whether a step is currently active for this iteration.
8996
* Used for group-based iteration layout, see SeriesData.hpp for
9097
* iteration-based layout.
9198
* Access via stepStatus() method to automatically select the correct
9299
* one among both flags.
93100
*/
94-
std::shared_ptr< StepStatus >
95-
m_stepStatus = std::make_shared< StepStatus >( StepStatus::NoStep );
96-
97-
std::shared_ptr< IterationEncoding > m_iterationEncoding{
98-
std::make_shared< IterationEncoding >() };
99-
std::shared_ptr< std::string > m_name;
100-
std::shared_ptr< Format > m_format;
101-
102-
std::shared_ptr< std::string > m_filenamePrefix;
103-
std::shared_ptr< std::string > m_filenamePostfix;
104-
std::shared_ptr< int > m_filenamePadding;
105-
106-
std::shared_ptr< auxiliary::Option< WriteIterations > > m_writeIterations =
107-
std::make_shared< auxiliary::Option< WriteIterations > >();
101+
StepStatus m_stepStatus = StepStatus::NoStep;
108102
}; // SeriesData
109103

110104
class SeriesInternal;
@@ -467,135 +461,8 @@ class Series : public SeriesImpl
467461
*/
468462
WriteIterations writeIterations();
469463
};
470-
471-
/**
472-
* @brief Subclass of Iteration that knows its own index withing the containing
473-
* Series.
474-
*/
475-
class IndexedIteration : public Iteration
476-
{
477-
friend class SeriesIterator;
478-
479-
public:
480-
using iterations_t = decltype( internal::SeriesData::iterations );
481-
using index_t = iterations_t::key_type;
482-
index_t const iterationIndex;
483-
484-
private:
485-
template< typename Iteration_t >
486-
IndexedIteration( Iteration_t && it, index_t index )
487-
: Iteration( std::forward< Iteration_t >( it ) )
488-
, iterationIndex( index )
489-
{
490-
}
491-
};
492-
493-
class SeriesIterator
494-
{
495-
using iteration_index_t = IndexedIteration::index_t;
496-
497-
using maybe_series_t = auxiliary::Option< Series >;
498-
499-
maybe_series_t m_series;
500-
iteration_index_t m_currentIteration = 0;
501-
502-
//! construct the end() iterator
503-
SeriesIterator();
504-
505-
public:
506-
SeriesIterator( Series );
507-
508-
SeriesIterator & operator++();
509-
510-
IndexedIteration
511-
operator*();
512-
513-
bool
514-
operator==( SeriesIterator const & other ) const;
515-
516-
bool
517-
operator!=( SeriesIterator const & other ) const;
518-
519-
static SeriesIterator
520-
end();
521-
};
522-
523-
/**
524-
* @brief Reading side of the streaming API.
525-
*
526-
* Create instance via Series::readIterations().
527-
* For use in a C++11-style foreach loop over iterations.
528-
* Designed to allow reading any kind of Series, streaming and non-
529-
* streaming alike.
530-
* Calling Iteration::close() manually before opening the next iteration is
531-
* encouraged and will implicitly flush all deferred IO actions.
532-
* Otherwise, Iteration::close() will be implicitly called upon
533-
* SeriesIterator::operator++(), i.e. upon going to the next iteration in
534-
* the foreach loop.
535-
* Since this is designed for streaming mode, reopening an iteration is
536-
* not possible once it has been closed.
537-
*
538-
*/
539-
class ReadIterations
540-
{
541-
friend class Series;
542-
543-
private:
544-
using iterations_t = decltype( internal::SeriesData::iterations );
545-
using iterator_t = SeriesIterator;
546-
547-
Series m_series;
548-
549-
ReadIterations( Series );
550-
551-
public:
552-
iterator_t begin();
553-
554-
iterator_t
555-
end();
556-
};
557-
558-
/** Writing side of the streaming API.
559-
*
560-
* Create instance via Series::writeIterations().
561-
* For use via WriteIterations::operator[]().
562-
* Designed to allow reading any kind of Series, streaming and non-
563-
* streaming alike. Calling Iteration::close() manually before opening
564-
* the next iteration is encouraged and will implicitly flush all
565-
* deferred IO actions. Otherwise, Iteration::close() will be implicitly
566-
* called upon SeriesIterator::operator++(), i.e. upon going to the next
567-
* iteration in the foreach loop.
568-
*
569-
* Since this is designed for streaming mode, reopening an iteration is
570-
* not possible once it has been closed.
571-
*
572-
*/
573-
class WriteIterations : private Container< Iteration, uint64_t >
574-
{
575-
friend class Series;
576-
577-
private:
578-
using iterations_t = Container< Iteration, uint64_t >;
579-
struct SharedResources
580-
{
581-
iterations_t iterations;
582-
auxiliary::Option< uint64_t > currentlyOpen;
583-
584-
SharedResources( iterations_t );
585-
~SharedResources();
586-
};
587-
588-
using key_type = typename iterations_t::key_type;
589-
using value_type = typename iterations_t::key_type;
590-
WriteIterations( iterations_t );
591-
explicit WriteIterations() = default;
592-
//! Index of the last opened iteration
593-
std::shared_ptr< SharedResources > shared;
594-
595-
public:
596-
mapped_type &
597-
operator[]( key_type const & key ) override;
598-
mapped_type &
599-
operator[]( key_type && key ) override;
600-
};
601464
} // namespace openPMD
465+
466+
// Make sure that this one is always included if Series.hpp is included,
467+
// otherwise SeriesImpl::readIterations() cannot be used
468+
#include "openPMD/ReadIterations.hpp"

0 commit comments

Comments
 (0)