Skip to content

Commit 889646d

Browse files
committed
Record / BaseRecord Reading
1 parent 76a765a commit 889646d

2 files changed

Lines changed: 15 additions & 38 deletions

File tree

src/backend/BaseRecord.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -768,39 +768,7 @@ inline bool BaseRecord<T_elem>::scalar() const
768768
template <typename T_elem>
769769
inline void BaseRecord<T_elem>::readBase()
770770
{
771-
using DT = Datatype;
772-
Parameter<Operation::READ_ATT> aRead;
773-
774-
aRead.name = "unitDimension";
775-
this->IOHandler()->enqueue(IOTask(this, aRead));
776-
this->IOHandler()->flush(internal::defaultFlushParams);
777-
if (auto val = Attribute(Attribute::from_any, *aRead.m_resource)
778-
.getOptional<std::array<double, 7>>();
779-
val.has_value())
780-
this->setAttribute("unitDimension", val.value());
781-
else
782-
throw std::runtime_error(
783-
"Unexpected Attribute datatype for 'unitDimension'");
784-
785-
aRead.name = "timeOffset";
786-
this->IOHandler()->enqueue(IOTask(this, aRead));
787-
this->IOHandler()->flush(internal::defaultFlushParams);
788-
if (*aRead.dtype == DT::FLOAT)
789-
this->setAttribute(
790-
"timeOffset",
791-
Attribute(Attribute::from_any, *aRead.m_resource).get<float>());
792-
else if (*aRead.dtype == DT::DOUBLE)
793-
this->setAttribute(
794-
"timeOffset",
795-
Attribute(Attribute::from_any, *aRead.m_resource).get<double>());
796-
// conversion cast if a backend reports an integer type
797-
else if (auto val = Attribute(Attribute::from_any, *aRead.m_resource)
798-
.getOptional<double>();
799-
val.has_value())
800-
this->setAttribute("timeOffset", val.value());
801-
else
802-
throw std::runtime_error(
803-
"Unexpected Attribute datatype for 'timeOffset'");
771+
internal::ScientificDefaults<BaseRecord<T_elem>>::readDefaults();
804772
}
805773

806774
template <typename T_elem>

src/backend/ScientificDefaults.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,6 @@ void ScientificDefaults<Child>::defaults_impl()
261261
{
262262
auto dimensionality = asChild().retrieveDimensionality();
263263

264-
defaultAttribute("timeOffset", 0.f)
265-
.withSetter(&Mesh::setTimeOffset)
266-
.withReader(ensureFloatingScalar(
267-
[this](auto &&val) { asChild().setTimeOffset(val); }))(wor);
268-
269264
defaultAttribute("geometry", Mesh::Geometry::cartesian)
270265
.withSetter(&Mesh::setGeometry)
271266
.template withReader<std::string>([](Mesh &m, std::string val) {
@@ -375,6 +370,12 @@ void ScientificDefaults<Child>::defaults_impl()
375370
handling for different floating types here */
376371
)(wor);
377372

373+
defaultAttribute("timeOffset", 0.f)
374+
.withSetter(&Mesh::setTimeOffset)
375+
.withReader(ensureFloatingScalar([this](auto &&val) {
376+
asChild().setAttribute("timeOffset", val);
377+
}))(wor);
378+
378379
addParentDefaults<BaseRecord<MeshRecordComponent>, write>();
379380
}
380381
else if constexpr (std::is_same_v<Child, Record>)
@@ -394,6 +395,12 @@ void ScientificDefaults<Child>::defaults_impl()
394395
&Record::setUnitDimension)(wor);
395396
}
396397

398+
defaultAttribute("timeOffset", 0.f)
399+
.withSetter(&Record::setTimeOffset)
400+
.withReader(ensureFloatingScalar([this](auto &&val) {
401+
asChild().setAttribute("timeOffset", val);
402+
}))(wor);
403+
397404
addParentDefaults<BaseRecord<RecordComponent>, write>();
398405
}
399406
else if constexpr (std::is_same_v<Child, PatchRecord>)
@@ -453,5 +460,7 @@ template class ScientificDefaults<PatchRecordComponent>;
453460
template class ScientificDefaults<ParticleSpecies>;
454461
template class ScientificDefaults<Record>;
455462
template class ScientificDefaults<BaseRecord<MeshRecordComponent>>;
463+
template class ScientificDefaults<BaseRecord<PatchRecordComponent>>;
464+
template class ScientificDefaults<BaseRecord<RecordComponent>>;
456465
template class ScientificDefaults<PatchRecord>;
457466
} // namespace openPMD::internal

0 commit comments

Comments
 (0)