Skip to content

Commit a65eda3

Browse files
committed
Prepare class structure without applying logic yet
BaseRecord is now derived by its contained RecordComponent type. If it is scalar, the idea is that the BaseRecord itself is used as a RecordComponent, without needing to retrieve the [SCALAR] entry. No logic implemented yet around this, this just prepares the class structure. Notice that this will write some unnecessary attributes since the RecordComponent types initialize some default attributes upon construction.
1 parent d6f8057 commit a65eda3

File tree

10 files changed

+65
-16
lines changed

10 files changed

+65
-16
lines changed

include/openPMD/ParticleSpecies.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace traits
6161
template <>
6262
struct GenerationPolicy<ParticleSpecies>
6363
{
64+
constexpr static bool is_noop = false;
6465
template <typename T>
6566
void operator()(T &ret)
6667
{

include/openPMD/RecordComponent.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ namespace internal
9595
*/
9696
bool m_hasBeenExtended = false;
9797
};
98+
template <typename, typename>
99+
class BaseRecordData;
98100
} // namespace internal
99101

100102
class RecordComponent : public BaseRecordComponent
@@ -103,8 +105,10 @@ class RecordComponent : public BaseRecordComponent
103105
friend class Container;
104106
friend class Iteration;
105107
friend class ParticleSpecies;
106-
template <typename T_elem>
108+
template <typename>
107109
friend class BaseRecord;
110+
template <typename, typename>
111+
friend class internal::BaseRecordData;
108112
friend class Record;
109113
friend class Mesh;
110114
template <typename>
@@ -437,6 +441,7 @@ OPENPMD_protected
437441
std::shared_ptr<Data_t> m_recordComponentData;
438442

439443
RecordComponent();
444+
RecordComponent(NoInit);
440445

441446
inline Data_t const &get() const
442447
{

include/openPMD/backend/Attributable.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace internal
8181
A_MAP m_attributes;
8282
};
8383

84-
template <typename>
84+
template <typename, typename>
8585
class BaseRecordData;
8686
} // namespace internal
8787

@@ -99,7 +99,7 @@ class Attributable
9999
friend class BaseRecord;
100100
template <typename T_elem>
101101
friend class BaseRecordInterface;
102-
template <typename>
102+
template <typename, typename>
103103
friend class internal::BaseRecordData;
104104
template <typename T, typename T_key, typename T_container>
105105
friend class Container;

