Skip to content

Commit 7e46729

Browse files
committed
Compiles
1 parent e9a242c commit 7e46729

18 files changed

+232
-257
lines changed

include/openPMD/Iteration.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ class Iteration
349349
void readMeshes(std::string const &meshesPath);
350350
void readParticles(std::string const &particlesPath);
351351

352+
void setDefaultAttributes();
353+
352354
/**
353355
* Status after beginning an IO step. Currently includes:
354356
* * The advance status (OK, OVER, RANDOMACCESS)
@@ -444,7 +446,6 @@ class Iteration
444446

445447
protected:
446448
void defaults_impl(bool write, OpenpmdStandard) override;
447-
auto as_attributable() -> Attributable & override;
448449
}; // Iteration
449450

450451
extern template float Iteration::time<float>() const;

include/openPMD/Mesh.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ class Mesh : public BaseRecord<MeshRecordComponent>
332332
flush_impl(std::string const &, internal::FlushParams const &) override;
333333
void read();
334334
auto retrieveDimensionality() const -> uint64_t;
335+
336+
protected:
337+
void defaults_impl(bool write, OpenpmdStandard) override;
335338
}; // Mesh
336339

337340
static_assert(internal::IsContainer_v<Mesh>);

include/openPMD/ParticleSpecies.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ParticleSpecies
6464
{
6565
return m_containerData;
6666
}
67+
68+
protected:
69+
void defaults_impl(bool write, OpenpmdStandard) override;
6770
};
6871

6972
namespace traits

include/openPMD/Record.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class Record : public BaseRecord<RecordComponent>
5757
flush_impl(std::string const &, internal::FlushParams const &) override;
5858

5959
[[nodiscard]] internal::HomogenizeExtents read();
60+
61+
protected:
62+
void defaults_impl(bool write, OpenpmdStandard) override;
6063
}; // Record
6164

6265
static_assert(internal::HasScientificDefaults_v<Record>);

include/openPMD/RecordComponent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ OPENPMD_protected
550550
void verifyChunk(Offset const &, Extent const &) const;
551551

552552
void verifyChunk(Datatype, Offset const &, Extent const &) const;
553+
554+
protected:
555+
void defaults_impl(bool write, OpenpmdStandard) override;
553556
}; // RecordComponent
554557

555558
namespace internal

include/openPMD/backend/BaseRecord.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ class BaseRecord
382382
flush_impl(std::string const &, internal::FlushParams const &) = 0;
383383

384384
void eraseScalar();
385+
386+
protected:
387+
void defaults_impl(bool write, OpenpmdStandard) override;
385388
}; // BaseRecord
386389

387390
namespace detail

include/openPMD/backend/MeshRecordComponent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class MeshRecordComponent : public RecordComponent
9999
{
100100
v(*this);
101101
}
102+
103+
protected:
104+
void defaults_impl(bool write, OpenpmdStandard) override;
102105
};
103106

104107
template <typename T>

include/openPMD/backend/PatchRecordComponent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ OPENPMD_protected
111111

112112
PatchRecordComponent();
113113
PatchRecordComponent(NoInit);
114+
115+
protected:
116+
void defaults_impl(bool write, OpenpmdStandard) override;
114117
}; // PatchRecordComponent
115118

116119
template <typename T>

include/openPMD/backend/ScientificDefaults.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ struct ConfigAttribute;
1717
class ScientificDefaults
1818
{
1919
protected:
20-
[[nodiscard]] auto defaultAttribute(char const *attrName)
20+
[[nodiscard]] auto defaultAttribute(Attributable &, char const *attrName)
2121
-> ConfigAttribute;
2222

2323
// template <typename Parent, bool write>
2424
// void addParentDefaults(OpenpmdStandard);
2525

26-
virtual void defaults_impl(bool write, OpenpmdStandard);
27-
virtual auto as_attributable() -> Attributable &;
26+
virtual void defaults_impl(bool write, OpenpmdStandard) = 0;
2827

2928
protected:
3029
// Called upon Iteration::close(), will fill in defaults below Iteration

src/Iteration.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
#include "openPMD/auxiliary/DerefDynamicCast.hpp"
3131
#include "openPMD/auxiliary/Filesystem.hpp"
3232
#include "openPMD/auxiliary/StringManip.hpp"
33+
#include "openPMD/auxiliary/TypeTraits.hpp"
3334
#include "openPMD/auxiliary/Variant.hpp"
3435
#include "openPMD/backend/Attributable.hpp"
36+
#include "openPMD/backend/BaseRecordComponent.hpp"
3537
#include "openPMD/backend/ScientificDefaults.hpp"
3638
#include "openPMD/backend/ScientificDefaults_impl.hpp"
3739
#include "openPMD/backend/Variant_internal.hpp"
@@ -44,6 +46,7 @@
4446
#include <optional>
4547
#include <stdexcept>
4648
#include <tuple>
49+
#include <type_traits>
4750
#include <variant>
4851

4952
namespace openPMD
@@ -114,7 +117,7 @@ Iteration &Iteration::close(bool _flush)
114117

115118
if (access::write(IOHandler()->m_frontendAccess))
116119
{
117-
writeDefaultsRecursively(IOHandler()->m_standard);
120+
setDefaultAttributes();
118121
}
119122

120123
if (_flush)
@@ -148,6 +151,40 @@ Iteration &Iteration::close(bool _flush)
148151
return *this;
149152
}
150153

154+
void Iteration::setDefaultAttributes()
155+
{
156+
auto standard = IOHandler()->m_standard;
157+
visitHierarchy([standard](auto &component) {
158+
using ComponentType = std::remove_reference_t<decltype(component)>;
159+
if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, ComponentType>)
160+
{
161+
if (component.empty() && !component.datasetDefined())
162+
{
163+
std::cerr
164+
<< "Cannot flush Record without any contained components: '"
165+
<< component.myPath().openPMDPath() << "'. Will ignore.";
166+
if (component.written())
167+
{
168+
std::cerr
169+
<< "\n(Note: The Record seems to have been written "
170+
"previously?)";
171+
}
172+
std::cerr << std::endl;
173+
return;
174+
}
175+
}
176+
177+
if constexpr (
178+
!std::is_same_v<ComponentType, Container<Mesh>> &&
179+
!std::is_same_v<ComponentType, Container<Record>> &&
180+
!std::is_same_v<ComponentType, Container<PatchRecord>> &&
181+
!std::is_same_v<ComponentType, Container<ParticleSpecies>>)
182+
{
183+
component.writeDefaults(standard);
184+
}
185+
});
186+
}
187+
151188
Iteration &Iteration::open()
152189
{
153190
Series s = retrieveSeries();
@@ -941,22 +978,17 @@ void Iteration::defaults_impl(bool write, OpenpmdStandard)
941978
auto float_types = get_float_types();
942979
auto const wor = write ? WriteOrRead::Write : WriteOrRead::Read;
943980

944-
defaultAttribute("time")
981+
defaultAttribute(*this, "time")
945982
.template withSetter<Iteration>(0., &Iteration::setTime)
946983
.withReader(float_types, require_scalar)(wor);
947-
defaultAttribute("dt")
984+
defaultAttribute(*this, "dt")
948985
.template withSetter<Iteration>(1., &Iteration::setDt)
949986
.withReader(float_types, require_scalar)(wor);
950-
defaultAttribute("timeUnitSI")
987+
defaultAttribute(*this, "timeUnitSI")
951988
.template withSetter<Iteration>(1.0, &Iteration::setTimeUnitSI)
952989
.withReader(float_types, require_type<double>())(wor);
953990
}
954991

955-
auto Iteration::as_attributable() -> Attributable &
956-
{
957-
return *this;
958-
}
959-
960992
template float Iteration::time<float>() const;
961993
template double Iteration::time<double>() const;
962994
template long double Iteration::time<long double>() const;

0 commit comments

Comments
 (0)