include/openPMD/backend/BaseRecord.hpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ namespace openPMD
3232
{
3333
namespace internal
3434
{
35-
template <typename T_elem>
36-
class BaseRecordData : public ContainerData<T_elem>
35+
template <
36+
typename T_elem, // = T_RecordComponent
37+
/*
38+
* Technically not necessary, but some old compilers ignore friend
39+
* declarations at this place, so we specify the data class explicitly
40+
*/
41+
typename T_RecordComponentData = typename T_elem::Data_t>
42+
class BaseRecordData final
43+
: public ContainerData<T_elem>
44+
, public T_RecordComponentData
3745
{
3846
public:
3947
/**
@@ -55,17 +63,29 @@ namespace internal
5563
} // namespace internal
5664

5765
template <typename T_elem>
58-
class BaseRecord : public Container<T_elem>
66+
class BaseRecord
67+
: public Container<T_elem>
68+
, public T_elem // T_RecordComponent
5969
{
70+
using T_RecordComponent = T_elem;
71+
using T_Container = Container<T_elem>;
72+
using T_Self = BaseRecord<T_elem>;
6073
friend class Iteration;
6174
friend class ParticleSpecies;
6275
friend class PatchRecord;
6376
friend class Record;
6477
friend class Mesh;
78+
template <typename, typename>
79+
friend class internal::BaseRecordData;
6580

66-
using Data_t = internal::BaseRecordData<T_elem>;
81+
using Data_t =
82+
internal::BaseRecordData<T_elem, typename T_RecordComponent::Data_t>;
6783
std::shared_ptr<Data_t> m_baseRecordData;
6884

85+
static_assert(
86+
traits::GenerationPolicy<T_RecordComponent>::is_noop,
87+
"Internal error: Scalar components cannot have generation policies.");
88+
6989
inline Data_t const &get() const
7090
{
7191
return *m_baseRecordData;
@@ -82,7 +102,8 @@ class BaseRecord : public Container<T_elem>
82102
inline void setData(std::shared_ptr<Data_t> data)
83103
{
84104
m_baseRecordData = std::move(data);
85-
Container<T_elem>::setData(m_baseRecordData);
105+
T_Container::setData(m_baseRecordData);
106+
T_RecordComponent::setData(m_baseRecordData);
86107
}
87108

88109
public:
@@ -96,8 +117,8 @@ class BaseRecord : public Container<T_elem>
96117
using const_reference = typename Container<T_elem>::const_reference;
97118
using pointer = typename Container<T_elem>::pointer;
98119
using const_pointer = typename Container<T_elem>::const_pointer;
99-
using iterator = typename Container<T_elem>::iterator;
100-
using const_iterator = typename Container<T_elem>::const_iterator;
120+
using iterator = typename T_Container::iterator;
121+
using const_iterator = typename T_Container::const_iterator;
101122

102123
virtual ~BaseRecord() = default;
103124

@@ -158,8 +179,8 @@ class BaseRecord : public Container<T_elem>
158179

159180
namespace internal
160181
{
161-
template <typename T_elem>
162-
BaseRecordData<T_elem>::BaseRecordData()
182+
template <typename T_elem, typename T_RecordComponentData>
183+
BaseRecordData<T_elem, T_RecordComponentData>::BaseRecordData()
163184
{
164185
Attributable impl;
165186
impl.setData({this, [](auto const *) {}});
@@ -170,7 +191,9 @@ namespace internal
170191
} // namespace internal
171192

172193
template <typename T_elem>
173-
BaseRecord<T_elem>::BaseRecord() : Container<T_elem>(Attributable::NoInit())
194+
BaseRecord<T_elem>::BaseRecord()
195+
: T_Container(Attributable::NoInit())
196+
, T_RecordComponent(Attributable::NoInit())
174197
{
175198
setData(std::make_shared<Data_t>());
176199
}
@@ -291,7 +314,7 @@ template <typename T_elem>
291314
inline std::array<double, 7> BaseRecord<T_elem>::unitDimension() const
292315
{
293316
return this->getAttribute("unitDimension")
294-
.template get<std::array<double, 7> >();
317+
.template get<std::array<double, 7>>();
295318
}
296319

297320
template <typename T_elem>
@@ -310,7 +333,7 @@ inline void BaseRecord<T_elem>::readBase()
310333
this->IOHandler()->enqueue(IOTask(this, aRead));
311334
this->IOHandler()->flush(internal::defaultFlushParams);
312335
if (auto val =
313-
Attribute(*aRead.resource).getOptional<std::array<double, 7> >();
336+
Attribute(*aRead.resource).getOptional<std::array<double, 7>>();
314337
val.has_value())
315338
this->setAttribute("unitDimension", val.value());
316339
else
@@ -339,7 +362,7 @@ template <typename T_elem>
339362
inline void BaseRecord<T_elem>::flush(
340363
std::string const &name, internal::FlushParams const &flushParams)
341364
{
342-
if (!this->written() && this->empty())
365+
if (!this->written() && this->T_Container::empty())
343366
throw std::runtime_error(
344367
"A Record can not be written without any contained "
345368
"RecordComponents: " +

include/openPMD/backend/Container.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace traits
4949
template <typename U>
5050
struct GenerationPolicy
5151
{
52+
constexpr static bool is_noop = true;
5253
template <typename T>
5354
void operator()(T &)
5455
{}

include/openPMD/backend/MeshRecordComponent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ class MeshRecordComponent : public RecordComponent
3030
{
3131
template <typename T, typename T_key, typename T_container>
3232
friend class Container;
33+
template <typename>
34+
friend class BaseRecord;
3335

3436
friend class Mesh;
3537

3638
private:
3739
MeshRecordComponent();
40+
MeshRecordComponent(NoInit);
3841
void read() override;
3942

4043
public:

include/openPMD/backend/PatchRecordComponent.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ namespace internal
5656

5757
PatchRecordComponentData();
5858
};
59+
60+
template <typename, typename>
61+
class BaseRecordData;
5962
} // namespace internal
6063

6164
/**
@@ -67,6 +70,8 @@ class PatchRecordComponent : public BaseRecordComponent
6770
friend class Container;
6871
template <typename>
6972
friend class BaseRecord;
73+
template <typename, typename>
74+
friend class internal::BaseRecordData;
7075
friend class ParticlePatches;
7176
friend class PatchRecord;
7277
friend class ParticleSpecies;
@@ -121,6 +126,7 @@ OPENPMD_protected
121126
std::shared_ptr<Data_t> m_patchRecordComponentData;
122127

123128
PatchRecordComponent();
129+
PatchRecordComponent(NoInit);
124130

125131
inline Data_t const &get() const
126132
{

src/RecordComponent.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ RecordComponent::RecordComponent() : BaseRecordComponent(NoInit())
4646
setUnitSI(1);
4747
}
4848

49+
RecordComponent::RecordComponent(NoInit) : BaseRecordComponent(NoInit())
50+
{}
51+
4952
// We need to instantiate this somewhere otherwise there might be linker issues
5053
// despite this thing actually being constepxr
5154
constexpr char const *const RecordComponent::SCALAR;

src/backend/MeshRecordComponent.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ MeshRecordComponent::MeshRecordComponent() : RecordComponent()
2727
setPosition(std::vector<double>{0});
2828
}
2929

30+
MeshRecordComponent::MeshRecordComponent(NoInit) : RecordComponent(NoInit())
31+
{}
32+
3033
void MeshRecordComponent::read()
3134
{
3235
using DT = Datatype;

src/backend/PatchRecordComponent.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ PatchRecordComponent::PatchRecordComponent() : BaseRecordComponent(NoInit())
8080
setUnitSI(1);
8181
}
8282

83+
PatchRecordComponent::PatchRecordComponent(NoInit)
84+
: BaseRecordComponent(NoInit())
85+
{}
86+
8387
void PatchRecordComponent::flush(
8488
std::string const &name, internal::FlushParams const &flushParams)
8589
{

0 commit comments

Comments
 (0)